Skip to content

Commit

Permalink
Bug fix: NPE when adding event count in ParamMapBucket (#494)
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Zhao <sczyh16@gmail.com>
  • Loading branch information
sczyh30 committed Feb 20, 2019
1 parent ee4a0d4 commit 020a63f
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,16 @@ public int get(RollingParamEvent event, Object value) {
}

public ParamMapBucket add(RollingParamEvent event, int count, Object value) {
data[event.ordinal()].putIfAbsent(value, new AtomicInteger());
AtomicInteger counter = data[event.ordinal()].get(value);
counter.addAndGet(count);
// Note: not strictly concise.
if (counter == null) {
AtomicInteger old = data[event.ordinal()].putIfAbsent(value, new AtomicInteger(count));
if (old != null) {
old.addAndGet(count);
}
} else {
counter.addAndGet(count);
}
return this;
}

Expand All @@ -74,4 +81,4 @@ public Set<Object> descendingKeySet(RollingParamEvent type) {
}

public static final int DEFAULT_MAX_CAPACITY = 200;
}
}

0 comments on commit 020a63f

Please sign in to comment.