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: parameter must be non-null in inner class constructor #772

Closed
ahubold opened this issue Oct 11, 2018 · 2 comments
Closed

Comments

@ahubold
Copy link
Contributor

ahubold commented Oct 11, 2018

Spotbugs 3.1.6 shows an issue for rule findbugs:NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE that an inner class constructor parameter must be non-null, even if the parameter is already annotated as NonNull. Code example:

package com.example;

import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;

public class NonNullParameterOfInnerClassConstructor {

  private class Inner {
    private final String a;
    private final Object b;

    Inner(@NonNull String a, @Nullable Object b) {
      this.a = a.toLowerCase(); // <--- false positive: a must be non-null but is marked as nullable
      this.b = b;
    }
  }
}





@ahubold
Copy link
Contributor Author

ahubold commented Oct 11, 2018

Pull request with reproducer for this issue: #773

(Not sure if this is the correct way to write test cases for issues, so please have a look)

I detected this bug by using sonar-findbugs and opened an issue there that is caused by this one: spotbugs/sonar-findbugs#213

@KengoTODA
Copy link
Member

@ahubold Thanks for your nice report and reproduction! I've fixed it, we'll release patched version in the next January.

KengoTODA pushed a commit that referenced this issue Jan 15, 2019
KengoTODA pushed a commit that referenced this issue Jan 23, 2019
KengoTODA pushed a commit that referenced this issue Feb 11, 2019
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

2 participants