Search code examples
javaiosonarqubenio

SonarLint Rule regarding Files.notExists


SonarLint is saying that i should use if(programFolder.toFile().exists) instead of if(Files.exists(programFolder)). I always thought it is encouraged to use the newer nio Path instead of io File.

Can someone explain me why SonarList encourages the use of the file instead of the path in this case?


Solution

  • You have the description of the rule accessible from SonarLint directly if you click on the issue on the list of issues. Here is a link to the description of the rule.

    If you look at the last section of the description that links to two JDK bugs explaining what is going on. Basically, this implementation performs poorly as it fills up needless stacks with errors when the file does not exists.