当我将一个字段设置为空时,Fortify会抱怨一个空的反引用:
ApplicanteeTO applicanteeTO = null;
if(applicanteeNRIC != null && !applicanteeNRIC.equals("")){
if(!populationId.equals(Constants.POPTYPE1) && !populationId.equals(Constants.POPTYPE2)) {
applicanteeTO = //retrieve from db
}
}
log.debug("applicanteeTO details: " + applicanteeTO);
if(applicanteeTO != null){
// do logic
}我尝试做的是用null初始化ApplicanteeTO对象,然后检查它是否在某个填充类型下,填充它。如果不是,则将其保留为null。然而,Fortify在报告中向我发出了这样的警告:
The method initForm() in SingleReplacementController.java can crash the program by dereferencing a null-pointer on line 110. 这条线指向记录器。我正在尝试消除Fortify发出的警告。有什么办法解决这个问题吗?
我可以这样做吗?
ApplicanteeTO applicanteeTO;
if(applicanteeNRIC != null && !applicanteeNRIC.equals("")){
if(!populationId.equals(Constants.POPTYPE1) && !populationId.equals(Constants.POPTYPE2)) {
applicanteeTO = //retrieve from db
}
} else {
applicanteeTO = null;
}
log.debug("applicanteeTO details: " + applicanteeTO);
if(applicanteeTO != null){
// do logic
}谢谢!
发布于 2021-01-27 09:55:27
如果Fortify在抱怨log.debug产品线,那么它(Fortify!)是不正确的。使用null连接字符串是安全的。它将null转换为"null",并将其连接起来。
所以你有几个选择:
//这个丑陋的代码是为了停止Fortify抱怨log.debug("applicanteeTO details:“+ (applicanteeTO == null:"null”:applicanteeTO));//或者使用if / else
幸运的是,JIT编译器将生成不对applicanteeTO执行多次null检查的代码。但这是版本相关的。
如果事情就像声明的那样,这确实是一个Fortify错误,那么你应该:
https://stackoverflow.com/questions/65911582
复制相似问题