Skip to content

Commit 6cee9cd

Browse files
authored
[CQ] migrate off deprecated URL constructor invocations (#8495)
As of Java 20, `URL(uri)` is deprecated in favor of `URI(uri).toURL()`. See: https://bugs.openjdk.org/browse/JDK-8296385?jql=parent%3DJDK-8294241 --- - [x] I’ve reviewed the contributor guide and applied the relevant portions to this PR. <details> <summary>Contribution guidelines:</summary><br> - See our [contributor guide]([https://github.com/dart-lang/sdk/blob/main/CONTRIBUTING.md](https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview) for general expectations for PRs. - Larger or significant changes should be discussed in an issue before creating a PR. - Dart contributions to our repos should follow the [Dart style guide](https://dart.dev/guides/language/effective-dart) and use `dart format`. - Java and Kotlin contributions should strive to follow Java and Kotlin best practices ([discussion](#8098)). </details>
1 parent 677ca5e commit 6cee9cd

File tree

2 files changed

+38
-21
lines changed

2 files changed

+38
-21
lines changed

src/io/flutter/run/daemon/FlutterApp.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@
4545
import io.flutter.run.FlutterLaunchMode;
4646
import io.flutter.run.common.RunMode;
4747
import io.flutter.settings.FlutterSettings;
48-
import io.flutter.utils.*;
48+
import io.flutter.utils.MostlySilentColoredProcessHandler;
49+
import io.flutter.utils.ProgressHelper;
50+
import io.flutter.utils.StreamSubscription;
51+
import io.flutter.utils.UrlUtils;
52+
import io.flutter.utils.VmServiceListenerAdapter;
4953
import io.flutter.vmService.ServiceExtensions;
5054
import io.flutter.vmService.VMServiceManager;
5155
import org.dartlang.vm.service.VmService;
@@ -55,9 +59,18 @@
5559

5660
import java.io.File;
5761
import java.net.MalformedURLException;
58-
import java.net.URL;
59-
import java.util.*;
60-
import java.util.concurrent.*;
62+
import java.net.URI;
63+
import java.net.URISyntaxException;
64+
import java.util.ArrayList;
65+
import java.util.EventListener;
66+
import java.util.HashMap;
67+
import java.util.List;
68+
import java.util.Map;
69+
import java.util.concurrent.CompletableFuture;
70+
import java.util.concurrent.Future;
71+
import java.util.concurrent.FutureTask;
72+
import java.util.concurrent.TimeUnit;
73+
import java.util.concurrent.TimeoutException;
6174
import java.util.concurrent.atomic.AtomicReference;
6275
import java.util.function.Consumer;
6376

@@ -765,12 +778,12 @@ public void onAppDebugPort(@NotNull DaemonEvent.AppDebugPort debugInfo) {
765778
if (uri.startsWith("file:")) {
766779
// Convert the file: url to a path.
767780
try {
768-
uri = new URL(uri).getPath();
781+
uri = new URI(uri).toURL().getPath();
769782
if (uri.endsWith(File.separator)) {
770783
uri = uri.substring(0, uri.length() - 1);
771784
}
772785
}
773-
catch (MalformedURLException e) {
786+
catch (IllegalArgumentException | MalformedURLException | URISyntaxException e) {
774787
// ignore
775788
}
776789
}
@@ -844,7 +857,8 @@ private void sendDtdRequest(@NotNull DtdRequest dtdRequest, @NotNull JsonObject
844857
final JsonPrimitive type = result != null ? result.getAsJsonPrimitive("type") : null;
845858
if (type != null && "Success".equals(type.getAsString())) {
846859
LOG.info("Successful request " + dtdRequest.type + " to DTD with params: " + initialParams);
847-
} else {
860+
}
861+
else {
848862
LOG.warn("Failed request " + dtdRequest.type + "to DTD with params: " + initialParams);
849863
LOG.warn("Result: " + result);
850864
}

src/io/flutter/utils/UrlUtils.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
package io.flutter.utils;
22

33
import java.net.MalformedURLException;
4+
import java.net.URI;
5+
import java.net.URISyntaxException;
46
import java.net.URL;
57

68
public class UrlUtils {
7-
public static String generateHtmlFragmentWithHrefTags(String input) {
8-
StringBuilder builder = new StringBuilder();
9-
for (String token : input.split(" ")) {
10-
if (!builder.isEmpty()) {
11-
builder.append(" ");
12-
}
13-
try {
14-
URL url = new URL(token);
15-
builder.append("<a href=\"").append(url).append("\">").append(url).append("</a>");
16-
} catch(MalformedURLException e) {
17-
builder.append(token);
18-
}
19-
}
20-
return builder.toString();
9+
public static String generateHtmlFragmentWithHrefTags(String input) {
10+
StringBuilder builder = new StringBuilder();
11+
for (String token : input.split(" ")) {
12+
if (!builder.isEmpty()) {
13+
builder.append(" ");
14+
}
15+
try {
16+
URL url = new URI(token).toURL();
17+
builder.append("<a href=\"").append(url).append("\">").append(url).append("</a>");
18+
}
19+
catch (IllegalArgumentException | MalformedURLException | URISyntaxException e) {
20+
builder.append(token);
21+
}
2122
}
23+
return builder.toString();
24+
}
2225
}

0 commit comments

Comments
 (0)