1
1
/*
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.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
41
41
import jdk .test .lib .OSVersion ;
42
42
43
43
public class SpecialTempFile {
44
+ //
45
+ // If exceptionExpected == null, then any IOException thrown by
46
+ // File.createTempFile is ignored.
47
+ //
44
48
private static void test (String name , String [] prefix , String [] suffix ,
45
- boolean exceptionExpected ) throws IOException
49
+ Boolean exceptionExpected ) throws IOException
46
50
{
47
51
if (prefix == null || suffix == null
48
52
|| prefix .length != suffix .length )
@@ -69,19 +73,21 @@ private static void test(String name, String[] prefix, String[] suffix,
69
73
f = File .createTempFile (prefix [i ], suffix [i ],
70
74
tempDir .toFile ());
71
75
} 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" );
80
89
}
81
90
}
82
-
83
- if (exceptionExpected && (!exceptionThrown || f != null ))
84
- throw new RuntimeException ("IOException is expected" );
85
91
}
86
92
}
87
93
}
@@ -110,9 +116,12 @@ public static void main(String[] args) throws Exception {
110
116
// Test JDK-8013827
111
117
String [] resvPre = { "LPT1.package.zip" , "com7.4.package.zip" };
112
118
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 );
117
126
}
118
127
}
0 commit comments