Skip to content

Commit

Permalink
handle uncaught NPE causing App termination in prolific driver contro…
Browse files Browse the repository at this point in the history
…lline background thread
  • Loading branch information
kai-morich committed May 13, 2024
1 parent 28506a9 commit 9bc3834
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class ProlificSerialPort extends CommonUsbSerialPort {
private volatile Thread mReadStatusThread = null;
private final Object mReadStatusThreadLock = new Object();
private boolean mStopReadStatusThread = false;
private IOException mReadStatusException = null;
private Exception mReadStatusException = null;


public ProlificSerialPort(UsbDevice device, int portNumber) {
Expand Down Expand Up @@ -201,8 +201,8 @@ private void setControlLines(int newControlLinesValue) throws IOException {

private void readStatusThreadFunction() {
try {
byte[] buffer = new byte[STATUS_BUFFER_SIZE];
while (!mStopReadStatusThread) {
byte[] buffer = new byte[STATUS_BUFFER_SIZE];
long endTime = MonotonicClock.millis() + 500;
int readBytesCount = mConnection.bulkTransfer(mInterruptEndpoint, buffer, STATUS_BUFFER_SIZE, 500);
if(readBytesCount == -1)
Expand All @@ -217,8 +217,9 @@ private void readStatusThreadFunction() {
}
}
}
} catch (IOException e) {
mReadStatusException = e;
} catch (Exception e) {
if (isOpen())
mReadStatusException = e;
}
//Log.d(TAG, "end control line status thread " + mStopReadStatusThread + " " + (mReadStatusException == null ? "-" : mReadStatusException.getMessage()));
}
Expand Down Expand Up @@ -249,8 +250,8 @@ private int getStatus() throws IOException {
}
}

/* throw and clear an exception which occured in the status read thread */
IOException readStatusException = mReadStatusException;
/* throw and clear an exception which occurred in the status read thread */
Exception readStatusException = mReadStatusException;
if (mReadStatusException != null) {
mReadStatusException = null;
throw new IOException(readStatusException);
Expand Down

0 comments on commit 9bc3834

Please sign in to comment.