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

FII_USE_METHOD_REFERENCE false positive #388

Closed
Serranya opened this issue Feb 20, 2020 · 4 comments
Closed

FII_USE_METHOD_REFERENCE false positive #388

Serranya opened this issue Feb 20, 2020 · 4 comments

Comments

@Serranya
Copy link

The following code triggres an FII_USE_METHOD_REFERENCE warning

int[] updateCount = ...
Arrays.stream(updateCount).mapToObj(i -> i == 1 ? Boolean.TRUE : Boolean.FALSE).allMatch(b -> b);

I have rewritten the code to the more concise

int[] updateCount = ...
Arrays.stream(updateCount).allMatch(i -> i == 1);

which works. But the warning still seems like a false positive.

@ThrawnCA
Copy link
Contributor

I suspect it was complaining about the i -> i reference. It probably could have been replaced with something like Boolean.TRUE::equals

@Serranya
Copy link
Author

Ahh I see. If this is intentional im fine with closing the bug.

@mebigfatguy
Copy link
Owner

Seems like the problem is the compiler is generating two lambda methods for this one mapToObject invocation. The first

private static java.lang.Boolean lambda$20(int);
descriptor: (I)Ljava/lang/Boolean;
flags: ACC_PRIVATE, ACC_STATIC, ACC_SYNTHETIC
Code:
stack=2, locals=1, args_size=1
0: iload_0
1: iconst_1
2: if_icmpne 11
5: getstatic #322 // Field java/lang/Boolean.TRUE:Ljava/lang/Boolean;
8: goto 14
11: getstatic #328 // Field java/lang/Boolean.FALSE:Ljava/lang/Boolean;
14: areturn

and the second

private static boolean lambda$21(java.lang.Boolean);
descriptor: (Ljava/lang/Boolean;)Z
flags: ACC_PRIVATE, ACC_STATIC, ACC_SYNTHETIC
Code:
stack=1, locals=1, args_size=1
0: aload_0
1: invokevirtual #335 // Method java/lang/Boolean.booleanValue:()Z
4: ireturn

The second lambda is clearly the same as Boolean::valueOf and that is what is being reported. However you didn't write two lambdas the compiler did. Have it figure out how to address this.

mebigfatguy added a commit that referenced this issue Feb 23, 2020
…ences, as javac does wonky things with autoboxing for #388
@mebigfatguy
Copy link
Owner

thanks for the report, should be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants