Skip to content

Commit

Permalink
Also catch java.net.URISyntaxException and java.net.MalformedURLExcep…
Browse files Browse the repository at this point in the history
…tion and convert them to an IOException.
  • Loading branch information
mvdvm committed Feb 1, 2024
1 parent 2cdb94e commit c188594
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tests/TLSTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,14 @@ private byte[] fetchBytes(String resource) throws IOException {
}

private InputStream fetchData(String resource) throws IOException {
URL url = new java.net.URI("http://" + serverHost + ":" + serverPort + resource).toURL;
URL url;
try {
// Note: as of Java version 20 java.net.URL(String) constructor is deprecated.
// https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/net/URL.html#%3Cinit%3E(java.lang.String)
url = new java.net.URI("http://" + serverHost + ":" + serverPort + resource).toURL();
} catch (java.net.URISyntaxException | java.net.MalformedURLException e) {
throw new IOException(e.getMessage());
}
URLConnection conn = url.openConnection();
conn.connect();
return conn.getInputStream();
Expand Down

0 comments on commit c188594

Please sign in to comment.