AltBeacon / android-beacon-library

Allows Android apps to interact with BLE beacons
Apache License 2.0
2.84k stars 837 forks source link

App in StrictMode force-quits when ModelSpecificDistanceCalculator loads json file #72

Closed brianmuse closed 9 years ago

brianmuse commented 9 years ago

This is likely lower priority, but I wanted to make you aware of it. I have an app that force closes when in Android's strict mode when AltBeacon is loading the JSON file containing the device specific information. The error is:

java.lang.Throwable: Explicit termination method 'end' not called

This is likely due to the detectLeakedClosableObjects portion of the config below.

            StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                    .detectDiskReads()
                    .detectDiskWrites()
                    .detectNetwork()
                    .penaltyLog()
                    .build());
            StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                    .detectLeakedSqlLiteObjects()
                    .detectLeakedClosableObjects()
                    .penaltyLog()
                    .penaltyDeath()
                    .build());

This is the line that causes the crash: https://github.com/AltBeacon/android-beacon-library/blob/master/src/main/java/org/altbeacon/beacon/distance/ModelSpecificDistanceCalculator.java#L281

I wasn't able to replicate this on a Nexus 5, but can replicate consistently on a Nexus 6.

davidgyoung commented 9 years ago

Hopefully this change will fix that: 8ce1d7a35ce7c2e90cb07478ffd4e58bec1d49ac

The stream only gets used once for each time the app is run, failing to close it probably won't cause a problem. But it's best not to be sloppy anyway!