[java] Allow try-with-resources to be empty

* Fixes #432
This commit is contained in:
Juan Martín Sotuyo Dodero 2017-06-21 17:20:11 -03:00
parent bede603fb3
commit 878f73158a
2 changed files with 14 additions and 1 deletions

View File

@ -129,7 +129,7 @@ Avoid empty try blocks - what's the point?
<property name="xpath">
<value>
<![CDATA[
//TryStatement/Block[1][count(*) = 0]
//TryStatement[not(ResourceSpecification)]/Block[1][count(*) = 0]
]]>
</value>
</property>

View File

@ -46,6 +46,19 @@ public class EmptyTryBlock3 {
int x = 5;
}
}
}
]]></code>
</test-code>
<test-code>
<description>#432 false positive for empty try-with-resource</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
class X {
void method() {
try (ClientResponse response = execute(() -> target.request(mediaTypes).delete(), DELETE, new ExpectedResponse(status, required))) {
// false positive
}
}
}
]]></code>
</test-code>