Skip to content
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 for MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR in final class? #1812

Closed
danielnorberg opened this issue Nov 16, 2021 · 3 comments

Comments

@danielnorberg
Copy link
Contributor

Spotbugs 4.5.0 yields a warning for MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR when calling an inherited method from the constructor in a final class. But the method cannot be overridden by a subclass when the class is final.

See repro: https://github.com/danielnorberg/spotbugs-falsepositives/blob/main/src/main/java/Repro_FalsePositive_MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR.java

I propose that spotbug should not yield MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR when the class is final, same as when the called method itself is final.

@welcome
Copy link

welcome bot commented Nov 16, 2021

Thanks for opening your first issue here! 😃
Please check our contributing guideline. Especially when you report a problem, make sure you share a Minimal, Complete, and Verifiable example to reproduce it in this issue.

@danielnorberg
Copy link
Contributor Author

Looking at the implementation of this check, there's no need for inheritance to trigger this false positive. Calling any method in a final class from the constructor yields MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR.

See repro https://github.com/danielnorberg/spotbugs-falsepositives/blob/main/src/main/java/Repro2_FalsePositive_MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR.java

danielnorberg added a commit to danielnorberg/spotbugs that referenced this issue Nov 16, 2021
MC_OVERRIDABLE_METHOD_CALL errors should not be emitted for final
final classes.

spotbugs#1812
KengoTODA added a commit that referenced this issue Dec 7, 2021
* fix MC_OVERRIDABLE_METHOD_CALL false positive for final class

MC_OVERRIDABLE_METHOD_CALL errors should not be emitted for final
final classes.

#1812

* add changelog entry

Co-authored-by: Kengo TODA <skypencil+github@gmail.com>
@KengoTODA
Copy link
Member

closed by #1813

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants