运行下面的代码查找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 screenshot
“目标必须为非空但被标记为可为空”
我没有明确添加任何注释,为什么会出现此错误?
答案 0 :(得分:0)
您正在通过类别广播将目标参数分配给其他参考。因此,您可能会遇到异常。您必须控制它是否为null或不为null,或者必须添加notnull注释。