From 90fc0d11a45985a1d0041bb5578bddfe6dba1a65 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Thu, 20 Oct 2016 16:50:01 +0200 Subject: [PATCH] IG: avoid NPE --- .../src/com/siyeh/ig/LightInspectionTestCase.java | 8 +++++++- .../ig/threading/AtomicFieldUpdaterIssuesInspection.java | 3 +++ .../AtomicFieldUpdaterIssuesInspectionTest.java | 9 +++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/java/testFramework/src/com/siyeh/ig/LightInspectionTestCase.java b/java/testFramework/src/com/siyeh/ig/LightInspectionTestCase.java index d1fa0b9ca1df..2e102efb1ea3 100644 --- a/java/testFramework/src/com/siyeh/ig/LightInspectionTestCase.java +++ b/java/testFramework/src/com/siyeh/ig/LightInspectionTestCase.java @@ -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(""); } + else if ("!".equals(text)) { + newText.append(""); + } else if ("_".equals(text)) { newText.append(""); } + else if (text.startsWith("!")) { + newText.append(""); + } else { newText.append(""); } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/threading/AtomicFieldUpdaterIssuesInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/threading/AtomicFieldUpdaterIssuesInspection.java index b72a0e62f291..688fdb0defc5 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/threading/AtomicFieldUpdaterIssuesInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/threading/AtomicFieldUpdaterIssuesInspection.java @@ -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())); diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/threading/AtomicFieldUpdaterIssuesInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/threading/AtomicFieldUpdaterIssuesInspectionTest.java index 790337b82e9e..ad0e1d71cf1b 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/threading/AtomicFieldUpdaterIssuesInspectionTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/threading/AtomicFieldUpdaterIssuesInspectionTest.java @@ -124,6 +124,15 @@ public class AtomicFieldUpdaterIssuesInspectionTest extends LightInspectionTestC "}"); } + public void testAvoidNPE() { + doTest("import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;\n" + + "class Z {\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() {