8048840: File.createTempFile has uninformative failure message
authorjmanson
Wed, 02 Jul 2014 14:14:17 -0700
changeset 25223 4d33af5975a5
parent 25222 5d63cd3696d6
child 25224 7c7e029826e1
8048840: File.createTempFile has uninformative failure message Reviewed-by: martin, alanb
jdk/src/share/classes/java/io/File.java
jdk/test/java/io/File/NulFile.java
--- a/jdk/src/share/classes/java/io/File.java	Wed Jul 02 10:21:23 2014 -0700
+++ b/jdk/src/share/classes/java/io/File.java	Wed Jul 02 14:14:17 2014 -0700
@@ -1997,8 +1997,10 @@
                                       File directory)
         throws IOException
     {
-        if (prefix.length() < 3)
-            throw new IllegalArgumentException("Prefix string too short");
+        if (prefix.length() < 3) {
+            throw new IllegalArgumentException("Prefix string \"" + prefix +
+                "\" too short: length must be at least 3");
+        }
         if (suffix == null)
             suffix = ".tmp";
 
--- a/jdk/test/java/io/File/NulFile.java	Wed Jul 02 10:21:23 2014 -0700
+++ b/jdk/test/java/io/File/NulFile.java	Wed Jul 02 14:14:17 2014 -0700
@@ -602,7 +602,10 @@
             try {
                 File.createTempFile(prefix, suffix, directory);
             } catch (IllegalArgumentException ex) {
-                if ("Prefix string too short".equals(ex.getMessage()))
+                String actual = ex.getMessage();
+                String expected = "Prefix string \"" + prefix +
+                    "\" too short: length must be at least 3";
+                if (actual != null && actual.equals(expected))
                     exceptionThrown = true;
             } catch (IOException ioe) {
                 System.err.println("IOException happens in testCreateTempFile");