7023034: Files.createTempDirectory((Path)null, "temp") does not throw NPE
Reviewed-by: forax
--- a/jdk/src/share/classes/java/nio/file/Files.java Tue Mar 01 16:22:22 2011 +0800
+++ b/jdk/src/share/classes/java/nio/file/Files.java Tue Mar 01 12:03:44 2011 +0000
@@ -794,7 +794,8 @@
FileAttribute<?>... attrs)
throws IOException
{
- return TempFileHelper.createTempFile(dir, prefix, suffix, attrs);
+ return TempFileHelper.createTempFile(Objects.requireNonNull(dir),
+ prefix, suffix, attrs);
}
/**
@@ -891,7 +892,8 @@
FileAttribute<?>... attrs)
throws IOException
{
- return TempFileHelper.createTempDirectory(dir, prefix, attrs);
+ return TempFileHelper.createTempDirectory(Objects.requireNonNull(dir),
+ prefix, attrs);
}
/**
--- a/jdk/test/java/nio/file/Files/TemporaryFiles.java Tue Mar 01 16:22:22 2011 +0800
+++ b/jdk/test/java/nio/file/Files/TemporaryFiles.java Tue Mar 01 12:03:44 2011 +0000
@@ -22,7 +22,7 @@
*/
/* @test
- * @bug 4313887 6838333 7006126
+ * @bug 4313887 6838333 7006126 7023034
* @summary Unit test for Files.createTempXXX
* @library ..
*/
@@ -167,5 +167,31 @@
testInvalidFileTemp("../blah", null);
testInvalidFileTemp("dir/blah", null);
testInvalidFileTemp("blah", ".dat/foo");
+
+ // nulls
+ try {
+ Files.createTempFile("blah", ".tmp", (FileAttribute<?>[])null);
+ throw new RuntimeException("NullPointerException expected");
+ } catch (NullPointerException ignore) { }
+ try {
+ Files.createTempFile("blah", ".tmp", new FileAttribute<?>[] { null });
+ throw new RuntimeException("NullPointerException expected");
+ } catch (NullPointerException ignore) { }
+ try {
+ Files.createTempDirectory("blah", (FileAttribute<?>[])null);
+ throw new RuntimeException("NullPointerException expected");
+ } catch (NullPointerException ignore) { }
+ try {
+ Files.createTempDirectory("blah", new FileAttribute<?>[] { null });
+ throw new RuntimeException("NullPointerException expected");
+ } catch (NullPointerException ignore) { }
+ try {
+ Files.createTempFile((Path)null, "blah", ".tmp");
+ throw new RuntimeException("NullPointerException expected");
+ } catch (NullPointerException ignore) { }
+ try {
+ Files.createTempDirectory((Path)null, "blah");
+ throw new RuntimeException("NullPointerException expected");
+ } catch (NullPointerException ignore) { }
}
}