FindBugs: Possible Null Pointer Dereferencing

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 encountered the following problem:

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

      

I must mention that startDate and endDate are long variables. I tried adding checks for null inside if condition, also I tried using longValue () method but no result. Do you know how I can fix this problem? Could there be a bug on the fndBugs side?

+3


source to share


1 answer


You are getting the error because startDate

(and also endDate

) maybe null

. But you checked them on null

to make it impossible, right?



The answer is that both are global and can be set null

at any time by another thread.

+5


source







All Articles