#1079 Wrong warning about parameter of compiler-generated method


When an interface uses a generics type parameter, e.g.
public interface GenericFindBugsParameterChecking<T> {
public void doSomething(@CheckForNull T theParameter);
and an implementation looks like this:
public class GenericFindBugsParameterCheckingImpl implements GenericFindBugsParameterChecking<String> {
public void doSomething(@Nonnull String theParameter) {
// do something
then running FindBugs on the implementation class will warn "$L1 must be nonnull but is marked as nullable".

I reckon this is due to the compiler generated additional method:
public void doSomething(Object theParameter) {
doSomething((String) theParameter);

Now, without Generics, e.g.:
public interface FindBugsParameterChecking {
public void doSomething(@CheckForNull String theParameter);
public class FindBugsParameterCheckingImpl implements FindBugsParameterChecking {
public void doSomething(@Nonnull String theParameter) {
// do something

when running FindBugs on the implementation class, no warnings are reported.

Therefore: should FindBugs not be permissive in the above case even if Generics are in use and determine the requirements for the parameter of the compiler generated method by picking up the @Nonnull annotation of the parameter of the invoked method?


  • Comment has been marked as spam. 

    You can see all pending comments posted by this user  here

    Anonymous - 2012-05-18

    This occurs with FindBugs 2.0.0, Oracle JDK 1.6.0_24

  • William Pugh

    William Pugh - 2012-05-22
    • status: open --> open-accepted

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks