diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ClassCastLambdaUsage.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ClassCastLambdaUsage.java index 11af5823db..ce83ed0bda 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ClassCastLambdaUsage.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ClassCastLambdaUsage.java @@ -48,7 +48,7 @@ public Description matchLambdaExpression(LambdaExpressionTree tree, VisitorState } Type type = ASTHelpers.getType(typeCast); - if (type == null || type.isParameterized()) { + if (type == null || type.isParameterized() || type.isPrimitive()) { return Description.NO_MATCH; } diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ClassCastLambdaUsageTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ClassCastLambdaUsageTest.java index 5b445ecacf..5e210d47c8 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ClassCastLambdaUsageTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ClassCastLambdaUsageTest.java @@ -12,6 +12,7 @@ void identification() { .addSourceLines( "A.java", "import com.google.common.collect.ImmutableSet;", + "import java.util.stream.IntStream;", "import java.util.stream.Stream;", "", "class A {", @@ -34,6 +35,7 @@ void identification() { " Stream.of(ImmutableSet.of(5)).map(l -> (ImmutableSet) l);", " Stream.of(ImmutableSet.of(6)).map(l -> (ImmutableSet) l);", " Stream.of(7).reduce((a, b) -> (Integer) a);", + " IntStream.of(8).mapToObj(a -> (char) a);", "", " // BUG: Diagnostic contains:", " Stream.of(8).map(i -> (Integer) i);",