I have an error in the SonarQube of Nullcheck of call when assigning a value to a stored procedure.
call.setBigDecimal(ONE, bank != null ? bank : BigDecimal.ZERO);
Exactly in this excerpt above. He makes the same mistake if he removes the ternary. I did an IF before the function and the same error occurred.
public CarrierReturnDTO getMobileCarriers(BigDecimal bank) throws SQLException {
CarrierReturnDTO carrierReturnListDTO = new CarrierReturnDTO();
List<CarrierDTO> mobileCarrierList = new ArrayList<CarrierDTO>();
DataSource dataSource = jdbcTemplate.getDataSource();
if (dataSource != null) {
try (Connection connection = dataSource.getConnection()) {
if (connection != null) {
try (CallableStatement call = connection.prepareCall(Constants.COMBO_OPERCEL)) {
call.setBigDecimal(ONE, bank != null ? bank : BigDecimal.ZERO);
call.registerOutParameter(TWO, OracleTypes.CURSOR);
call.execute();
ResultSet rs = (ResultSet) call.getObject(TWO);
while (rs.next()) {
CarrierDTO mobileCarrier = new CarrierDTO();
mobileCarrier.setMobileCarrierCode(rs.getBigDecimal(Constants.COD_EMP_OPER));
mobileCarrier.setMobileCarrier(rs.getString(Constants.NOM_EMP_OPER));
mobileCarrier.setAmountDigitChecked(rs.getBigDecimal(Constants.QTD_DIG_VERIFIC));
mobileCarrier.setFlagDoubleDigit(rs.getString(Constants.FLG_DUP_DIGIT));
mobileCarrier.setBankCode(rs.getString(Constants.BCO_CNV_ALTAIR));
mobileCarrier.setBranchCode(rs.getString(Constants.AGE_CNV_ALTAIR));
mobileCarrier.setAccountCode(rs.getString(Constants.CTA_CNV_ALTAIR));
mobileCarrierList.add(mobileCarrier);
}
rs.close();
}
}
}
}
carrierReturnListDTO.setCarriers(mobileCarrierList);
return carrierReturnListDTO;
}
You have SonarQube's NullCheck enabled. This will give you an error for using a null
check in places where a variable cannot be null
. Following documentation, this would mean that you are never passing a null
into getMobileCarriers()
. For robustness of your code, having that null
check is a good idea (as you might be using that method from elsewhere, or even externally at some point). Therefore, I would recommend looking into SonarQube's setup and either turning this check off or modifying it such that it won't perform this analysis cross-method calls.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.