8347740: java/io/File/createTempFile/SpecialTempFile.java failing

Backport-of: f2a9d26b2e
This commit is contained in:
Goetz Lindenmaier
2025-02-13 10:23:18 +00:00
committed by Sergey Shelomentsev
parent 25e8dee671
commit f8e64d144e

View File

@@ -39,8 +39,12 @@ import jdk.internal.util.OSVersion;
import jdk.internal.util.StaticProperty;
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)
@@ -67,19 +71,21 @@ public class SpecialTempFile {
f = File.createTempFile(prefix[i], suffix[i],
tempDir.toFile());
} 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");
}
}
}
@@ -108,9 +114,12 @@ public class SpecialTempFile {
// Test JDK-8013827
String[] resvPre = { "LPT1.package.zip", "com7.4.package.zip" };
String[] resvSuf = { ".temp", ".temp" };
boolean exceptionExpected =
!(StaticProperty.osName().matches("^.*[11|2025]$") ||
new OSVersion(10, 0).compareTo(OSVersion.current()) > 0);
test("ReservedName", resvPre, resvSuf, exceptionExpected);
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);
}
}