我试图用以下代码指出Sonar中的关键问题:
if (candidate.isDirectory() && candidate.canRead() &&
TEMPLATE.equalsIgnoreCase(candidate.getName())) {
List<String> fileContentList = Arrays.asList(candidate.list());
我也在下面进行了更改,但它仍然无法正常工作
if(null != Arrays.asList(candidate.list())){
List<String> fileContentList = Arrays.asList(candidate.list());}
请帮忙。
答案 0 :(得分:0)
发生错误,因为candidate
可以为null。有关说明,请参阅https://www.owasp.org/index.php/Null_Dereference。
List<String> fileContentList = candidate != null ? Arrays.asList(candidate.list()) : new ArrayList<>();