java - 在 findbug 中不断收到可能的空指针取消引用?
问题描述
不明白为什么我在 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.```
解决方案
推荐阅读
- python - 将 COCO 数据集导入 google colaboratory
- python - 如何从下面的代码中获取一个数据帧
- r - 模型中假阳性率为0.5时真阳性率是多少?
- node.js - 如何从节点 js 使用 AWS s3 实现 AWS Media Convert?
- python - 如何用python分割线并得到剩余的线
- linux - 如何在紧急模式下编辑 fstab?
- java - 如何在 java netbeans 中使用其他项目打开 .jar 文件(使用路径位置打开 .jar)?
- c++ - 当我将源代码传递给其参数时,QXmlQuery::setQuery() 无法查询
- git - JGit 是否支持 Webhooks?
- javascript - 在 jquery hover() 之后,css :hover 在我的元素上没有被激活