您好,我有以下方法:
protected boolean shouldCheckLimit() {
if (startDate == null || endDate == null) {
return true;
}
final Long currentTime = System.currentTimeMillis();
if (startDate <= currentTime && currentTime < endDate) {
return true;
}
return false;
}
问题是findBugs发现了以下问题:
Possible null pointer dereference of TimeIntervalLimit.startDate in com.bet.blues.limit.TimeIntervalLimit.shouldCheckLimit() [Scary(8), Normal
我不得不提到 startDate 和 endDate 是 Long 变量。 我尝试在 if 条件下添加 null 检查,我也尝试使用 longValue() 方法,但没有结果。 你知道我该如何解决这个问题吗?可能是 fndBugs 方面的错误?
最佳答案
您收到错误是因为 startDate
(以及 endDate
)可能为 null
。但是您检查了它们是否为 null
,所以这应该是不可能的,对吧?
答案是两者都是全局的,并且可能随时被另一个线程设置为 null
。
关于java - FindBugs:可能的空指针取消引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31261425/