Selaa lähdekoodia

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

Signed-off-by: Eric Zhao <sczyh16@gmail.com>
master
Eric Zhao GitHub 6 vuotta sitten
vanhempi
commit
020a63fdb5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 muutettua tiedostoa jossa 10 lisäystä ja 3 poistoa
  1. +10
    -3
      sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/statistic/data/ParamMapBucket.java

+ 10
- 3
sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/statistic/data/ParamMapBucket.java Näytä tiedosto

@@ -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;
}
}

Loading…
Peruuta
Tallenna