Skip to content

Commit

Permalink
Merge pull request #215 from AltBeacon/protect-against-npe
Browse files Browse the repository at this point in the history
Protect Against NPE in Iteration
  • Loading branch information
davidgyoung committed Jul 5, 2015
2 parents 1c720f3 + 0d276a9 commit fa66ce1
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/main/java/org/altbeacon/beacon/service/BeaconService.java
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,15 @@ private List<Region> matchingRegions(Beacon beacon, Collection<Region> regions)
Iterator<Region> regionIterator = regions.iterator();
while (regionIterator.hasNext()) {
Region region = regionIterator.next();
if (region.matchesBeacon(beacon)) {
matched.add(region);
} else {
LogManager.d(TAG, "This region (%s) does not match beacon: %s", region, beacon);
// Need to check if region is null in case it was removed from the collection by
// another thread during iteration
if (region != null) {
if (region.matchesBeacon(beacon)) {
matched.add(region);
} else {
LogManager.d(TAG, "This region (%s) does not match beacon: %s", region, beacon);
}
}

}

return matched;
Expand Down

0 comments on commit fa66ce1

Please sign in to comment.