mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
guarded by inspections: don't fail on invalid code
EA-124454 - SIOOBE: JCiPUtil.getGuardValue
This commit is contained in:
+6
-5
@@ -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++;
|
||||
}
|
||||
}
|
||||
+4
@@ -43,6 +43,10 @@ public class FieldAccessedNotGuardedInspectionTest extends LightCodeInsightFixtu
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testIncompleteCode() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testStaticSyncOnClass() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user