From 8eca7db3071b0826a1198ea980265fe964e846f2 Mon Sep 17 00:00:00 2001 From: Michael McMahon Date: Tue, 17 Aug 2010 14:49:01 +0100 Subject: [PATCH] 6339649: URI.create should include a detail message when throwing IllegalArgumentException Create enclosing exception with message of enclosed Reviewed-by: alanb, chegar --- jdk/src/share/classes/java/net/URI.java | 4 +--- jdk/test/java/net/URI/Test.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/jdk/src/share/classes/java/net/URI.java b/jdk/src/share/classes/java/net/URI.java index c05b7b2abaa..9b891b4b4dd 100644 --- a/jdk/src/share/classes/java/net/URI.java +++ b/jdk/src/share/classes/java/net/URI.java @@ -856,9 +856,7 @@ public final class URI try { return new URI(str); } catch (URISyntaxException x) { - IllegalArgumentException y = new IllegalArgumentException(); - y.initCause(x); - throw y; + throw new IllegalArgumentException(x.getMessage(), x); } } diff --git a/jdk/test/java/net/URI/Test.java b/jdk/test/java/net/URI/Test.java index 449f7d1c19e..39b5b9487d1 100644 --- a/jdk/test/java/net/URI/Test.java +++ b/jdk/test/java/net/URI/Test.java @@ -1536,6 +1536,7 @@ public class Test { serial(); urls(); npes(); + bugs(); } @@ -1572,6 +1573,19 @@ public class Test { } + // 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) {