void (@NotNull PsiReferenceExpression expression) { super.visitReferenceExpression(expression); final PsiElement target = expression.resolve(); if (!(target instanceof PsiField lockedField)) { return; } if (!lockedField.hasModifierProperty(PsiModifier.STATIC) || ExpressionUtils.isConstant(lockedField)) { return; } if (lockedField.hasModifierProperty(PsiModifier.FINAL)) { final PsiClass aClass = PsiUtil.resolveClassInClassTypeOnly(lockedField.getType()); final ConcurrencyAnnotationsManager annotationsManager = ConcurrencyAnnotationsManager.getInstance(expression.getProject()); final List<String> list = annotationsManager.getThreadSafeList(); if (AnnotationUtil.findAnnotation(aClass, list) != null) { return; } } final PsiClass containingClass = lockedField.getContainingClass(); if (!PsiTreeUtil.isAncestor(containingClass, expression, false)) { return; } if (!ignoredClasses.isEmpty() && ignoredClasses.contains(TypeUtils.resolvedClassName(lockedField.getType()))) { return; } boolean isLockedOnInstance = false; boolean isLockedOnClass = false; final PsiMethod containingMethod = PsiTreeUtil.getParentOfType(expression, PsiMethod.class); if (containingMethod != null && containingMethod.hasModifierProperty(PsiModifier.SYNCHRONIZED)) { if (containingMethod.hasModifierProperty(PsiModifier.STATIC)) { isLockedOnClass = true; } else { isLockedOnInstance = true; } } final PsiClass expressionClass = PsiTreeUtil.getParentOfType(expression, PsiClass.class); if (expressionClass == null) { return; } PsiElement elementToCheck = expression; while (true) { final PsiSynchronizedStatement synchronizedStatement = PsiTreeUtil.getParentOfType(elementToCheck, PsiSynchronizedStatement.class); if (synchronizedStatement == null || !PsiTreeUtil.isAncestor(expressionClass, synchronizedStatement, true)) { break; } final PsiExpression lockExpression = synchronizedStatement.getLockExpression(); if (lockExpression instanceof PsiReferenceExpression reference) { final PsiElement lockTarget = reference.resolve(); if (lockTarget instanceof PsiField lockField) { if (lockField.hasModifierProperty(PsiModifier.STATIC)) { isLockedOnClass = true; } else { isLockedOnInstance = true; } } } else if (lockExpression instanceof PsiThisExpression) { isLockedOnInstance = true; } else if (lockExpression instanceof PsiClassObjectAccessExpression) { isLockedOnClass = true; } elementToCheck = synchronizedStatement; } if (!isLockedOnInstance || isLockedOnClass) { return; } registerError(expression, expression); }