changeset 10247:48f37afb002c

8048840: File.createTempFile has uninformative failure message Reviewed-by: martin, alanb
author jmanson
date Wed, 02 Jul 2014 14:14:17 -0700
parents 4ee22aef03c6
children 8c061305cf30
files src/share/classes/java/io/File.java test/java/io/File/NulFile.java
diffstat 2 files changed, 8 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/io/File.java	Wed Jul 02 10:21:23 2014 -0700
+++ b/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/test/java/io/File/NulFile.java	Wed Jul 02 10:21:23 2014 -0700
+++ b/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");