I’m not new to Java programming in any way, but this problem is unheard of to me.
I have this code:
private static boolean isEarlierThanAndNotReminded(Callback left, Callback right) {
if(right == null) {
return !left.isReminded();
}
else {
return !left.isReminded() && (left.getAlertStart().before(right.getAlertStart()));
}
}
Ok so the problem is that I get a report of a null pointer on the line in the “else” clause.
When I debug, I can see that right is actually null, but still the execution land first in the if-clause and then control continues into the “else”-clause where it gets a null pointer.
I am clueless to what I am missing here, any suggestions?
It’s probably just a function of the optimisation of the compiler and the way the debugger handles it.
It’s going to the ‘if’ first condition but not actually executing the return. If you think about it, whatever
the value of ‘right’ is the code needs to know the value of ‘ !left.isReminded()’, so that statement has to be executed. I bet that if you started your function with
before the if statement and then did put that new boolean into your return statements, you would see a different execution path in the debugger.