IDEA-162140 (AtomicFieldUpdater warnings incorrect for generic members)
authorBas Leijdekkers <basleijdekkers@gmail.com>
Fri, 7 Oct 2016 14:01:21 +0000 (16:01 +0200)
committerBas Leijdekkers <basleijdekkers@gmail.com>
Fri, 7 Oct 2016 14:04:37 +0000 (16:04 +0200)
plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/threading/AtomicFieldUpdaterIssuesInspection.java
plugins/InspectionGadgets/testsrc/com/siyeh/ig/threading/AtomicFieldUpdaterIssuesInspectionTest.java

index 705b5c8166897664d49a4004e6af0de993e0e3aa..c3739d4bf34babaa34c30ee29c2f2aee40b6f686 100644 (file)
@@ -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.
@@ -129,7 +129,7 @@ public class AtomicFieldUpdaterIssuesInspection extends BaseInspection {
         }
         final PsiClassObjectAccessExpression objectAccessExpression = (PsiClassObjectAccessExpression)argument2;
         final PsiType type = objectAccessExpression.getOperand().getType();
-        if (!field.getType().equals(type)) {
+        if (!TypeUtils.areConvertible(type, field.getType())) {
           registerError(lastArgument, InspectionGadgetsBundle.message("field.incorrect.type.problem.descriptor",
                                                                       fieldName, type.getPresentableText()));
           return;
index 230a10cfa1474f4bcaf5b9e43c2d4c0b24ee434b..790337b82e9e1379a3785bc5da9ee3bb506dd227 100644 (file)
@@ -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.
@@ -89,6 +89,16 @@ public class AtomicFieldUpdaterIssuesInspectionTest extends LightInspectionTestC
            "}");
   }
 
+  public void testRightType() {
+    doTest("import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;" +
+           "import java.util.RandomAccess;" +
+           "class A<T extends RandomAccess> {" +
+           "  private volatile T value = null;" +
+           "  private static final AtomicReferenceFieldUpdater updater = " +
+           "    AtomicReferenceFieldUpdater.newUpdater(A.class, RandomAccess.class, \"value\");" +
+           "}");
+  }
+
   public void testNotAccessible1() {
     doTest("import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;" +
            "class Z {" +