Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix java.lang.ArrayIndexOutOfBoundsException in java.util.ArrayList.fastRemove (ArrayList.java:557) #321

Open
scottleibrand opened this issue Jul 24, 2020 · 3 comments
Assignees

Comments

@scottleibrand
Copy link
Contributor

Version 0.3(91)

Stacktrace

Reason

java.lang.ArrayIndexOutOfBoundsException

Link to App Center

@duskoo
Copy link
Collaborator

duskoo commented Aug 12, 2020

@scottleibrand I am unable to assign the issue to myself: can you add me to the Android team?

@scottleibrand
Copy link
Contributor Author

Done.

@duskoo duskoo self-assigned this Aug 14, 2020
@duskoo
Copy link
Collaborator

duskoo commented Aug 15, 2020

Stacktrace:
java.util.ArrayList.fastRemove ArrayList.java:557 java.util.ArrayList.remove ArrayList.java:540 org.tcncoalition.tcnclient.bluetooth.TcnBluetoothManager.dequeueFromAdvertising TcnBluetoothManager.kt:128 org.tcncoalition.tcnclient.bluetooth.TcnBluetoothManager.access$dequeueFromAdvertising TcnBluetoothManager.kt:34 org.tcncoalition.tcnclient.bluetooth.TcnBluetoothManager$changeOwnTcn$1.run TcnBluetoothManager.kt:114 java.util.concurrent.ThreadPoolExecutor.processTask ThreadPoolExecutor.java:1187 java.util.concurrent.ThreadPoolExecutor.runWorker ThreadPoolExecutor.java:1152 java.util.concurrent.ThreadPoolExecutor$Worker.run ThreadPoolExecutor.java:641 java.lang.Thread.run Thread.java:929
Crash originates in tcnclient lib.
Likely cause is concurrent modification of 'tcnAdvertisingQueue' (explains index value of -1):

private fun dequeueFromAdvertising(tcn: ByteArray?) { tcn ?: return tcnAdvertisingQueue.remove(tcn) Log.i(TAG, "Dequeued TCN=${Base64.encodeToString(tcn, Base64.NO_WRAP)} from advertising") }

From ArrayList.java:

Note that this implementation is not synchronized. If multiple threads access an ArrayList instance concurrently, and at least one of the threads modifies the list structurally, it must be synchronized externally. (A structural modification is any operation that adds or deletes one or more elements, or explicitly resizes the backing array; merely setting the value of an element is not a structural modification.) This is typically accomplished by synchronizing on some object that naturally encapsulates the list.

Proposed solution: a PR for tcnclient adding synchronization when modifying tcnAdvertisingQueue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants