DfaNullability (@NotNull DfaVariableValue value, @Nullable PsiElement context) { PsiField field = ObjectUtils.tryCast(myVariable, PsiField.class); if (field != null && hasInitializationHacks(field)) { return DfaNullability.FLUSHED; } DfaVariableValue qualifier = value.getQualifier(); if (field != null && context != null) { PsiMember member = ObjectUtils.tryCast(context.getParent(), PsiMember.class); if (member != null) { PsiClass methodClass = member.getContainingClass(); if (methodClass != null && methodClass.equals(field.getContainingClass())) { PsiMethod method = ObjectUtils.tryCast(member, PsiMethod.class); VariableDescriptor qualifierDescriptor = qualifier == null ? null : qualifier.getDescriptor(); if (qualifierDescriptor instanceof ThisDescriptor && ((ThisDescriptor)qualifierDescriptor).getPsiElement().equals(methodClass)) { if (member instanceof PsiClassInitializer) { return DfaNullability.UNKNOWN; } if (method != null) { if (!method.isConstructor() && isPossiblyNonInitialized(field, method)) { return DfaNullability.NULLABLE; } else if (method.isConstructor()) { return DfaNullability.UNKNOWN; } } } if (method != null && field.hasModifierProperty(PsiModifier.STATIC) && isPossiblyNonInitialized(field, method)) { return DfaNullability.NULLABLE; } } } } PsiType type = getType(qualifier); Nullability nullability = DfaPsiUtil.getElementNullabilityIgnoringParameterInference(type, myVariable); if (nullability != Nullability.UNKNOWN) { return DfaNullability.fromNullability(nullability); } if (myVariable instanceof PsiParameter && myVariable.getParent() instanceof PsiForeachStatement) { PsiExpression iteratedValue = ((PsiForeachStatement)myVariable.getParent()).getIteratedValue(); if (iteratedValue != null) { PsiType itemType = JavaGenericsUtil.getCollectionItemType(iteratedValue); if (itemType != null) { return DfaNullability.fromNullability(DfaPsiUtil.getElementNullability(itemType, myVariable)); } } } if (field != null && FieldChecker.getChecker(context).canTrustFieldInitializer(field)) { return DfaNullability.fromNullability(NullabilityUtil.getNullabilityFromFieldInitializers(field).second); } return DfaNullability.UNKNOWN; }