简体   繁体   English

SONAR中可能的空指针取消引用

[英]Possible null pointer dereference in SONAR

I have tried to point critical issues in Sonar with the following code: 我试图用以下代码指出Sonar中的关键问题:

if (candidate.isDirectory() && candidate.canRead() && 
          TEMPLATE.equalsIgnoreCase(candidate.getName())) {  
  List<String> fileContentList = Arrays.asList(candidate.list());

I have also done the change below, but it still didn't work 我也做了下面的更改,但仍然没有用

if(null != Arrays.asList(candidate.list())){
  List<String> fileContentList = Arrays.asList(candidate.list());}

Please help. 请帮忙。

The error occures because candidate can be null. 发生错误是因为candidate可以为空。 See https://www.owasp.org/index.php/Null_Dereference for a description. 有关说明,请参见https://www.owasp.org/index.php/Null_Dereference

You could do sth. 你可以做某事。 like this: 像这样:

List<String> fileContentList = candidate != null ? Arrays.asList(candidate.list()) : new ArrayList<>();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM