- SonarLint Version: 3.5.1.2759
- It is a wrong “Null pointers should not be dereferenced” check! S2259
- steps to reproduce
My code like this:
private void methodAnyWay() {
ApprovalStatusEnum statusEnum = ApprovalStatusEnum.findByCode(form.getApprovalStatus());
if (null == statusEnum) {
logAndError("form.getApprovalStatus() can not be null.");
}
switch(statusEnum) {
case PASS:
...
}
}
private void logAndError(String msg) {
LOGGER.error(msg);
throw new CommonBizException(msg);
}
Actually, I have managed the NPE in the logAndError method. The CommonBizException is an Exception inherited from RuntimeException.
- potential workaround
I hope it can be fix by checking the method in the ‘if null’ statement.
#bug:fp