
Co-authored-by: Amélie Renard <44666826+amelie-renard-sonarsource@users.noreply.github.com> Co-authored-by: Dorian Burihabwa <75226315+dorian-burihabwa-sonarsource@users.noreply.github.com>
47 lines
932 B
Plaintext
47 lines
932 B
Plaintext
== Why is this an issue?
|
|
|
|
:example: java/code-example.adoc
|
|
|
|
:compliant: java/compliant.adoc
|
|
|
|
include::../description.adoc[]
|
|
|
|
In the case of try-with-resources, the try should remain even without a catch clause, to keep the resource management
|
|
|
|
[source, java]
|
|
----
|
|
String readFirstLine(FileReader fileReader) throws IOException {
|
|
try (BufferedReader br = new BufferedReader(fileReader)) {
|
|
return br.readLine();
|
|
} catch (IOException e) { // Noncompliant
|
|
throw e;
|
|
}
|
|
----
|
|
|
|
becomes
|
|
|
|
[source, java]
|
|
----
|
|
String readFirstLine(FileReader fileReader) throws IOException {
|
|
try (BufferedReader br = new BufferedReader(fileReader)) {
|
|
return br.readLine();
|
|
}
|
|
}
|
|
----
|
|
|
|
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[]
|