Skip to content

Commit 4816a5f

Browse files
authored
Merge pull request #868 from pshipton/sptemp2025
Backport 8347740: java/io/File/createTempFile/SpecialTempFile.java failing
2 parents 85f4fc4 + af1e6c2 commit 4816a5f

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

test/jdk/java/io/File/createTempFile/SpecialTempFile.java

+26-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -41,8 +41,12 @@
4141
import jdk.test.lib.OSVersion;
4242

4343
public class SpecialTempFile {
44+
//
45+
// If exceptionExpected == null, then any IOException thrown by
46+
// File.createTempFile is ignored.
47+
//
4448
private static void test(String name, String[] prefix, String[] suffix,
45-
boolean exceptionExpected) throws IOException
49+
Boolean exceptionExpected) throws IOException
4650
{
4751
if (prefix == null || suffix == null
4852
|| prefix.length != suffix.length)
@@ -69,19 +73,21 @@ private static void test(String name, String[] prefix, String[] suffix,
6973
f = File.createTempFile(prefix[i], suffix[i],
7074
tempDir.toFile());
7175
} catch (IOException e) {
72-
if (exceptionExpected) {
73-
if (e.getMessage().startsWith(exceptionMsg))
74-
exceptionThrown = true;
75-
else
76-
System.out.println("Wrong error message:" +
77-
e.getMessage());
78-
} else {
79-
throw e;
76+
if (exceptionExpected != null) {
77+
if (exceptionExpected) {
78+
if (e.getMessage().startsWith(exceptionMsg))
79+
exceptionThrown = true;
80+
else
81+
System.out.println("Wrong error message:" +
82+
e.getMessage());
83+
} else {
84+
throw e;
85+
}
86+
87+
if (exceptionExpected && (!exceptionThrown || f != null))
88+
throw new RuntimeException("IOException expected");
8089
}
8190
}
82-
83-
if (exceptionExpected && (!exceptionThrown || f != null))
84-
throw new RuntimeException("IOException is expected");
8591
}
8692
}
8793
}
@@ -110,9 +116,12 @@ public static void main(String[] args) throws Exception {
110116
// Test JDK-8013827
111117
String[] resvPre = { "LPT1.package.zip", "com7.4.package.zip" };
112118
String[] resvSuf = { ".temp", ".temp" };
113-
boolean exceptionExpected =
114-
!(System.getProperty("os.name").endsWith("11") ||
115-
new OSVersion(10, 0).compareTo(OSVersion.current()) > 0);
116-
test("ReservedName", resvPre, resvSuf, exceptionExpected);
119+
120+
System.out.println("OS name: " + System.getProperty("os.name") + "\n" +
121+
"OS version: " + OSVersion.current());
122+
123+
// Here the test is for whether File.createTempFile hangs, so whether
124+
// an exception is thrown is ignored: expectedException == null
125+
test("ReservedName", resvPre, resvSuf, null);
117126
}
118127
}

0 commit comments

Comments
 (0)