New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
False positive BC_IMPOSSIBLE_INSTANCEOF #2968
Comments
Thanks for opening your first issue here! 😃 |
Thank you for your example. It is indeed looks like an FP. |
I am not sure how I can verify that - I am using the Eclipse plugin with the version |
That is the plugin release using 4.8.4. Since using eclipse, you could flip over to our snapshots as it's released every day or so. Look at the various eclipse projects to find the update url. That might help find if issues are fixed or not. Some have been.
Sent from my Verizon, Samsung Galaxy smartphone
Get Outlook for Android<https://aka.ms/AAb9ysg>
…________________________________
From: ghernadi ***@***.***>
Sent: Wednesday, April 24, 2024 8:52:46 AM
To: spotbugs/spotbugs ***@***.***>
Cc: Subscribed ***@***.***>
Subject: Re: [spotbugs/spotbugs] False positive BC_IMPOSSIBLE_INSTANCEOF (Issue #2968)
I am not sure how I can verify that - I am using the Eclipse plugin with the version 4.8.4.r202404071625-a86cfd3 - Not sure if that is the version of SpotBugs or the Eclipse plugin or if those two are identical anyways. I found this version under Eclipse -> Help -> About Eclipse -> Installation Details -> SpotBugs / Version column.
—
Reply to this email directly, view it on GitHub<#2968 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAHODIYCWZMFY6KZHGU6JTDY66TJ5AVCNFSM6AAAAABGWZCYX2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZUHA3TOOJVHE>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
I know this all looks a bit weird, but it is something we have in a real life project, I just renamed the exceptions, methods and the interface in order to create a minimal working example.
There are a few important parts in order to reproduce this issue:
catch
blocks seem to be important)catch (RedHerring1Exception | RedHerring2Exception exc)
has to exist and needs to catch multiple exceptions (i.e. use a|
). SpotBugs does not report a false positive result if we either remove thiscatch
block or split it into two differentcatch
blocks.I do not fully understand why SpotBugs thinks that only
RuntimeExceptions
are possible in thecatch (Exception exc)
block. My best guess would be that theRedHerring1Exception | RedHerring2Exception
gets somehow merged into acatch (CommonException)
, which would "change" the code into something like:But that ^ is simply a wrong transformation of the original code.
I have found this other issue #926, that could also raise here the question "Why not use a
catch (CommonException exc)
?"Answer: Sure, we could use a dedicated
catch (CommonException exc)
block, but we would have to split the existing code in something like the following in order to minimize code duplication:Which looks quite tedious to me, especially since we would need to modify a working code only to get rid of a false positive SpotBugs report.
Please let me know if there are open questions or if I have missed something.
The text was updated successfully, but these errors were encountered: