Wrap URISyntaxException as IllegalArgumentException for Proxy#toURI.

master
Sutra Zhou 2020-06-24 13:24:45 +08:00
parent 236e5ade44
commit 6d3f2d9b64
1 changed files with 8 additions and 7 deletions

View File

@ -61,7 +61,7 @@ public class Proxy {
return password; return password;
} }
public URI toURI() throws URISyntaxException { public URI toURI() {
final StringBuilder userInfoBuffer = new StringBuilder(); final StringBuilder userInfoBuffer = new StringBuilder();
if (username != null) { if (username != null) {
userInfoBuffer.append(urlencode(username)); userInfoBuffer.append(urlencode(username));
@ -70,7 +70,12 @@ public class Proxy {
userInfoBuffer.append(":").append(urlencode(password)); userInfoBuffer.append(":").append(urlencode(password));
} }
final String userInfo = StringUtils.defaultIfEmpty(userInfoBuffer.toString(), null); final String userInfo = StringUtils.defaultIfEmpty(userInfoBuffer.toString(), null);
final URI uri = new URI(scheme, userInfo, host, port, null, null, null); URI uri;
try {
uri = new URI(scheme, userInfo, host, port, null, null, null);
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e.getMessage(), e);
}
return uri; return uri;
} }
@ -109,11 +114,7 @@ public class Proxy {
@Override @Override
public String toString() { public String toString() {
try { return this.toURI().toString();
return this.toURI().toString();
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
}
} }
} }