IDEA-146009 Good code is yellow: "Unboxing may produce NPE" inside forEach lambda

This commit is contained in:
peter
2015-10-06 13:04:24 +02:00
parent ebe3adb0e8
commit 06c0f35c8f
3 changed files with 14 additions and 0 deletions

View File

@@ -1218,6 +1218,8 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
}
private void generateBoxingUnboxingInstructionFor(PsiExpression expression, PsiType expectedType) {
if (expectedType == PsiType.VOID) return;
PsiType exprType = expression.getType();
if (TypeConversionUtil.isPrimitiveAndNotNull(expectedType) && TypeConversionUtil.isPrimitiveWrapper(exprType)) {

View File

@@ -0,0 +1,11 @@
import java.util.List;
class Example {
public void example(List<Foo> foos) {
foos.forEach(foo -> foo.bar = null);
}
}
class Foo {
public Long bar;
}

View File

@@ -105,4 +105,5 @@ public class DataFlowInspection8Test extends LightCodeInsightFixtureTestCase {
doTest();
}
public void testPrimitiveInVoidLambda() { doTest(); }
}