Skip to content

Commit cd2d725

Browse files
authored
Merge pull request #794 from pshipton/sptemp2025
Backport 8347740: java/io/File/createTempFile/SpecialTempFile.java failing
2 parents f35fb47 + 8719f84 commit cd2d725

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

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

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 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
@@ -21,6 +21,12 @@
2121
* questions.
2222
*/
2323

24+
/*
25+
* ===========================================================================
26+
* (c) Copyright IBM Corp. 2025, 2025 All Rights Reserved
27+
* ===========================================================================
28+
*/
29+
2430
/*
2531
* @test
2632
* @bug 8013827 8011950 8017212 8025128
@@ -32,9 +38,12 @@
3238
import java.io.IOException;
3339

3440
public class SpecialTempFile {
35-
41+
//
42+
// If exceptionExpected == null, then any IOException thrown by
43+
// File.createTempFile is ignored.
44+
//
3645
private static void test(String name, String[] prefix, String[] suffix,
37-
boolean exceptionExpected) throws IOException
46+
Boolean exceptionExpected) throws IOException
3847
{
3948
if (prefix == null || suffix == null
4049
|| prefix.length != suffix.length)
@@ -61,19 +70,21 @@ private static void test(String name, String[] prefix, String[] suffix,
6170
else
6271
f = File.createTempFile(prefix[i], suffix[i], new File(dir));
6372
} catch (IOException e) {
64-
if (exceptionExpected) {
65-
if (e.getMessage().startsWith(exceptionMsg))
66-
exceptionThrown = true;
67-
else
68-
System.out.println("Wrong error message:" +
69-
e.getMessage());
70-
} else {
71-
throw e;
73+
if (exceptionExpected != null) {
74+
if (exceptionExpected) {
75+
if (e.getMessage().startsWith(exceptionMsg))
76+
exceptionThrown = true;
77+
else
78+
System.out.println("Wrong error message:" +
79+
e.getMessage());
80+
} else {
81+
throw e;
82+
}
83+
84+
if (exceptionExpected && (!exceptionThrown || f != null))
85+
throw new RuntimeException("IOException expected");
7286
}
7387
}
74-
75-
if (exceptionExpected && (!exceptionThrown || f != null))
76-
throw new RuntimeException("IOException is expected");
7788
}
7889
}
7990
}
@@ -106,6 +117,12 @@ public static void main(String[] args) throws Exception {
106117
// Test JDK-8013827
107118
String[] resvPre = { "LPT1.package.zip", "com7.4.package.zip" };
108119
String[] resvSuf = { ".temp", ".temp" };
109-
test("ReservedName", resvPre, resvSuf, true);
120+
121+
System.out.println("OS name: " + System.getProperty("os.name") + "\n" +
122+
"OS version: " + System.getProperty("os.version"));
123+
124+
// Here the test is for whether File.createTempFile hangs, so whether
125+
// an exception is thrown is ignored: expectedException == null
126+
test("ReservedName", resvPre, resvSuf, null);
110127
}
111128
}

0 commit comments

Comments
 (0)