3939import jdk .internal .util .StaticProperty ;
4040
4141public class SpecialTempFile {
42+ //
43+ // If exceptionExpected == null, then any IOException thrown by
44+ // File.createTempFile is ignored.
45+ //
4246 private static void test (String name , String [] prefix , String [] suffix ,
43- boolean exceptionExpected ) throws IOException
47+ Boolean exceptionExpected ) throws IOException
4448 {
4549 if (prefix == null || suffix == null
4650 || prefix .length != suffix .length )
@@ -67,19 +71,21 @@ private static void test(String name, String[] prefix, String[] suffix,
6771 f = File .createTempFile (prefix [i ], suffix [i ],
6872 tempDir .toFile ());
6973 } catch (IOException e ) {
70- if (exceptionExpected ) {
71- if (e .getMessage ().startsWith (exceptionMsg ))
72- exceptionThrown = true ;
73- else
74- System .out .println ("Wrong error message:" +
75- e .getMessage ());
76- } else {
77- throw e ;
74+ if (exceptionExpected != null ) {
75+ if (exceptionExpected ) {
76+ if (e .getMessage ().startsWith (exceptionMsg ))
77+ exceptionThrown = true ;
78+ else
79+ System .out .println ("Wrong error message:" +
80+ e .getMessage ());
81+ } else {
82+ throw e ;
83+ }
84+
85+ if (exceptionExpected && (!exceptionThrown || f != null ))
86+ throw new RuntimeException ("IOException expected" );
7887 }
7988 }
80-
81- if (exceptionExpected && (!exceptionThrown || f != null ))
82- throw new RuntimeException ("IOException is expected" );
8389 }
8490 }
8591 }
@@ -108,9 +114,12 @@ public static void main(String[] args) throws Exception {
108114 // Test JDK-8013827
109115 String [] resvPre = { "LPT1.package.zip" , "com7.4.package.zip" };
110116 String [] resvSuf = { ".temp" , ".temp" };
111- boolean exceptionExpected =
112- !(StaticProperty .osName ().matches ("^.*[11|2025]$" ) ||
113- new OSVersion (10 , 0 ).compareTo (OSVersion .current ()) > 0 );
114- test ("ReservedName" , resvPre , resvSuf , exceptionExpected );
117+
118+ System .out .println ("OS name: " + StaticProperty .osName () + "\n " +
119+ "OS version: " + OSVersion .current ());
120+
121+ // Here the test is for whether File.createTempFile hangs, so whether
122+ // an exception is thrown is ignored: expectedException == null
123+ test ("ReservedName" , resvPre , resvSuf , null );
115124 }
116125}
0 commit comments