Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GenericUrl: improve the error message for malformed URLs #1486

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> SHORT_PATH_PARTS = Arrays.asList("", "path");
Expand Down