You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a try-with-resources defines a local variable but it is not used in the try-block, the rule should flag this variable as unused. If some weird action is happening on creation and closing (because close() is automatically executed by the try-with-resources) and the code can't be removed, then the variable should be named like unused - then it will be ignored by the rule.
Note: This is fixed already with PMD 7.0.0-rc1.
Found via #3123.
adangel
changed the title
[java] UnusedLocalVariable false-negative with unused try-with-resources
[java] UnusedLocalVariable: false-negative with try-with-resources
Apr 28, 2023
Affects PMD Version: 6.x
Rule: UnusedLocalVariable
Description:
If a try-with-resources defines a local variable but it is not used in the try-block, the rule should flag this variable as unused. If some weird action is happening on creation and closing (because
close()
is automatically executed by the try-with-resources) and the code can't be removed, then the variable should be named likeunused
- then it will be ignored by the rule.Note: This is fixed already with PMD 7.0.0-rc1.
Found via #3123.
Code Sample demonstrating the issue:
Expected outcome:
PMD should report a violation at line 5, but doesn't. This is a false-negative.
The text was updated successfully, but these errors were encountered: