A "NullPointerException" could be thrown; "customerMobile" is nullable here

Dear SonarSourcers:
Some code in my project was scanned to have bugs, but I thought it is a false positive, as I have checked nullability in the following lines. Could someone help me check about this? Thanks a lot~~

Sonar version: 7.9.3
JDK version: openjdk 11.0.8

    CustomerMobile customerMobile = getCustomerMobileByCuidOrFakeId(cuid, fakeId);
        if ((StringUtils.isBlank(cuid) && StringUtils.isBlank(fakeId)) || Objects.isNull(customerMobile)) {
            log.info("------there is not corresponding cuid or fakeId record, cuid[{}], fakeId[{}]", cuid, fakeId);
            CustomerMobile cm = customerMobileDAO.queryByMobile(currentMobile);
            if (Objects.isNull(cm)) {
                firstLoginFlag = Constant.FIRST_LOGIN_Y;
                customer = createCustomer(currentMobile, authLoginDTO.getChannelId());
                createCustomerMobile(customer.getCustomerId(), currentMobile, cuid, fakeId);
                log.info("------there is not corresponding phone number record, phone number[{}]", currentMobile);
            } else {
                bindCuidAndFakeIdToCustomerMobile(cm, cuid, fakeId);
                customer = customerMapper.selectByPrimaryKey(cm.getCustomerId());
                log.info("------there is corresponding phone number record, phone number[{}]", currentMobile);
            }
            return createCustomerLoginInfo(customer, currentMobile, firstLoginFlag, accessToken);
        }
        log.info("------there is corresponding cuid or fakeId record, cuid[{}], fakeId[{}]", cuid, fakeId);
        if (currentMobile.equals(customerMobile.getMobile())) {
//.....
}

Hello @cikezxy, and welcome to the community.

I played a bit with your example, but I did not manage to reproduce the issue on my side with the most recent version of SonarQube (8.6), everything behaves as expected.

A lot happened since version 7.9.3, is it possible on your side to test if this code still raises an issue with the latest version? If you still face the issue, feel free to come back to us.

Otherwise, I would just resolve this issue as a False positive, as it is clearly one.

Best,
Quentin

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.