rspec/rules/S4458/java/rule.adoc

36 lines
812 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
In java 7 to 9, ``++FileInputStream++`` and ``++FileOutputStream++`` rely on finalization to perform final closes if the stream is not already closed. Whether or not the stream is already closed, the finalizer will be called, resulting in extra work for the garbage collector. This can easily be avoided using the ``++Files++`` API.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
try(FileInputStream fis = new FileInputStream(...)) { // Noncompliant
} finally {
}
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
2021-05-21 01:24:06 +00:00
try(InputStream is = Files.newInputStream(...)) {
2021-04-28 16:49:39 +02:00
} finally {
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]