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

@ParametersAreNonnullByDefault ignored for private methods if set on package or class level. #374

Closed
adimaret opened this issue Sep 13, 2017 · 5 comments · Fixed by #1222
Labels

Comments

@adimaret
Copy link

We have a problem here where spotbugs does not apply the "@ParametersAreNonnullByDefault" annotation to private methods if the annotation has been set on package or class level. If you annotate the private method directly however it works.

How to reproduce:

  1. Unzip the attached maven project.
  2. Run "mvn clean verify"

Expected Behavior:
Spotbugs should find the same bug in all three example classes, as all classes have the same code, but simply get their @ParametersAreNonnullByDefault annotation from a different level (package/class/method).

Actual Behavior:
Spotbugs only finds the bug in "TestNonnullByDefaultFromMethodAnnotation.java"

Workaround:
Change all private methods to protected or public and spotbugs will correctly complain about all three classes.

spotbugs.zip

@KengoTODA KengoTODA added the bug label Sep 26, 2017
@KengoTODA
Copy link
Member

Hi @adimaret,
Could you try to reproduce this problem with latest SpotBugs 3.1.3? It includes fix for annotations in package-info.java.

@adimaret
Copy link
Author

@KengoTODA
Awesome! I'm on a business trip right now, but I will try as soon as I'm back.

@adimaret
Copy link
Author

adimaret commented Apr 28, 2018

@KengoTODA
I couldn't wait :-)

Unfortunately the bug has not been fixed yet. I updated my example project to spotbugs 3.1.3 but still the bug is only reported for TestNonnullByDefaultFromMethodAnnotation.java

spotbugs-3.1.3.zip

@adwsingh
Copy link

This doesn't seem to fixed yet.

RitChan added a commit to cs304-fall2020/spotbugs that referenced this issue May 8, 2020
cwbriones pushed a commit to cwbriones/spotbugs that referenced this issue Jul 18, 2020
cwbriones added a commit to cwbriones/spotbugs that referenced this issue Jul 18, 2020
Remove the restriction that a method must not be private in order to
inherit default annotations from package or class scope.

Resolves spotbugs#374.
@cwbriones
Copy link
Contributor

I tracked down the failure to what appears to be an intentional choice to omit private methods (code ref), but nonetheless I went ahead and opened a PR.

Happy to keep discussion here if that was premature on my part.

KengoTODA pushed a commit that referenced this issue Aug 17, 2020
…class scope (#1222)

* refs #374: reproduce reported problem

* allow private methods to inherit default annotations

Remove the restriction that a method must not be private in order to
inherit default annotations from package or class scope.

Resolves #374.

* bump year in license header

* add a comment in changelog as per the PR template

* ./gradlew spotlessApply

* address pr comments

- fix copyright attribution
- move entry in changelog

Co-authored-by: Ritee <chenh0510@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants