From df53e4ab8deab4cd2fda8d7a9857e778540ccad4 Mon Sep 17 00:00:00 2001 From: Sophia Guo Date: Fri, 8 May 2026 14:51:33 -0400 Subject: [PATCH 1/2] Backport f2a9d26b2e409a7216d967ebb6b92726e8ed65c3 --- .../File/createTempFile/SpecialTempFile.java | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/jdk/test/java/io/File/createTempFile/SpecialTempFile.java b/jdk/test/java/io/File/createTempFile/SpecialTempFile.java index 8bb8d934d36..60a9ccdd225 100644 --- a/jdk/test/java/io/File/createTempFile/SpecialTempFile.java +++ b/jdk/test/java/io/File/createTempFile/SpecialTempFile.java @@ -32,9 +32,12 @@ import java.io.IOException; public class SpecialTempFile { - + // + // If exceptionExpected == null, then any IOException thrown by + // File.createTempFile is ignored. + // private static void test(String name, String[] prefix, String[] suffix, - boolean exceptionExpected) throws IOException + Boolean exceptionExpected) throws IOException { if (prefix == null || suffix == null || prefix.length != suffix.length) @@ -61,19 +64,21 @@ private static void test(String name, String[] prefix, String[] suffix, else f = File.createTempFile(prefix[i], suffix[i], new File(dir)); } catch (IOException e) { - if (exceptionExpected) { - if (e.getMessage().startsWith(exceptionMsg)) - exceptionThrown = true; - else - System.out.println("Wrong error message:" + - e.getMessage()); - } else { - throw e; + if (exceptionExpected != null) { + if (exceptionExpected) { + if (e.getMessage().startsWith(exceptionMsg)) + exceptionThrown = true; + else + System.out.println("Wrong error message:" + + e.getMessage()); + } else { + throw e; + } + + if (exceptionExpected && (!exceptionThrown || f != null)) + throw new RuntimeException("IOException expected"); } } - - if (exceptionExpected && (!exceptionThrown || f != null)) - throw new RuntimeException("IOException is expected"); } } } @@ -106,6 +111,11 @@ public static void main(String[] args) throws Exception { // Test JDK-8013827 String[] resvPre = { "LPT1.package.zip", "com7.4.package.zip" }; String[] resvSuf = { ".temp", ".temp" }; - test("ReservedName", resvPre, resvSuf, true); + System.out.println("OS name: " + StaticProperty.osName() + "\n" + + "OS version: " + OSVersion.current()); + + // Here the test is for whether File.createTempFile hangs, so whether + // an exception is thrown is ignored: expectedException == null + test("ReservedName", resvPre, resvSuf, null); } } From 5857f18748feae3021e00659bc660afb96198d61 Mon Sep 17 00:00:00 2001 From: Sophia Guo Date: Wed, 27 May 2026 17:07:51 -0400 Subject: [PATCH 2/2] Backport 8183344 Signed-off-by: Sophia Guo --- .../File/createTempFile/SpecialTempFile.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/jdk/test/java/io/File/createTempFile/SpecialTempFile.java b/jdk/test/java/io/File/createTempFile/SpecialTempFile.java index 60a9ccdd225..604e132023c 100644 --- a/jdk/test/java/io/File/createTempFile/SpecialTempFile.java +++ b/jdk/test/java/io/File/createTempFile/SpecialTempFile.java @@ -30,6 +30,9 @@ import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; public class SpecialTempFile { // @@ -48,21 +51,21 @@ private static void test(String name, String[] prefix, String[] suffix, final String exceptionMsg = "Unable to create temporary file"; String[] dirs = { null, "." }; + Path testPath = Paths.get(System.getProperty("test.dir", ".")); for (int i = 0; i < prefix.length; i++) { boolean exceptionThrown = false; File f = null; for (String dir: dirs) { + Path tempDir = Files.createTempDirectory(testPath, dir); System.out.println("In test " + name + ", creating temp file with prefix, " + prefix[i] + ", suffix, " + suffix[i] + - ", in dir, " + dir); + ", in dir, " + tempDir); try { - if (dir == null || dir.isEmpty()) - f = File.createTempFile(prefix[i], suffix[i]); - else - f = File.createTempFile(prefix[i], suffix[i], new File(dir)); + f = File.createTempFile(prefix[i], suffix[i], + tempDir.toFile()); } catch (IOException e) { if (exceptionExpected != null) { if (exceptionExpected) { @@ -86,10 +89,6 @@ private static void test(String name, String[] prefix, String[] suffix, public static void main(String[] args) throws Exception { // Common test final String name = "SpecialTempFile"; - File f = new File(System.getProperty("java.io.tmpdir"), name); - if (!f.exists()) { - f.createNewFile(); - } String[] nulPre = { name + "\u0000" }; String[] nulSuf = { ".test" }; test("NulName", nulPre, nulSuf, true); @@ -111,8 +110,8 @@ public static void main(String[] args) throws Exception { // Test JDK-8013827 String[] resvPre = { "LPT1.package.zip", "com7.4.package.zip" }; String[] resvSuf = { ".temp", ".temp" }; - System.out.println("OS name: " + StaticProperty.osName() + "\n" + - "OS version: " + OSVersion.current()); + System.out.println("OS name: " + System.getProperty("os.name") + "\n" + + "OS version: " + System.getProperty("os.version")); // Here the test is for whether File.createTempFile hangs, so whether // an exception is thrown is ignored: expectedException == null