Skip to content

Commit

Permalink
UnnecessaryBoxedAssignment: avoid CCE on method reference
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan202 committed Oct 21, 2023
1 parent 747227a commit 73dc358
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public Description matchVariable(VariableTree tree, VisitorState state) {
}

private Description matchCommon(ExpressionTree expression, VisitorState state) {
if (expression == null || !VALUE_OF_MATCHER.matches(expression, state)) {
if (!(expression instanceof MethodInvocationTree)
|| !VALUE_OF_MATCHER.matches(expression, state)) {
return Description.NO_MATCH;
}
MethodInvocationTree methodInvocationTree = (MethodInvocationTree) expression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.google.errorprone.bugpatterns.testdata;

import java.util.function.Function;

/**
* @author awturner@google.com (Andy Turner)
*/
Expand Down Expand Up @@ -76,4 +78,8 @@ Integer positive_wrappedAgain(int aInteger) {
a = Integer.valueOf(aInteger);
return Integer.valueOf(a);
}

void negative_methodReference() {
Function<String, Boolean> toBoolean = Boolean::valueOf;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.google.errorprone.bugpatterns.testdata;

import java.util.function.Function;

/**
* @author awturner@google.com (Andy Turner)
*/
Expand Down Expand Up @@ -76,4 +78,8 @@ Integer positive_wrappedAgain(int aInteger) {
a = aInteger;
return a;
}

void negative_methodReference() {
Function<String, Boolean> toBoolean = Boolean::valueOf;
}
}

0 comments on commit 73dc358

Please sign in to comment.