Using Java 11. Noticing a strange behavior with very simple functionality. In the following code, if the expiration date is not null, only then it should try to extract the
sql.Timestamp from the given
preparedStatement.setTimestamp(expirationDateParameterIndex, Objects.nonNull(memberReward.getExpirationDate()) ? Timestamp.from(memberReward.getExpirationDate()) : null);
Problem is that even though the expiration date is set to
Timestamp.from(..) is called and throwing
java.lang.NullPointerException: null at java.sql/java.sql.Timestamp.from(Timestamp.java:545)
The issue is not reproducible outside the project.
Well, your debug screenshot is clear:
null was passed to
Timestamp.from(), which means
memberReward.getExpirationDate() is null.
That’s weird, because right before that, you check for that condition! Thus, we get to these explanations, all quite exotic:
getExpirationDate()is non-stable: It returns different values every time. Imagine it was implemented as follows:
return random.coinFlip() == HEADS ? null : someDateObj;– then this can happen. One way to fix this is to call it once, save to a local variable, and carry on with that.
java.util, and the nonNull method on it, is broken.
These all sound exotic, but it must be one of these things.