在为存储过程赋值时,我在调用 Nullcheck 的 SonarQube 中出错。
call.setBigDecimal(ONE, bank != null ? bank : BigDecimal.ZERO);
正是在上面的这段摘录中。如果他去掉三元,他也会犯同样的错误。我在函数之前做了一个 IF 并且发生了同样的错误。
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;
}
答案 0 :(得分:0)
您启用了 SonarQube 的 NullCheck。如果在变量不能为 null
的地方使用 null
检查,这会给您一个错误。根据文档,这意味着您永远不会将 null
传递到 getMobileCarriers()
。为了您的代码的健壮性,检查 null
是一个好主意(因为您可能会从其他地方使用该方法,甚至在某些时候从外部使用该方法)。因此,我建议查看 SonarQube 的设置并关闭此检查或修改它,使其不会执行此分析跨方法调用。