Skip to content

Commit

Permalink
Merge pull request #716 from AltBeacon/fix-ranged-beacon-null-pointer
Browse files Browse the repository at this point in the history
Fix NPE on RangedBeacon per #638
  • Loading branch information
davidgyoung authored Sep 1, 2018
2 parents 1dd7545 + 9a1361d commit edee7c4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
### Development

Bug Fixes:
- Prevent crash caused by internal Android exception when stopping scanning (#724, David G. Young)
- Fix Android 8 crashing apps on background monitoring/ranging data delivery (#720, David G. Young)
- Fix intermittent NPE on ranging beacons (#716, Federico Bertoli, David G. Young)
- Stop running scheduled jobs to do scans after last consumer unbound. (#702, David G. Young)
- Prevent crash caused by internal Android exception when stopping scanning (#724, David G. Young)

### 2.15 / 2018-07-04

Expand Down
38 changes: 20 additions & 18 deletions src/main/java/org/altbeacon/beacon/service/RangeState.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public Callback getCallback() {
}

public void addBeacon(Beacon beacon) {
if (mRangedBeacons.containsKey(beacon)) {
RangedBeacon rangedBeacon = mRangedBeacons.get(beacon);
RangedBeacon rangedBeacon = mRangedBeacons.get(beacon);
if (rangedBeacon != null) {
if (LogManager.isVerboseLoggingEnabled()) {
LogManager.d(TAG, "adding %s to existing range for: %s", beacon, rangedBeacon);
}
Expand All @@ -71,23 +71,25 @@ public synchronized Collection<Beacon> finalizeBeacons() {
synchronized (mRangedBeacons) {
for (Beacon beacon : mRangedBeacons.keySet()) {
RangedBeacon rangedBeacon = mRangedBeacons.get(beacon);
if (rangedBeacon.isTracked()) {
rangedBeacon.commitMeasurements(); // calculates accuracy
if (!rangedBeacon.noMeasurementsAvailable()) {
finalizedBeacons.add(rangedBeacon.getBeacon());
if (rangedBeacon != null) {
if (rangedBeacon.isTracked()) {
rangedBeacon.commitMeasurements(); // calculates accuracy
if (!rangedBeacon.noMeasurementsAvailable()) {
finalizedBeacons.add(rangedBeacon.getBeacon());
}
}
// If we still have useful measurements, keep it around but mark it as not
// tracked anymore so we don't pass it on as visible unless it is seen again
if (!rangedBeacon.noMeasurementsAvailable() == true) {
//if TrackingCache is enabled, allow beacon to not receive
//measurements for a certain amount of time
if (!sUseTrackingCache || rangedBeacon.isExpired())
rangedBeacon.setTracked(false);
newRangedBeacons.put(beacon, rangedBeacon);
}
else {
LogManager.d(TAG, "Dumping beacon from RangeState because it has no recent measurements.");
}
}
// If we still have useful measurements, keep it around but mark it as not
// tracked anymore so we don't pass it on as visible unless it is seen again
if (!rangedBeacon.noMeasurementsAvailable() == true) {
//if TrackingCache is enabled, allow beacon to not receive
//measurements for a certain amount of time
if (!sUseTrackingCache || rangedBeacon.isExpired())
rangedBeacon.setTracked(false);
newRangedBeacons.put(beacon, rangedBeacon);
}
else {
LogManager.d(TAG, "Dumping beacon from RangeState because it has no recent measurements.");
}
}
mRangedBeacons = newRangedBeacons;
Expand Down

0 comments on commit edee7c4

Please sign in to comment.