继续在findbug中获得可能的空指针取消引用吗?

时间:2020-04-27 20:43:43

标签: java pointers null findbugs

不明白为什么我一直在findbug中获得可能的空指针取消引用?我看到了许多有关如何修复它的示例,但是仍然出现错误。请给我一些提示。


static final ConcurrentHashMap<WFGaugeFactor,AtomicDouble> GAUGE_FACTORS = new ConcurrentHashMap<>();

public void handleGauge(String name, List<Tag> tags, double value) {
        String gaugeKey = gaugeKey(name, tags);

        if (GAUGE_CACHE != null && !GAUGE_CACHE.containsKey(gaugeKey)) {
            GAUGE_CACHE.put(gaugeKey, new AtomicDouble());
        }
        AtomicDouble gaugeValue =  getGaugeValue(gaugeKey) == null ? new AtomicDouble() : getGaugeValue(gaugeKey);
        System.out.println("Value:" + gaugeValue.doubleValue());
}

    @CheckForNull
    private AtomicDouble getGaugeValue(String key) {
        if (GAUGE_CACHE != null && GAUGE_CACHE.get(key) != null) {
            return GAUGE_CACHE.get(key);
        } else {
            return new AtomicDouble();
        }
    }

显示的错误:

Code    Warning
NP  Possible null pointer dereference in handleGauge(String, List, double) due to return value of called method
Details
NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE: Possible null pointer dereference due to return value of called method
The return value from a method is dereferenced without a null check, and the return value of that method is one that should generally be checked for null. This may lead to a NullPointerException when the code is executed.```

0 个答案:

没有答案