guarded by inspections: don't fail on invalid code

EA-124454 - SIOOBE: JCiPUtil.getGuardValue
This commit is contained in:
Anna.Kozlova
2018-07-11 19:35:00 +02:00
parent 69571737d4
commit 0f232187f3
3 changed files with 21 additions and 5 deletions
@@ -90,14 +90,15 @@ public class JCiPUtil {
@Nullable
static String getGuardValue(PsiAnnotation annotation) {
final PsiAnnotationMemberValue psiAnnotationMemberValue = annotation.findAttributeValue("value");
if (psiAnnotationMemberValue != null) {
final String value = psiAnnotationMemberValue.getText();
final String trim = value.substring(1, value.length() - 1).trim();
if (trim.equals("itself")) {
if (psiAnnotationMemberValue instanceof PsiLiteralExpression) {
final Object value = ((PsiLiteralExpression)psiAnnotationMemberValue).getValue();
if ("itself".equals(value)) {
final PsiMember member = PsiTreeUtil.getParentOfType(annotation, PsiMember.class);
if (member != null) return member.getName();
}
return trim;
if (value instanceof String) {
return (String)value;
}
}
return null;
}
@@ -0,0 +1,11 @@
import javax.annotation.concurrent.GuardedBy;
class CheapReadWriteLock {
@GuardedBy(<error descr="Incompatible types. Found: 'int', required: 'java.lang.String'">1</error>) private volatile int value;
public int getValue() { return value; }
public synchronized int increment() {
return value++;
}
}
@@ -43,6 +43,10 @@ public class FieldAccessedNotGuardedInspectionTest extends LightCodeInsightFixtu
doTest();
}
public void testIncompleteCode() {
doTest();
}
public void testStaticSyncOnClass() {
doTest();
}