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

[Beta6] NoSuchElementException (Nexus 4 only) #37

Closed
ghost opened this issue Oct 25, 2018 · 4 comments
Closed

[Beta6] NoSuchElementException (Nexus 4 only) #37

ghost opened this issue Oct 25, 2018 · 4 comments
Assignees
Labels
Milestone

Comments

@ghost
Copy link

ghost commented Oct 25, 2018

Device: Nexus 4 running 5.1.1

    java.util.NoSuchElementException
        at java.util.LinkedList.removeFirstImpl(LinkedList.java:689)
        at java.util.LinkedList.removeFirst(LinkedList.java:676)
        at java.util.LinkedList.poll(LinkedList.java:895)
        at no.nordicsemi.android.ble.BleManager$BleManagerGattCallback.nextRequest(BleManager.java:2864)
        at no.nordicsemi.android.ble.BleManager$BleManagerGattCallback.onCharacteristicWriteSafe(BleManager.java:2482)
        at no.nordicsemi.android.ble.MainThreadBluetoothGattCallback.lambda$onCharacteristicWrite$3(MainThreadBluetoothGattCallback.java:128)
        at no.nordicsemi.android.ble.-$$Lambda$MainThreadBluetoothGattCallback$dAnXisth7CAlJFFhbDJ5X_192I0.run(lambda)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5254)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)```
@ghost
Copy link
Author

ghost commented Oct 25, 2018

It fails consistently on Nexus4, but the same operations on other devices never trigger this issue

@philips77 philips77 self-assigned this Oct 25, 2018
@philips77 philips77 added the bug label Oct 25, 2018
@philips77 philips77 added this to the Version 2.0 milestone Oct 25, 2018
@philips77 philips77 changed the title [Beta6] NoSuchElementException [Beta6] NoSuchElementException (Nexus 4 only) Oct 25, 2018
@philips77
Copy link
Member

This indeed is very interesting. The poll() should return null if the list is empty:
https://android.googlesource.com/platform/libcore/+/lollipop-mr1-release/luni/src/main/java/java/util/LinkedList.java#895

But if size != null, then it calls removeFirst() which actually may throw an exception in that case:
https://android.googlesource.com/platform/libcore/+/lollipop-mr1-release/luni/src/main/java/java/util/LinkedList.java#713
The question is, why the list is empty and has size > 0, or where does it get messed up. Looks like race condition.

I tried running nRF Blinky on Nexus 4 with Android 5.1.1, but didn't have problem like this. Do you add or remove tasks in some weird way in your app?
The only solution I can find is to enclose it all in try-catch to avoid crashes like this.

philips77 added a commit that referenced this issue Oct 30, 2018
@ghost ghost mentioned this issue Oct 31, 2018
@ghost
Copy link
Author

ghost commented Oct 31, 2018

I'm enqueuing multiple write requests at the same time. I don't see any failure before this NPE.

I'm thinking this is a bug on my side, they should be queued one after the other, but it's working on most devices.

Once next version is released, I'll test again and close the issue if I can't reproduce it. Thanks for the effort!

@philips77
Copy link
Member

I've released 2.0-beta7 with all the recent changes (except Reliable Write).

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

No branches or pull requests

1 participant