简体   繁体   English

FindBugs:可能的空指针取消引用

[英]FindBugs: Possible null pointer dereference

Hi I have the following method: 嗨,我有以下方法:

protected boolean shouldCheckLimit() {
    if (startDate == null || endDate == null) {
        return true;
    }
    final Long currentTime = System.currentTimeMillis();
    if (startDate <= currentTime && currentTime < endDate) {
        return true;
    }
    return false;
}

The problem is that findBugs found the following problem: 问题是findBugs发现了以下问题:

Possible null pointer dereference of TimeIntervalLimit.startDate in com.bet.blues.limit.TimeIntervalLimit.shouldCheckLimit() [Scary(8), Normal 

I have to mention that startDate and endDate are Long variables. 我必须提到startDate和endDate是Long变量。 I tried to add checks for null inside if condition, also I tried to use longValue() method, but with no result. 我尝试在条件中添加null的检查,我也尝试使用longValue()方法,但没有结果。 Do you have any idea how can I fix this problem? 你知道如何解决这个问题吗? Could be a bug on fndBugs side? 可能是fndBugs方面的错误?

You get the error because startDate (and also endDate ) might be null . 您收到错误,因为startDate (以及endDate )可能为null But you checked them for null , so that shouldn't be possible, right? 但你检查它们是否为null ,所以这不可能,对吧?

The answer is that both are global and might be set to null at any time by another thread. 答案是两者都是全局的,并且可能在任何时候被另一个线程设置为null

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM