warn about usages of final fields in another fields even if they appear after constructor where it would be definitely assigned (IDEA-114280)

This commit is contained in:
anna
2013-10-02 18:08:56 +02:00
parent 6d6b73b496
commit 7bf6e776a3
2 changed files with 7 additions and 3 deletions

View File

@@ -252,7 +252,7 @@ public class HighlightControlFlowUtil {
Map<PsiElement, Collection<PsiReferenceExpression>> uninitializedVarProblems, @NotNull PsiFile containingFile) {
if (variable instanceof ImplicitVariable) return null;
if (!PsiUtil.isAccessedForReading(expression)) return null;
final int startOffset = expression.getTextRange().getStartOffset();
int startOffset = expression.getTextRange().getStartOffset();
final PsiElement topBlock;
if (variable.hasInitializer()) {
topBlock = PsiUtil.getVariableCodeBlock(variable, variable);
@@ -317,6 +317,10 @@ public class HighlightControlFlowUtil {
if (aClass == null || isFieldInitializedInOtherFieldInitializer(aClass, field, field.hasModifierProperty(PsiModifier.STATIC))) {
return null;
}
final PsiField anotherField = PsiTreeUtil.getParentOfType(expression, PsiField.class);
if (anotherField != null && anotherField.getContainingClass() == aClass) {
startOffset = 0;
}
block = null;
// initializers will be checked later
final PsiMethod[] constructors = aClass.getConstructors();

View File

@@ -133,8 +133,8 @@ class c2 {
public c2() {
c = "";
}
// its ok
int k3 = c.length();
int k3 = <error descr="Variable 'c' might not have been initialized">c</error>.length();
c2(int i) {
this();