IG: avoid NPE

This commit is contained in:
Bas Leijdekkers
2016-10-20 20:07:55 +02:00
parent 3bb1d1c10f
commit 90fc0d11a4
3 changed files with 19 additions and 1 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -105,9 +105,15 @@ public abstract class LightInspectionTestCase extends LightCodeInsightFixtureTes
if (text.isEmpty()) {
newText.append("</warning>");
}
else if ("!".equals(text)) {
newText.append("</error>");
}
else if ("_".equals(text)) {
newText.append("<caret>");
}
else if (text.startsWith("!")) {
newText.append("<error descr=\"").append(text.substring(1)).append("\">");
}
else {
newText.append("<warning descr=\"").append(text).append("\">");
}
@@ -130,6 +130,9 @@ public class AtomicFieldUpdaterIssuesInspection extends BaseInspection {
final PsiClassObjectAccessExpression objectAccessExpression = (PsiClassObjectAccessExpression)argument2;
final PsiType type = objectAccessExpression.getOperand().getType();
final PsiType substFieldType = classType.resolveGenerics().getSubstitutor().substitute(field.getType());
if (substFieldType == null) {
return;
}
if (!substFieldType.isAssignableFrom(type)) {
registerError(lastArgument, InspectionGadgetsBundle.message("field.incorrect.type.problem.descriptor",
fieldName, type.getPresentableText()));
@@ -124,6 +124,15 @@ public class AtomicFieldUpdaterIssuesInspectionTest extends LightInspectionTestC
"}");
}
public void testAvoidNPE() {
doTest("import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;\n" +
"class Z</*!Cyclic inheritance involving 'T'*//*!*/T extends T> {\n" +
" private T value = null;\n" +
" private static final AtomicReferenceFieldUpdater updater = \n" +
" AtomicReferenceFieldUpdater.newUpdater(Z.class, Object.class, \"value\");\n" +
"}");
}
@Nullable
@Override
protected InspectionProfileEntry getInspection() {