Skip to content

Commit 028d3a7

Browse files
committed
Backport f2a9d26b2e409a7216d967ebb6b92726e8ed65c3
1 parent 2691c14 commit 028d3a7

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

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

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@
4242
import jdk.internal.util.StaticProperty;
4343

4444
public class SpecialTempFile {
45+
//
46+
// If exceptionExpected == null, then any IOException thrown by
47+
// File.createTempFile is ignored.
48+
//
4549
private static void test(String name, String[] prefix, String[] suffix,
46-
boolean exceptionExpected) throws IOException
50+
Boolean exceptionExpected) throws IOException
4751
{
4852
if (prefix == null || suffix == null
4953
|| prefix.length != suffix.length)
@@ -70,19 +74,21 @@ private static void test(String name, String[] prefix, String[] suffix,
7074
f = File.createTempFile(prefix[i], suffix[i],
7175
tempDir.toFile());
7276
} catch (IOException e) {
73-
if (exceptionExpected) {
74-
if (e.getMessage().startsWith(exceptionMsg))
75-
exceptionThrown = true;
76-
else
77-
System.out.println("Wrong error message:" +
78-
e.getMessage());
79-
} else {
80-
throw e;
77+
if (exceptionExpected != null) {
78+
if (exceptionExpected) {
79+
if (e.getMessage().startsWith(exceptionMsg))
80+
exceptionThrown = true;
81+
else
82+
System.out.println("Wrong error message:" +
83+
e.getMessage());
84+
} else {
85+
throw e;
86+
}
87+
88+
if (exceptionExpected && (!exceptionThrown || f != null))
89+
throw new RuntimeException("IOException expected");
8190
}
8291
}
83-
84-
if (exceptionExpected && (!exceptionThrown || f != null))
85-
throw new RuntimeException("IOException is expected");
8692
}
8793
}
8894
}
@@ -115,5 +121,12 @@ public static void main(String[] args) throws Exception {
115121
!(System.getProperty("os.name").matches("^.*[11|2025]$") ||
116122
new OSVersion(10, 0).compareTo(OSVersion.current()) > 0);
117123
test("ReservedName", resvPre, resvSuf, exceptionExpected);
124+
125+
System.out.println("OS name: " + System.getProperty("os.name") + "\n" +
126+
"OS version: " + OSVersion.current());
127+
128+
// Here the test is for whether File.createTempFile hangs, so whether
129+
// an exception is thrown is ignored: expectedException == null
130+
test("ReservedName", resvPre, resvSuf, null);
118131
}
119132
}

0 commit comments

Comments
 (0)