changeset 2661:42eaa082a4e6

6339649: URI.create should include a detail message when throwing IllegalArgumentException Summary: create enclosing exception with message of enclosed Reviewed-by: alanb, chegar
author michaelm
date Tue, 17 Aug 2010 14:49:01 +0100
parents 8329ebeabc10
children bfc3855a9341
files src/share/classes/java/net/URI.java test/java/net/URI/Test.java
diffstat 2 files changed, 15 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/net/URI.java	Mon Aug 16 15:36:13 2010 -0700
+++ b/src/share/classes/java/net/URI.java	Tue Aug 17 14:49:01 2010 +0100
@@ -856,9 +856,7 @@
         try {
             return new URI(str);
         } catch (URISyntaxException x) {
-            IllegalArgumentException y = new IllegalArgumentException();
-            y.initCause(x);
-            throw y;
+            throw new IllegalArgumentException(x.getMessage(), x);
         }
     }
 
--- a/test/java/net/URI/Test.java	Mon Aug 16 15:36:13 2010 -0700
+++ b/test/java/net/URI/Test.java	Tue Aug 17 14:49:01 2010 +0100
@@ -1536,6 +1536,7 @@
         serial();
         urls();
         npes();
+        bugs();
     }
 
 
@@ -1572,6 +1573,19 @@
     }
 
 
+    // miscellaneous bugs/rfes that don't fit in with the test framework
+
+    static void bugs() {
+        // 6339649 - include detail message from nested exception
+        try {
+            URI uri = URI.create("http://nowhere.net/should not be permitted");
+        } catch (IllegalArgumentException e) {
+            if ("".equals(e.getMessage()) || e.getMessage() == null) {
+                throw new RuntimeException ("No detail message");
+            }
+        }
+    }
+
     public static void main(String[] args) throws Exception {
         switch (args.length) {