From df53e4ab8deab4cd2fda8d7a9857e778540ccad4 Mon Sep 17 00:00:00 2001 From: Sophia Guo Date: Fri, 8 May 2026 14:51:33 -0400 Subject: [PATCH] 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); } }