The Files.exists
method has noticeably poor performance in JDK 8, and can slow an application significantly when used to check files
that don't actually exist.
The same goes for Files.notExists
, Files.isDirectory
and Files.isRegularFile
.
Note that this rule is automatically disabled when the project's sonar.java.source
is not 8.
Path myPath; if(java.nio.Files.exists(myPath)) { // Noncompliant // do something }
Path myPath; if(myPath.toFile().exists())) { // do something }