False positive SA_LOCAL_SELF_COMPARISON when using instanceof pattern matching#1136
False positive SA_LOCAL_SELF_COMPARISON when using instanceof pattern matching#1136schosin wants to merge 4 commits into
Conversation
|
Test is not failing, could you check? @schosin |
|
|
||
| public static void instanceofPatternMatching() { | ||
| Number number = 1f; | ||
| if (number instanceof Float f) { |
There was a problem hiding this comment.
Is this correct syntax? Why the f?
There was a problem hiding this comment.
Yes, this is the new syntax introduced in this preview feature. I suppose the false positive is triggered because number and f reference the same instance of the boxed 1f.
259cfed to
083f2b2
Compare
|
The tests are probably not failing because gradle has to be running on JDK 14. See changes in build.gradle. If you prefer I can squash those changes once its done. |
083f2b2 to
fdec527
Compare
|
Fixed remaining typos and rebased on top of master. |
ThrawnCA
left a comment
There was a problem hiding this comment.
Looks ok, but please try to avoid force-pushes since they break the history.
|
Test won't be failing since the github workflow is only configured for java 8. For the tests to fail gradle has to be run on JDK 14. As a side note, edu.umd.cs.findbugs.DetectorsTest > testAllRegressionFilesJavac FAILED also fails when running on JDK 14, but I'm not sure what's the best way to fix it. |
|
I created #1435 to solve conflict and run full pre-merge build. Please use that for coming discussion & review. |
… matching (#1435) * add test for false positive when using instanceof pattern matching * #1136: add link to github issue * ci: use JDK 14 to run test with Java 14 * docs: add an entry to the CHANGELOG * build: upgrade JaCoCo to 0.8.6 that supports Java 14 officially * build: use Java 15 instead, because 14 is outdated already * Update CHANGELOG.md The bug is caused by Java 14, that is outdated and not maintained any more. In the SpotBugs side we need no update, so we should have no entry in this file. Co-authored-by: Ken Schosinsky <schosins@gmail.com>
|
Using 4.2.3 this is still a false positive. See 50cb283#commitcomment-49080418 |
|
@LutzHorn It's javac problem, please use Java 16 instead. Java 14 is already out of support. |
This PR adds a failing test when using instanceof pattern matching in Java 14 (preview feature).
In this code, SA_LOCAL_SELF_COMPARISON is incorrectly reported for
number:Edit: According to JEP 375 this feature will be going into a second preview with no changes relative to the first preview introduced in JDK 15. This PR should be changed to use JDK 15 as soon as it is released and gradle/other dependencies support JDK 15.