Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions jdk/test/java/io/File/createTempFile/SpecialTempFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@
import java.io.IOException;

public class SpecialTempFile {

//
// If exceptionExpected == null, then any IOException thrown by
// File.createTempFile is ignored.
//
private static void test(String name, String[] prefix, String[] suffix,
boolean exceptionExpected) throws IOException
Boolean exceptionExpected) throws IOException
{
if (prefix == null || suffix == null
|| prefix.length != suffix.length)
Expand All @@ -61,19 +64,21 @@ private static void test(String name, String[] prefix, String[] suffix,
else
f = File.createTempFile(prefix[i], suffix[i], new File(dir));
} catch (IOException e) {
if (exceptionExpected) {
if (e.getMessage().startsWith(exceptionMsg))
exceptionThrown = true;
else
System.out.println("Wrong error message:" +
e.getMessage());
} else {
throw e;
if (exceptionExpected != null) {
if (exceptionExpected) {
if (e.getMessage().startsWith(exceptionMsg))
exceptionThrown = true;
else
System.out.println("Wrong error message:" +
e.getMessage());
} else {
throw e;
}

if (exceptionExpected && (!exceptionThrown || f != null))
throw new RuntimeException("IOException expected");
}
}

if (exceptionExpected && (!exceptionThrown || f != null))
throw new RuntimeException("IOException is expected");
}
}
}
Expand Down Expand Up @@ -106,6 +111,11 @@ public static void main(String[] args) throws Exception {
// Test JDK-8013827
String[] resvPre = { "LPT1.package.zip", "com7.4.package.zip" };
String[] resvSuf = { ".temp", ".temp" };
test("ReservedName", resvPre, resvSuf, true);
System.out.println("OS name: " + StaticProperty.osName() + "\n" +
"OS version: " + OSVersion.current());

// Here the test is for whether File.createTempFile hangs, so whether
// an exception is thrown is ignored: expectedException == null
test("ReservedName", resvPre, resvSuf, null);
}
}