Skip to content

Commit a11c50a

Browse files
committed
Guard against null PluginCall in handleCommunicationError
1 parent 527b17e commit a11c50a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

android/app/src/main/java/betaflight/configurator/plugin/SocketPlugin.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,18 @@ private void handleCommunicationError(Exception error, String message, PluginCal
288288
state.set(ConnectionState.ERROR);
289289
closeResourcesInternal();
290290
state.set(ConnectionState.DISCONNECTED);
291-
call.reject(message + ": " + error.getMessage());
291+
292+
String fullMsg = message + ": " + (error != null ? error.getMessage() : "unknown error");
293+
if (call != null) {
294+
call.reject(fullMsg);
295+
} else {
296+
// No PluginCall available (e.g., background reader thread). Log the error.
297+
Log.e(TAG, fullMsg, error);
298+
// Optionally notify listeners (commented to avoid duplicate notifications):
299+
// JSObject err = new JSObject();
300+
// err.put("error", fullMsg);
301+
// notifyListeners("socketError", err);
302+
}
292303
Log.e(TAG, message, error);
293304
} finally {
294305
socketLock.unlock();

0 commit comments

Comments
 (0)