From c188594731e57ca8c321bacb88b9a267cc9a6861 Mon Sep 17 00:00:00 2001 From: Martin van Dinther Date: Thu, 1 Feb 2024 14:32:05 +0100 Subject: [PATCH] Also catch java.net.URISyntaxException and java.net.MalformedURLException and convert them to an IOException. --- tests/TLSTester.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/TLSTester.java b/tests/TLSTester.java index d9f0561..f65327d 100644 --- a/tests/TLSTester.java +++ b/tests/TLSTester.java @@ -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();