34 lines
857 B
Plaintext
34 lines
857 B
Plaintext
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++`` from ``++java.nio.file++`` package.
|
|
|
|
|
|
*Note* that this rule is automatically disabled when the project's ``++sonar.java.source++`` is not 8.
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
----
|
|
Path myPath;
|
|
if(java.nio.file.Files.exists(myPath)) { // Noncompliant
|
|
// do something
|
|
}
|
|
----
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
----
|
|
Path myPath;
|
|
if(myPath.toFile().exists())) {
|
|
// do something
|
|
}
|
|
----
|
|
|
|
|
|
== See
|
|
|
|
* https://bugs.openjdk.java.net/browse/JDK-8153414[https://bugs.openjdk.java.net/browse/JDK-8153414]
|
|
* https://bugs.openjdk.java.net/browse/JDK-8154077[https://bugs.openjdk.java.net/browse/JDK-8154077]
|
|
|