问题
I have tried to point critical issues in Sonar with the following code:
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.
回答1:
The error occures because candidate can be null. See https://www.owasp.org/index.php/Null_Dereference for a description.
You could do sth. like this:
List<String> fileContentList = candidate != null ? Arrays.asList(candidate.list()) : new ArrayList<>();
来源:https://stackoverflow.com/questions/37295215/possible-null-pointer-dereference-in-sonar