Skip to content

False negative with NP_METHOD_RETURN_RELAXING_ANNOTATION using @NonNullByDefault #3324

@ghernadi

Description

@ghernadi

Although the title already says all, here is a MWE:

// file: package-info.java

@NonNullByDefault
package ghIssues.issue3324;

import org.eclipse.jdt.annotation.NonNullByDefault;
package ghIssues.issue3324;

import javax.annotation.Nonnull;

public interface DummyInterface{
    String getNameDefaultNonnull();

    @Nonnull
    String getNameExplicitNonnullFromInterface();
}
package ghIssues.issue3324;

public abstract class DummyAbs {
    public abstract String getNameDefaultNonnullFromAbs();
}
package ghIssues.issue3324;

import javax.annotation.Nullable;

public class DummyImpl extends DummyAbs implements DummyInterface {
    @Override
    public @Nullable String getNameDefaultNonnull() {
        return null;
    }

    @Override
    public @Nullable String getNameExplicitNonnullFromInterface() {
        return null;
    }

    @Override
    public @Nullable String getNameDefaultNonnullFromAbs() {
        return null;
    }
}

First I was not sure if SpotBugs can detect issues that involve multiple classes / interfaces, but since the above MWE shows 1 NP_METHOD_RETURN_RELAXING_ANNOTATION, I guess I was wrong, SpotBugs can indeed detect such issues 🎉

However, in the above example I would have expected 3 reports of NP_METHOD_RETURN_RELAXING_ANNOTATION instead of 1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions