rspec/rules/S3725/java/rule.adoc

34 lines
857 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
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.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
Path myPath;
if(java.nio.file.Files.exists(myPath)) { // Noncompliant
// do something
}
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
Path myPath;
if(myPath.toFile().exists())) {
// do something
}
----
2021-04-28 16:49:39 +02:00
== 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]