changeset 3828:b7e763a573a4

7023034: Files.createTempDirectory((Path)null, "temp") does not throw NPE Reviewed-by: forax
author alanb
date Tue, 01 Mar 2011 12:03:44 +0000
parents f8bf888edf20
children 98d2d57d9e73 bc0c58d65e97
files src/share/classes/java/nio/file/Files.java test/java/nio/file/Files/TemporaryFiles.java
diffstat 2 files changed, 31 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/nio/file/Files.java	Tue Mar 01 16:22:22 2011 +0800
+++ b/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/test/java/nio/file/Files/TemporaryFiles.java	Tue Mar 01 16:22:22 2011 +0800
+++ b/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) { }
     }
 }