Skip to content

Commit 5ef651f

Browse files
authored
Replace usage of deprecated java.net.URL constructor with URI (#12755)
This commit replaces the usage of the deprecated java.net.URL constructor with URI, later converting toURL where necessary to interoperate with the URLConnection API.
1 parent a35573e commit 5ef651f

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

lucene/analysis/common/src/tools/java/org/apache/lucene/analysis/standard/GenerateJflexTLDMacros.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.InputStreamReader;
2222
import java.io.OutputStreamWriter;
2323
import java.io.Writer;
24+
import java.net.URI;
2425
import java.net.URL;
2526
import java.net.URLConnection;
2627
import java.nio.charset.StandardCharsets;
@@ -111,7 +112,7 @@ public static void main(String... args) throws Exception {
111112

112113
public GenerateJflexTLDMacros(String tldFileURL, String jflexFile, String tldListFile)
113114
throws Exception {
114-
this.tldFileURL = new URL(tldFileURL);
115+
this.tldFileURL = URI.create(tldFileURL).toURL();
115116
this.jflexMacroFile = Paths.get(jflexFile);
116117
this.tldListFile = Paths.get(tldListFile);
117118
}

lucene/analysis/icu/src/tools/java/org/apache/lucene/analysis/icu/GenerateUTR30DataFiles.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.io.OutputStream;
2828
import java.io.OutputStreamWriter;
2929
import java.io.Writer;
30+
import java.net.URI;
3031
import java.net.URL;
3132
import java.net.URLConnection;
3233
import java.nio.charset.StandardCharsets;
@@ -155,19 +156,19 @@ private static void expandDataFileRules(Path file) throws IOException {
155156
}
156157

157158
private static void getNFKCDataFilesFromIcuProject(String releaseTag) throws IOException {
158-
URL icuTagsURL = new URL(ICU_GIT_TAG_URL + "/");
159-
URL icuReleaseTagURL = new URL(icuTagsURL, releaseTag + "/");
160-
URL norm2url = new URL(icuReleaseTagURL, ICU_DATA_NORM2_PATH + "/");
159+
URI icuTagsURI = URI.create(ICU_GIT_TAG_URL + "/");
160+
URI icuReleaseTagURI = icuTagsURI.resolve(releaseTag + "/");
161+
URI norm2uri = icuReleaseTagURI.resolve(ICU_DATA_NORM2_PATH + "/");
161162

162163
System.err.print("Downloading " + NFKC_TXT + " ... ");
163-
download(new URL(norm2url, NFKC_TXT), NFKC_TXT);
164+
download(norm2uri.resolve(NFKC_TXT), NFKC_TXT);
164165
System.err.println("done.");
165166
System.err.print("Downloading " + NFKC_CF_TXT + " ... ");
166-
download(new URL(norm2url, NFKC_CF_TXT), NFKC_CF_TXT);
167+
download(norm2uri.resolve(NFKC_CF_TXT), NFKC_CF_TXT);
167168
System.err.println("done.");
168169

169170
System.err.print("Downloading " + NFKC_CF_TXT + " and making diacritic rules one-way ... ");
170-
URLConnection connection = openConnection(new URL(norm2url, NFC_TXT));
171+
URLConnection connection = openConnection(norm2uri.resolve(NFC_TXT).toURL());
171172
try (BufferedReader reader =
172173
new BufferedReader(
173174
new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8));
@@ -210,8 +211,8 @@ private static void getNFKCDataFilesFromIcuProject(String releaseTag) throws IOE
210211
System.err.println("done.");
211212
}
212213

213-
private static void download(URL url, String outputFile) throws IOException {
214-
final URLConnection connection = openConnection(url);
214+
private static void download(URI uri, String outputFile) throws IOException {
215+
final URLConnection connection = openConnection(uri.toURL());
215216
try (InputStream inputStream = connection.getInputStream();
216217
OutputStream outputStream = Files.newOutputStream(Path.of(outputFile))) {
217218
inputStream.transferTo(outputStream);

lucene/luke/src/java/org/apache/lucene/luke/app/desktop/util/URLLabel.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.awt.event.MouseEvent;
2424
import java.io.IOException;
2525
import java.net.MalformedURLException;
26+
import java.net.URI;
2627
import java.net.URISyntaxException;
2728
import java.net.URL;
2829
import javax.swing.JLabel;
@@ -37,8 +38,8 @@ public URLLabel(String text) {
3738
super(text);
3839

3940
try {
40-
this.link = new URL(text);
41-
} catch (MalformedURLException e) {
41+
this.link = (new URI(text)).toURL();
42+
} catch (URISyntaxException | MalformedURLException e) {
4243
throw new LukeException(e.getMessage(), e);
4344
}
4445

0 commit comments

Comments
 (0)