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

SpotBugs analysis: MethodType.equals(Object) does not check for null #204

Closed
ghost opened this issue Jan 10, 2023 · 0 comments
Closed

SpotBugs analysis: MethodType.equals(Object) does not check for null #204

ghost opened this issue Jan 10, 2023 · 0 comments

Comments

@ghost
Copy link

ghost commented Jan 10, 2023

From SpotBugs:

dbus-npe-04

The offending method:

    @Override
    public boolean equals(Object _o) {
        return _o.getClass().equals(MethodTuple.class) && ((MethodTuple) _o).name.equals(this.name) && ((MethodTuple) _o).sig.equals(this.sig);
    }

SpotBugs is correct, _o needs a null guard (by convention). The IDE generates the following code for hashCode, equals, and the constructor:

    public MethodTuple(final String _name, final String _sig) {
        name = _name;
        sig = Objects.requireNonNullElse(_sig, "");
        logger.trace("new MethodTuple({}, {})", name, sig);
    }

    @Override
    public boolean equals(final Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        final MethodTuple that = (MethodTuple) o;
        return Objects.equals(name, that.name) && Objects.equals(sig, that.sig);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, sig);
    }
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

0 participants