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

HashMap.putIfAbsent() requires minSdkVersion>=24 #179

Closed
2 of 10 tasks
chaulio opened this issue Aug 6, 2021 · 1 comment
Closed
2 of 10 tasks

HashMap.putIfAbsent() requires minSdkVersion>=24 #179

chaulio opened this issue Aug 6, 2021 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@chaulio
Copy link

chaulio commented Aug 6, 2021

Platform on which you observed the bug:

  • Android
  • iOS
  • Other
  • Platform is not relevant for this bug

Device on which you observed the bug:

  • Polar OH1
  • Polar Verity Sense
  • Polar H10
  • Polar H9
  • Other
  • Device is not relevant for this bug

Describe the bug

A user reported this crash on an Android 5.0 (API 21) device:

Fatal Exception: java.lang.NoSuchMethodError: No virtual method putIfAbsent(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; in class Ljava/util/HashMap; or its super classes (declaration of 'java.util.HashMap' appears in /system/framework/core-libart.jar)
       at com.androidcommunications.polar.api.ble.model.gatt.BleGattBase.addCharacteristic(BleGattBase.java:306)
       at com.androidcommunications.polar.api.ble.model.gatt.BleGattBase.addCharacteristicNotification(BleGattBase.java:280)
       at com.androidcommunications.polar.api.ble.model.gatt.client.psftp.BlePsFtpClient.<init>(BlePsFtpClient.java:64)
       at com.androidcommunications.polar.api.ble.model.gatt.BleGattFactory.getRemoteServices(BleGattFactory.java:41)
       at com.androidcommunications.polar.enpoints.ble.bluedroid.host.BDDeviceSessionImpl.<init>(BDDeviceSessionImpl.java:80)
       at com.androidcommunications.polar.enpoints.ble.bluedroid.host.BDDeviceListenerImpl.deviceDiscovered(BDDeviceListenerImpl.java:301)
       at com.androidcommunications.polar.enpoints.ble.bluedroid.host.BDScanCallback.onScanResult(BDScanCallback.java:273)
       at android.bluetooth.le.BluetoothLeScanner$BleScanCallbackWrapper$1.run(BluetoothLeScanner.java:337)
       at android.os.Handler.handleCallback(Handler.java:815)
       at android.os.Handler.dispatchMessage(Handler.java:104)
       at android.os.Looper.loop(Looper.java:194)
       at android.app.ActivityThread.main(ActivityThread.java:5537)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:956)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:751)

It turns out that calling HashMap.putIfAbsent() requires minSdkVersion>=24, at least according to the warning shown by Android Studio when I try to use that in my code.

In your 'Getting Started' instructions, you set minSdkVersion=21. So I believe it would make sense to either change this to 24, or to stop using putIfAbsent() - it's quite trivial to use containsKey()+put() instead.

Thanks!

How to Reproduce
Try to detect Polar devices on an Android device with Android 5.0, 5.1 or 6.0.

Expected behavior
No crash.

@chaulio chaulio added the bug Something isn't working label Aug 6, 2021
@JOikarinen JOikarinen self-assigned this Aug 10, 2021
JOikarinen added a commit that referenced this issue Aug 10, 2021
…hich only available from Android API 24 onwards
@JOikarinen
Copy link
Contributor

Fix released in 3.2.1

Rexios80 pushed a commit to Rexios80/polar-ble-sdk that referenced this issue Oct 11, 2022
…putIfAbsent which only available from Android API 24 onwards
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants