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: FII_USE_METHOD_REFERENCE #1006

Open
ialokim opened this issue Sep 3, 2019 · 2 comments
Open

false positive: FII_USE_METHOD_REFERENCE #1006

ialokim opened this issue Sep 3, 2019 · 2 comments

Comments

@ialokim
Copy link

ialokim commented Sep 3, 2019

I'm not sure whether this is really a bug in spotbugs, or if my java 11 compiler just does some magic I can't figure out. Perhaps someone out here has some idea.

The following code produces the error:

    @Test
    public void mapAddTileTwiceTest() {
        Map<TestPassage> map = new Map<>(4);
        Tile<TestPassage> firstTile = new Tile<>(0,0, TestPassage.PRESENT, TestPassage.PRESENT, TestPassage.PRESENT, TestPassage.PRESENT, false);
        Tile<TestPassage> secondTile = new Tile<>(0,0, TestPassage.NONE, TestPassage.NONE, TestPassage.NONE, TestPassage.NONE, true);
        map.addTile(firstTile);
        Assertions.assertThrows(IllegalArgumentException.class, () -> map.addTile(secondTile),
            "adding two tiles at the same position should throw an IllegalArgumentException");
    }

Obviously, I'm not able to change the lambda expression to a method reference as the method has a parameter.

Unfortunately, I was not able to reproduce it with some general Java classes, but changing map.addTile(secondTile) to map.addTile(new Tile<>(0,0, TestPassage.NONE, TestPassage.NONE, TestPassage.NONE, TestPassage.NONE, true)) (inlining the object creation) eliminates the warning.

@welcome
Copy link

welcome bot commented Sep 3, 2019

Thanks for opening your first issue here! 😃
Please check our contributing guideline. Especially when you report a problem, make sure you share a Minimal, Complete, and Verifiable example to reproduce it in this issue.

@Xiaoven
Copy link

Xiaoven commented May 19, 2021

It seems that FII_USE_METHOD_REFERENCE is a pattern of fb-contrib, not of spotbugs. 🤔

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