[java] UseTryWithResources: Fix false negative

This commit is contained in:
Andreas Dangel
2019-01-26 11:59:04 +01:00
parent 8364d97e92
commit 99d63cd261
2 changed files with 18 additions and 1 deletions

View File

@ -1465,7 +1465,7 @@ preserved.
<property name="xpath">
<value>
<![CDATA[
//TryStatement[not(ResourceSpecification)][FinallyStatement//Name[
//TryStatement[FinallyStatement//Name[
tokenize(@Image, '\.')[last()] = $closeMethods
]]
]]>

View File

@ -141,4 +141,21 @@ public class TryWithResources {
}
]]></code>
</test-code>
<test-code>
<description>False negative with two resources</description>
<expected-problems>1</expected-problems>
<expected-linenumbers>4</expected-linenumbers>
<code><![CDATA[
public class TryWithResources {
public void run() {
Reader r1 = new FileReader(file);
try (Reader r2 = new FileReader(otherFile)) {
} finally {
r1.close();
}
}
}
]]></code>
</test-code>
</test-data>