Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE in try-with-resources in…
… presence of debug symbols (#1932) * Fix RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE in try-with-resources in presence of debug symbols Resolves #1931 by improving on #1575 Probably also #868, #1338, #1694 Not entirely sure about what exactly is happening but since 4.4.0 on javac11+ (openjdk) findbugs was reporting redundant null check if all of following holds - code in try block always dereferences the object - try-with-resources is applied to an object via interface reference - debug symbols are present (LocalVariableTable, via javac -g) javac11+ generates bytecode along the lines of ``` try-body if (obj != null) obj.close() on_any_exceptions_in_try_body: if (obj != null) obj.close() ``` This does always close obj if it is not null Javac could've deduced that if try-body always throws on `obj==null` then null check isn't needed but isn't obliged to do so, for simplicity for example. Fix by treating invokeinterface same way as invokevirtual in FindNullDeref Adding a minimal test for interface case. Note that test suite is compiled with default gradle settings that have debug symbols enabled. * Add changelog entry * Update Issue600Test assertions to catch the issue with interfaces * fix indentation
- Loading branch information
Showing
5 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
spotbugsTestCases/src/java/ghIssues/issue600/IMyAutocloseable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package ghIssues.issue600; | ||
|
||
public interface IMyAutocloseable extends AutoCloseable { | ||
} |
6 changes: 6 additions & 0 deletions
6
spotbugsTestCases/src/java/ghIssues/issue600/TryWithResourcesSimple.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters