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
Fix RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE in try-with-resources in presence of debug symbols (spotbugs#1932)
* Fix RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE in try-with-resources in presence of debug symbols
Resolvesspotbugs#1931 by improving on spotbugs#1575
Probably also spotbugs#868, spotbugs#1338, spotbugs#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
Copy file name to clipboardexpand all lines: CHANGELOG.md
+2
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,8 @@ This is the changelog for SpotBugs. This follows [Keep a Changelog v1.0.0](http:
5
5
Currently the versioning policy of this project follows [Semantic Versioning v2.0.0](http://semver.org/spec/v2.0.0.html).
6
6
7
7
## Unreleased - 2022-??-??
8
+
### Fixed
9
+
- Fixed False positives for `RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE` on try-with-resources with interface references ([#1931](https://github.com/spotbugs/spotbugs/issues/1931))
0 commit comments