From 0ad2fb9899a4fdacb8f67c3a7027db6d09de603b Mon Sep 17 00:00:00 2001 From: pq Date: Wed, 23 Jul 2025 11:41:59 -0700 Subject: [PATCH] [CQ] cleanup dead/redundant code --- src/io/flutter/FlutterProjectActivity.kt | 2 +- .../flutter/actions/AttachDebuggerAction.java | 1 - src/io/flutter/android/AndroidEmulator.java | 1 - .../flutter/jxbrowser/JxBrowserManager.java | 1 - .../run/bazelTest/BazelTestLaunchState.java | 1 - .../test/DartTestEventsConverterZ.java | 2 +- src/io/flutter/utils/GradleUtils.java | 1 - .../vmService/frame/DartVmServiceValue.java | 6 +- .../dartlang/vm/service/VmServiceBase.java | 110 +++++++++++------- 9 files changed, 73 insertions(+), 52 deletions(-) diff --git a/src/io/flutter/FlutterProjectActivity.kt b/src/io/flutter/FlutterProjectActivity.kt index 87c642c173..b69d813de3 100644 --- a/src/io/flutter/FlutterProjectActivity.kt +++ b/src/io/flutter/FlutterProjectActivity.kt @@ -25,6 +25,6 @@ abstract class FlutterProjectActivity : ProjectActivity { } protected fun log(): Logger { - return log; + return log } } diff --git a/src/io/flutter/actions/AttachDebuggerAction.java b/src/io/flutter/actions/AttachDebuggerAction.java index 34ceeebd17..3ce12c2c93 100644 --- a/src/io/flutter/actions/AttachDebuggerAction.java +++ b/src/io/flutter/actions/AttachDebuggerAction.java @@ -226,7 +226,6 @@ private static class SelectConfigDialog extends DialogWrapper { //noinspection DataFlowIssue myPanel.add(myTextPane); init(); - //noinspection ConstantConditions getButton(getCancelAction()).setVisible(false); } diff --git a/src/io/flutter/android/AndroidEmulator.java b/src/io/flutter/android/AndroidEmulator.java index 7ced25d5bb..e1698f2bb5 100644 --- a/src/io/flutter/android/AndroidEmulator.java +++ b/src/io/flutter/android/AndroidEmulator.java @@ -140,7 +140,6 @@ public int hashCode() { // This is: EmulatorSettings.getInstance().getLaunchInToolWindow(); // Beginning in 2022.2, Android Studio moved this class to a different package. // IntelliJ did not adopt that change, and we cannot build separate plugins for the two. - @SuppressWarnings("ConstantConditions") private boolean getLaunchInToolWindow() { Class aClass; try { diff --git a/src/io/flutter/jxbrowser/JxBrowserManager.java b/src/io/flutter/jxbrowser/JxBrowserManager.java index 4ad5f83452..4e43eff599 100644 --- a/src/io/flutter/jxbrowser/JxBrowserManager.java +++ b/src/io/flutter/jxbrowser/JxBrowserManager.java @@ -6,7 +6,6 @@ package io.flutter.jxbrowser; import com.google.common.annotations.VisibleForTesting; -import com.intellij.openapi.application.ApplicationInfo; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProgressIndicator; diff --git a/src/io/flutter/run/bazelTest/BazelTestLaunchState.java b/src/io/flutter/run/bazelTest/BazelTestLaunchState.java index 8f8295af50..65ba55d86a 100644 --- a/src/io/flutter/run/bazelTest/BazelTestLaunchState.java +++ b/src/io/flutter/run/bazelTest/BazelTestLaunchState.java @@ -33,7 +33,6 @@ /** * The Bazel version of the {@link io.flutter.run.test.TestLaunchState}. */ -@SuppressWarnings("JavadocReference") public class BazelTestLaunchState extends CommandLineState { @NotNull private final BazelTestConfig config; diff --git a/src/io/flutter/test/DartTestEventsConverterZ.java b/src/io/flutter/test/DartTestEventsConverterZ.java index fc50cd3ed3..35398351a6 100644 --- a/src/io/flutter/test/DartTestEventsConverterZ.java +++ b/src/io/flutter/test/DartTestEventsConverterZ.java @@ -90,7 +90,7 @@ public class DartTestEventsConverterZ extends OutputToGeneralTestEventsConverter private String myLocation; private Key myCurrentOutputType; private ServiceMessageVisitor myCurrentVisitor; - private final HashMap myTestIdToTimestamp; + private final HashMap myTestIdToTimestamp; private final Map myTestData; private final Map myGroupData; private final Map mySuiteData; diff --git a/src/io/flutter/utils/GradleUtils.java b/src/io/flutter/utils/GradleUtils.java index 28d580928a..a49e03e3a0 100644 --- a/src/io/flutter/utils/GradleUtils.java +++ b/src/io/flutter/utils/GradleUtils.java @@ -211,7 +211,6 @@ private static GradleSettingsFile parseSettings(Project project) { } } - @SuppressWarnings("rawtypes") private static BuildModelContext makeBuildModelContext(Project project) { return BuildModelContext.create(project, new AndroidLocationProvider()); } diff --git a/src/io/flutter/vmService/frame/DartVmServiceValue.java b/src/io/flutter/vmService/frame/DartVmServiceValue.java index e2d494bbb6..8c2666eeb7 100644 --- a/src/io/flutter/vmService/frame/DartVmServiceValue.java +++ b/src/io/flutter/vmService/frame/DartVmServiceValue.java @@ -31,11 +31,11 @@ public class DartVmServiceValue extends XNamedValue { private static final LayeredIcon FINAL_FIELD_ICON = - new LayeredIcon().layeredIcon(() -> new Icon[]{AllIcons.Nodes.Field, AllIcons.Nodes.FinalMark}); + LayeredIcon.layeredIcon(() -> new Icon[]{AllIcons.Nodes.Field, AllIcons.Nodes.FinalMark}); private static final LayeredIcon STATIC_FIELD_ICON = - new LayeredIcon().layeredIcon(() -> new Icon[]{AllIcons.Nodes.Field, AllIcons.Nodes.StaticMark}); + LayeredIcon.layeredIcon(() -> new Icon[]{AllIcons.Nodes.Field, AllIcons.Nodes.StaticMark}); private static final LayeredIcon STATIC_FINAL_FIELD_ICON = - new LayeredIcon().layeredIcon(() -> new Icon[]{AllIcons.Nodes.Field, AllIcons.Nodes.StaticMark, AllIcons.Nodes.FinalMark}); + LayeredIcon.layeredIcon(() -> new Icon[]{AllIcons.Nodes.Field, AllIcons.Nodes.StaticMark, AllIcons.Nodes.FinalMark}); private static final String JSON_STRING_TEMPLATE = "'{'\"type\":\"@Instance\",\"class\":'{'\"type\":\"@Class\",\"fixedId\":\"true\",\"id\":\"classes/91\"," + "\"name\":\"_OneByteString\"'}',\"kind\":\"String\",\"length\":\"{0}\",\"valueAsString\":\"{1}\"'}'"; diff --git a/third_party/vmServiceDrivers/org/dartlang/vm/service/VmServiceBase.java b/third_party/vmServiceDrivers/org/dartlang/vm/service/VmServiceBase.java index 8e7e1c82ea..e1911ee8a4 100644 --- a/third_party/vmServiceDrivers/org/dartlang/vm/service/VmServiceBase.java +++ b/third_party/vmServiceDrivers/org/dartlang/vm/service/VmServiceBase.java @@ -53,7 +53,8 @@ public static VmService connect(final String url) throws IOException { URI uri; try { uri = new URI(url); - } catch (URISyntaxException e) { + } + catch (URISyntaxException e) { throw new IOException("Invalid URL: " + url, e); } String wsScheme = uri.getScheme(); @@ -65,7 +66,8 @@ public static VmService connect(final String url) throws IOException { WebSocket webSocket; try { webSocket = new WebSocket(uri); - } catch (WebSocketException e) { + } + catch (WebSocketException e) { throw new IOException("Failed to create websocket: " + url, e); } final VmService vmService = new VmService(); @@ -84,7 +86,8 @@ public void onMessage(WebSocketMessage message) { Logging.getLogger().logInformation("VM message: " + message.getText()); try { vmService.processMessage(message.getText()); - } catch (Exception e) { + } + catch (Exception e) { Logging.getLogger().logError(e.getMessage(), e); } } @@ -106,12 +109,13 @@ public void onPong() { }); // Establish WebSocket Connection - //noinspection TryWithIdenticalCatches try { webSocket.connect(); - } catch (WebSocketException e) { + } + catch (WebSocketException e) { throw new IOException("Failed to connect: " + url, e); - } catch (ArrayIndexOutOfBoundsException e) { + } + catch (ArrayIndexOutOfBoundsException e) { // The weberknecht can occasionally throw an array index exception if a connect terminates on initial connect // (de.roderick.weberknecht.WebSocket.connect, WebSocket.java:126). throw new IOException("Failed to connect: " + url, e); @@ -125,7 +129,7 @@ public void onPong() { @Override public void onError(RPCError error) { String msg = "Failed to determine protocol version: " + error.getCode() + "\n message: " - + error.getMessage() + "\n details: " + error.getDetails(); + + error.getMessage() + "\n details: " + error.getDetails(); Logging.getLogger().logInformation(msg); errMsg[0] = msg; } @@ -145,7 +149,8 @@ public void received(Version version) { if (errMsg[0] != null) { throw new IOException(errMsg[0]); } - } catch (InterruptedException e) { + } + catch (InterruptedException e) { throw new RuntimeException("Interrupted while waiting for response", e); } @@ -156,7 +161,6 @@ public void received(Version version) { * Connect to the VM observatory service on the given local port. * * @return an API object for interacting with the VM service (not {@code null}). - * * @deprecated prefer the Url based constructor {@link VmServiceBase#connect} */ @Deprecated @@ -253,8 +257,9 @@ public void onError(RPCError error) { @Override public void received(Obj response) { if (response instanceof Instance) { - consumer.received((Instance) response); - } else { + consumer.received((Instance)response); + } + else { onError(RPCError.unexpected("Instance", response)); } } @@ -280,8 +285,9 @@ public void onError(RPCError error) { @Override public void received(Obj response) { if (response instanceof Library) { - consumer.received((Library) response); - } else { + consumer.received((Library)response); + } + else { onError(RPCError.unexpected("Library", response)); } } @@ -343,7 +349,8 @@ public void connectionOpened() { for (VmServiceListener listener : new ArrayList<>(vmListeners)) { try { listener.connectionOpened(); - } catch (Exception e) { + } + catch (Exception e) { Logging.getLogger().logError("Exception notifying listener", e); } } @@ -353,7 +360,8 @@ private void forwardEvent(String streamId, Event event) { for (VmServiceListener listener : new ArrayList<>(vmListeners)) { try { listener.received(streamId, event); - } catch (Exception e) { + } + catch (Exception e) { Logging.getLogger().logError("Exception processing event: " + streamId + ", " + event.getJson(), e); } } @@ -363,7 +371,8 @@ public void connectionClosed() { for (VmServiceListener listener : new ArrayList<>(vmListeners)) { try { listener.connectionClosed(); - } catch (Exception e) { + } + catch (Exception e) { Logging.getLogger().logError("Exception notifying listener", e); } } @@ -394,8 +403,9 @@ void processMessage(String jsonText) { // Decode the JSON JsonObject json; try { - json = (JsonObject) JsonParser.parseString(jsonText); - } catch (Exception e) { + json = (JsonObject)JsonParser.parseString(jsonText); + } + catch (Exception e) { Logging.getLogger().logError("Parse message failed: " + jsonText, e); return; } @@ -415,12 +425,15 @@ void processMessage(String jsonText) { } if (json.has("id")) { processRequest(json); - } else { + } + else { processNotification(json); } - } else if (json.has("result") || json.has("error")) { + } + else if (json.has("result") || json.has("error")) { processResponse(json); - } else { + } + else { Logging.getLogger().logError("Malformed message"); } } @@ -433,7 +446,8 @@ void processRequest(JsonObject json) { String id; try { id = json.get(ID).getAsString(); - } catch (Exception e) { + } + catch (Exception e) { final String message = "Request malformed " + ID; Logging.getLogger().logError(message, e); final JsonObject error = new JsonObject(); @@ -449,7 +463,8 @@ void processRequest(JsonObject json) { String method; try { method = json.get(METHOD).getAsString(); - } catch (Exception e) { + } + catch (Exception e) { final String message = "Request malformed " + METHOD; Logging.getLogger().logError(message, e); final JsonObject error = new JsonObject(); @@ -463,7 +478,8 @@ void processRequest(JsonObject json) { JsonObject params; try { params = json.get(PARAMS).getAsJsonObject(); - } catch (Exception e) { + } + catch (Exception e) { final String message = "Request malformed " + METHOD; Logging.getLogger().logError(message, e); final JsonObject error = new JsonObject(); @@ -504,7 +520,8 @@ public void error(int code, String message, JsonObject data) { requestSink.add(response); } }); - } catch (Exception e) { + } + catch (Exception e) { final String message = "Internal Server Error"; Logging.getLogger().logError(message, e); final JsonObject error = new JsonObject(); @@ -516,28 +533,30 @@ public void error(int code, String message, JsonObject data) { } private static final RemoteServiceCompleter ignoreCallback = - new RemoteServiceCompleter() { - public void result(JsonObject result) { - // ignore - } + new RemoteServiceCompleter() { + public void result(JsonObject result) { + // ignore + } - public void error(int code, String message, JsonObject data) { - // ignore - } - }; + public void error(int code, String message, JsonObject data) { + // ignore + } + }; void processNotification(JsonObject json) { String method; try { method = json.get(METHOD).getAsString(); - } catch (Exception e) { + } + catch (Exception e) { Logging.getLogger().logError("Request malformed " + METHOD, e); return; } JsonObject params; try { params = json.get(PARAMS).getAsJsonObject(); - } catch (Exception e) { + } + catch (Exception e) { Logging.getLogger().logError("Event missing " + PARAMS, e); return; } @@ -545,19 +564,22 @@ void processNotification(JsonObject json) { String streamId; try { streamId = params.get(STREAM_ID).getAsString(); - } catch (Exception e) { + } + catch (Exception e) { Logging.getLogger().logError("Event missing " + STREAM_ID, e); return; } Event event; try { event = new Event(params.get(EVENT).getAsJsonObject()); - } catch (Exception e) { + } + catch (Exception e) { Logging.getLogger().logError("Event missing " + EVENT, e); return; } forwardEvent(streamId, event); - } else { + } + else { if (!remoteServiceRunners.containsKey(method)) { Logging.getLogger().logError("Unknown service " + method); return; @@ -566,7 +588,8 @@ void processNotification(JsonObject json) { final RemoteServiceRunner runner = remoteServiceRunners.get(method); try { runner.run(params, ignoreCallback); - } catch (Exception e) { + } + catch (Exception e) { Logging.getLogger().logError("Internal Server Error", e); } } @@ -587,7 +610,8 @@ void processResponse(JsonObject json) { String id; try { id = idElem.getAsString(); - } catch (Exception e) { + } + catch (Exception e) { Logging.getLogger().logError("Response missing " + ID, e); return; } @@ -603,7 +627,8 @@ void processResponse(JsonObject json) { JsonObject result; try { result = resultElem.getAsJsonObject(); - } catch (Exception e) { + } + catch (Exception e) { Logging.getLogger().logError("Response has invalid " + RESULT, e); return; } @@ -626,7 +651,8 @@ else if (!(consumer instanceof ServiceExtensionConsumer)) { JsonObject error; try { error = resultElem.getAsJsonObject(); - } catch (Exception e) { + } + catch (Exception e) { Logging.getLogger().logError("Response has invalid " + RESULT, e); return; }