55 lines
1.2 KiB
Plaintext
55 lines
1.2 KiB
Plaintext
== Why is this an issue?
|
|
|
|
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
|
|
|
|
[source,java]
|
|
----
|
|
Path myPath;
|
|
if(java.nio.file.Files.exists(myPath)) { // Noncompliant
|
|
// do something
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,java]
|
|
----
|
|
Path myPath;
|
|
if(myPath.toFile().exists())) {
|
|
// do something
|
|
}
|
|
----
|
|
|
|
|
|
== Resources
|
|
|
|
* 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]
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::message.adoc[]
|
|
|
|
include::highlighting.adoc[]
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::comments-and-links.adoc[]
|
|
endif::env-github,rspecator-view[]
|