Bug fix: NPE when adding event count in ParamMapBucket (#494)

Signed-off-by: Eric Zhao <sczyh16@gmail.com>
This commit is contained in:
Eric Zhao 2019-02-20 13:57:05 +08:00 committed by GitHub
parent ee4a0d43a1
commit 020a63fdb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 3 deletions

View File

@ -59,9 +59,16 @@ public class ParamMapBucket {
}
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;
}
@ -74,4 +81,4 @@ public class ParamMapBucket {
}
public static final int DEFAULT_MAX_CAPACITY = 200;
}
}