[java] UnusedLocalVariable - add test case from #3656

This commit is contained in:
Andreas Dangel 2021-12-01 09:05:41 +01:00
parent 3929cac930
commit c9c7d05ac7
No known key found for this signature in database
GPG Key ID: 93450DF2DF9A3FA3

View File

@ -391,6 +391,24 @@ public class UnusedLocalVariable {
int ignored, unused = 0;
int notok = 0;
}
}
]]></code>
</test-code>
<test-code>
<description>False positive with try-with-resources</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
import java.io.InputStream;
public class UsedLocalVar {
public boolean run() {
boolean canRead = false;
try(InputStream resource = open()) {
canRead = true;
} catch (Throwable ignore) {}
return canRead;
}
private InputStream open() { return null; }
}
]]></code>
</test-code>