diff --git a/google-http-client/src/main/java/com/google/api/client/http/GenericUrl.java b/google-http-client/src/main/java/com/google/api/client/http/GenericUrl.java index 3204f695e..6fe54dfb5 100644 --- a/google-http-client/src/main/java/com/google/api/client/http/GenericUrl.java +++ b/google-http-client/src/main/java/com/google/api/client/http/GenericUrl.java @@ -676,7 +676,7 @@ private static URL parseURL(String encodedUrl) { try { return new URL(encodedUrl); } catch (MalformedURLException e) { - throw new IllegalArgumentException(e); + throw new IllegalArgumentException("Malformed URL: \"" + encodedUrl + "\"", e); } } } diff --git a/google-http-client/src/test/java/com/google/api/client/http/GenericUrlTest.java b/google-http-client/src/test/java/com/google/api/client/http/GenericUrlTest.java index dbe1cc931..8910f3a00 100644 --- a/google-http-client/src/test/java/com/google/api/client/http/GenericUrlTest.java +++ b/google-http-client/src/test/java/com/google/api/client/http/GenericUrlTest.java @@ -14,6 +14,9 @@ package com.google.api.client.http; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + import com.google.api.client.util.Key; import java.net.MalformedURLException; import java.net.URI; @@ -98,6 +101,15 @@ public void testParse_noPath() { assertNull(url.getPathParts()); } + public void testParse_malformedUrl() { + try { + new GenericUrl("http://example.com:8080http://example.com:8080/"); + fail("expected " + IllegalArgumentException.class); + } catch (IllegalArgumentException e) { + assertThat(e.getMessage(), equalTo("Malformed URL: \"http://example.com:8080http://example.com:8080/\"")); + } + } + private static final String SHORT_PATH = "http://bar/path?a=b"; private static final List SHORT_PATH_PARTS = Arrays.asList("", "path");