luontola / retrolambda

Backport of Java 8's lambda expressions to Java 7, 6 and 5
Apache License 2.0
3.54k stars 227 forks source link

Freak issue in Android #135

Open Nicba1010 opened 7 years ago

Nicba1010 commented 7 years ago

This is a freak issue I encountered during development of a certain android app.

This works:

return new BeaconScanner<>( // CODE CUT
                new BeaconScannerListener<Unit>() {
                    @Override
                    public void onBeaconFound(@NotNull BeaconScanner<? extends Unit> scanner,
                                              @NotNull BeaconMetaData metadata, Unit unit) {
                        //CODE CUT
                        Location location = LocationUtils.getInstance().getBestLocation();

                            LatLng latLng = new LatLng(location.getLatitude(), location
                                    .getLongitude());
                            Api.getAPI().updateData(
                                    address,
                                    location.getLongitude(),
                                    location.getLatitude()
                            ).enqueue(CALLBACK);
                        }
                    }
                });

This produces an error:

return new BeaconScanner<>( // CODE CUT
                (scanner, metadata, unit) -> {
                        //CODE CUT
                        Location location = LocationUtils.getInstance().getBestLocation();

                            LatLng latLng = new LatLng(location.getLatitude(), location
                                    .getLongitude());
                            Api.getAPI().updateData(
                                    address,
                                    location.getLongitude(),
                                    location.getLatitude()
                            ).enqueue(CALLBACK);
                });

Stacktrace:

Throwing new exception 'length=162; index=1404' with unexpected pending exception: java.lang.ArrayIndexOutOfBoundsException: length=162; index=1404
  at void project.service.SmartFindService.lambda$createScanner$0(project.service.SmartFindService, project.BeaconScanner, project.BeaconMetaData, kotlin.Unit) (SmartFindService.java:102)
  at void project.service.SmartFindService$$Lambda$1.onBeaconFound(project.BeaconScanner, project.BeaconMetaData, java.lang.Object) ((null):0)
  at void project.BeaconScanner$1.invoke(project.BeaconScanner, project.BeaconMetaData, java.lang.Object) (BeaconScanner.kt:30)
  at java.lang.Object project.BeaconScanner$1.invoke(java.lang.Object, java.lang.Object, java.lang.Object) (BeaconScanner.kt:16)
  at void project.BeaconScanner$callback$1.onScanResult(int, android.bluetooth.le.ScanResult) (BeaconScanner.kt:59)
  at void android.bluetooth.le.BluetoothLeScanner$BleScanCallbackWrapper$1.run() (BluetoothLeScanner.java:355)
  at void android.os.Handler.handleCallback(android.os.Message) (Handler.java:739)
  at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:95)
  at void android.os.Looper.loop() (Looper.java:234)
  at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:5526)
  at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
  at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:726)
  at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:616)
luontola commented 6 years ago

Can you create an SSCCE for reproducing this?