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

UnnecessaryMethodReference gives false-positive #2102

Closed
wendigo opened this issue Jan 14, 2021 · 0 comments · Fixed by #2111
Closed

UnnecessaryMethodReference gives false-positive #2102

wendigo opened this issue Jan 14, 2021 · 0 comments · Fixed by #2111
Assignees

Comments

@wendigo
Copy link

wendigo commented Jan 14, 2021

Description of the problem / feature request:

UnnecessaryMethodReference gives a false-positive when variable is super.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

package test;

public class TestErrorProneSuper
{
    public static class S
            implements Closeable
    {
        @Override
        public void close()
                throws IOException
        {
            System.out.println("Closing S");
        }
    }

    public static class T
            extends S
    {
        Closer closer = Closer.create();

        @Override
        public void close() throws IOException
        {
            System.out.println("Closing T");
            closer.register(super::close);
        }
    }

    public static void main(String[] args)
    {
        try {
            new T().close();
        }
        catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }
}

Gives false-positive:

TestErrorProneSuper.java:[44,29] [UnnecessaryMethodReference] This method reference is unnecessary, and can be replaced with the variable itself.
(see https://errorprone.info/bugpattern/UnnecessaryMethodReference)
Did you mean 'closer.register(super);'?

which is not correct (cannot pass super as a variable: TestErrorProneSuper.java:[44,34] '.' expected)

What version of Error Prone are you using?

2.5.0

Have you found anything relevant by searching the web?

Nope :)

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

Successfully merging a pull request may close this issue.

2 participants