当以下代码针对Sonarqube 中的错误运行时
@Component
public class SMOCreateSignObjectValidator implements Validator{
private static final Logger LOG = LoggerFactory.getLogger(SMOCreateSignObjectValidator.class);
@Override
public boolean supports(Class<?> clazz) {
LOG.info("Inside create Sign Object validator");
return AgreementRecordRequest.class.isAssignableFrom(clazz);
}
@Override
public void validate(Object target, Errors errors) {
AgreementRecordRequest agreementRecordRequest = (AgreementRecordRequest)target;
if(null==agreementRecordRequest.getCustomerId() || agreementRecordRequest.getCustomerId().replaceAll(""", "").length()==0 ){
throw new SystemException(SMOErrorConstants.MESSAGE_SMO_0003_MSG);
}
if(agreementRecordRequest.getExpiryDate().isEmpty()){
throw new SystemException(SMOErrorConstants.MESSAGE_SMO_0004_MSG);
}
}
}
sonarcube中引发以下错误。sonarqube 截图
"目标必须为非null,但标记为可为null">
我没有明确添加任何注释,为什么我会出现这个错误?
您正在通过类转换将目标参数分配给其他引用。出于这个原因,您可能会得到一个异常。你必须控制它是null还是非null,或者你必须添加notnull注释。