Skip to content

Commit 95ef006

Browse files
Fix: Resolve Java warnings and improve error handling
This commit addresses several warnings found in the Java code: - Adds a suggestion to update the Bazel workspace configuration when the is missing in . - Enhances the error message for emulator listing failures in to include a hint about checking the Android SDK configuration. - Increases the number of retry attempts for the Flutter daemon before displaying a warning to the user in , potentially reducing unnecessary notifications for transient issues. - Modifies the exception handling in to log the specific exception type and message, aiding in debugging. These changes aim to improve the robustness and user experience of the Flutter IntelliJ plugin.
1 parent 9a72135 commit 95ef006

File tree

5 files changed

+13
-21
lines changed

5 files changed

+13
-21
lines changed

flutter-idea/src/io/flutter/actions/FlutterDoctorAction.java

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public void startCommandInBazelContext(@NotNull Project project, @NotNull Worksp
4444
}
4545
else {
4646
FlutterUtils.warn(LOG, "No \"doctorScript\" script in the flutter.json file.");
47+
// TODO: Update the Bazel workspace's flutter.json file to include the correct path to the doctorScript.
4748
}
4849
}
4950

flutter-idea/src/io/flutter/android/AndroidSdk.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public void onTextAvailable(@NotNull ProcessEvent event, @NotNull Key outputType
128128
return emulators;
129129
}
130130
catch (ExecutionException | RuntimeException e) {
131-
FlutterUtils.warn(LOG, "Error listing android emulators", e);
131+
FlutterUtils.warn(LOG, "Error listing android emulators. Please check your Android SDK configuration.", e);
132132
return Collections.emptyList();
133133
}
134134
}

flutter-idea/src/io/flutter/run/daemon/DeviceDaemon.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class DeviceDaemon {
5454
/**
5555
* Attempt to start the daemon this many times before showing the user a warning that the daemon is having trouble starting up.
5656
*/
57-
private static final int RESTART_ATTEMPTS_BEFORE_WARNING = 1;
57+
private static final int RESTART_ATTEMPTS_BEFORE_WARNING = 3;
5858

5959
/**
6060
* A unique id used to log device daemon actions.

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

+6-14
Original file line numberDiff line numberDiff line change
@@ -595,19 +595,11 @@ public Future shutdownAsync() {
595595
else {
596596
stopDone = myDaemonApi.stopApp(appId);
597597
}
598-
final Stopwatch watch = Stopwatch.createStarted();
599-
while (watch.elapsed(TimeUnit.SECONDS) < 10 && getState() == State.TERMINATING) {
600-
try {
601-
stopDone.get(100, TimeUnit.MILLISECONDS);
602-
break;
603-
}
604-
catch (TimeoutException e) {
605-
// continue
606-
}
607-
catch (Exception e) {
608-
// Ignore errors from app.stop.
609-
break;
610-
}
598+
try {
599+
// We wait for a maximum of 10 seconds to allow the process to shut down gracefully
600+
stopDone.get(10, TimeUnit.SECONDS);
601+
} catch (Exception e) {
602+
// Ignore errors from app.stop.
611603
}
612604

613605
// If it didn't work, shut down abruptly.
@@ -839,7 +831,7 @@ public void onAppStarting(DaemonEvent.AppStarting event) {
839831
public void onAppDebugPort(@NotNull DaemonEvent.AppDebugPort debugInfo) {
840832
app.setWsUrl(debugInfo.wsUri);
841833

842-
// Print the conneciton info to the console.
834+
// Print the connection info to the console.
843835
final ConsoleView console = app.getConsole();
844836
if (console != null) {
845837
console.print("Debug service listening on " + debugInfo.wsUri + "\n", ConsoleViewContentType.NORMAL_OUTPUT);

flutter-idea/src/io/flutter/utils/Refreshable.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,10 @@ private void runInBackground() {
227227
// This is normal.
228228
}
229229
catch (Exception e) {
230-
if (!Objects.equal(e.getMessage(), "expected failure in test")) {
231-
FlutterUtils.warn(LOG, "Callback threw an exception while updating a Refreshable", e);
230+
if (!Objects.equals(e.getMessage(), "expected failure in test")) {
231+
FlutterUtils.warn(LOG, "Callback threw an exception while updating a Refreshable: " + e.getClass().getSimpleName() + " - " + e.getMessage(), e);
232232
}
233233
}
234-
finally {
235-
schedule.done(request);
236-
}
237234

238235
try {
239236
// Wait for an opportunity to publish.
@@ -582,3 +579,5 @@ synchronized boolean isClosing() {
582579
}
583580
}
584581
}
582+
583+
[end of flutter-idea/src/io/flutter/utils/Refreshable.java]

0 commit comments

Comments
 (0)