View | Details | Raw Unified | Return to bug 257716 | Differences between
and this patch

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java (-19 / +42 lines)
Lines 18-23 Link Here
18
import org.eclipse.jdt.internal.compiler.ast.Reference;
18
import org.eclipse.jdt.internal.compiler.ast.Reference;
19
import org.eclipse.jdt.internal.compiler.ast.SubRoutineStatement;
19
import org.eclipse.jdt.internal.compiler.ast.SubRoutineStatement;
20
import org.eclipse.jdt.internal.compiler.ast.TryStatement;
20
import org.eclipse.jdt.internal.compiler.ast.TryStatement;
21
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
21
import org.eclipse.jdt.internal.compiler.codegen.BranchLabel;
22
import org.eclipse.jdt.internal.compiler.codegen.BranchLabel;
22
import org.eclipse.jdt.internal.compiler.lookup.Binding;
23
import org.eclipse.jdt.internal.compiler.lookup.Binding;
23
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
24
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
Lines 44-49 Link Here
44
		
45
		
45
boolean deferNullDiagnostic, preemptNullDiagnostic;
46
boolean deferNullDiagnostic, preemptNullDiagnostic;
46
47
48
public static final int 
49
  CAN_ONLY_NULL_NON_NULL = 0x0000, 
50
  	// check against null and non null, with definite values -- comparisons
51
  CAN_ONLY_NULL = 0x0001,
52
  	// check against null, with definite values -- comparisons
53
  CAN_ONLY_NON_NULL = 0x0002,
54
	// check against non null, with definite values -- comparisons
55
  MAY_NULL = 0x0003,
56
	// check against null, with potential values -- NPE guard
57
  CHECK_MASK = 0x00FF,
58
  IN_COMPARISON_NULL = 0x0100,
59
  IN_COMPARISON_NON_NULL = 0x0200,
60
    // check happened in a comparison
61
  IN_ASSIGNMENT = 0x0300,
62
    // check happened in an assignment
63
  IN_INSTANCEOF = 0x0400,
64
    // check happened in an instanceof expression
65
  CONTEXT_MASK = ~CHECK_MASK;
66
47
public FlowContext(FlowContext parent, ASTNode associatedNode) {
67
public FlowContext(FlowContext parent, ASTNode associatedNode) {
48
	this.parent = parent;
68
	this.parent = parent;
49
	this.associatedNode = associatedNode;
69
	this.associatedNode = associatedNode;
Lines 287-292 Link Here
287
	return null;
307
	return null;
288
}
308
}
289
309
310
public FlowInfo getInitsForFinalBlankInitializationCheck(TypeBinding declaringType, FlowInfo flowInfo) {
311
	FlowContext current = this;
312
	FlowInfo inits = flowInfo;
313
	do {
314
		if (current instanceof InitializationFlowContext) {
315
			InitializationFlowContext initializationContext = (InitializationFlowContext) current;
316
			if (((TypeDeclaration)initializationContext.associatedNode).binding == declaringType) {
317
				return inits;
318
			}
319
			inits = initializationContext.initsBeforeContext;
320
			current = initializationContext.initializationParent;
321
		} else if (current instanceof ExceptionHandlingFlowContext) {
322
			ExceptionHandlingFlowContext exceptionContext = (ExceptionHandlingFlowContext) current;
323
			current = exceptionContext.initializationParent == null ? exceptionContext.parent : exceptionContext.initializationParent;
324
		} else {
325
			current = current.parent;
326
		}
327
	} while (current != null);
328
	// not found
329
	return null;
330
}
331
290
/*
332
/*
291
 * lookup through break labels
333
 * lookup through break labels
292
 */
334
 */
Lines 468-492 Link Here
468
	}
510
	}
469
}
511
}
470
512
471
public static final int 
472
  CAN_ONLY_NULL_NON_NULL = 0x0000, 
473
  	// check against null and non null, with definite values -- comparisons
474
  CAN_ONLY_NULL = 0x0001,
475
  	// check against null, with definite values -- comparisons
476
  CAN_ONLY_NON_NULL = 0x0002,
477
	// check against non null, with definite values -- comparisons
478
  MAY_NULL = 0x0003,
479
	// check against null, with potential values -- NPE guard
480
  CHECK_MASK = 0x00FF,
481
  IN_COMPARISON_NULL = 0x0100,
482
  IN_COMPARISON_NON_NULL = 0x0200,
483
    // check happened in a comparison
484
  IN_ASSIGNMENT = 0x0300,
485
    // check happened in an assignment
486
  IN_INSTANCEOF = 0x0400,
487
    // check happened in an instanceof expression
488
  CONTEXT_MASK = ~CHECK_MASK;
489
490
/**
513
/**
491
 * Record a null reference for use by deferred checks. Only looping or 
514
 * Record a null reference for use by deferred checks. Only looping or 
492
 * finally contexts really record that information. The context may
515
 * finally contexts really record that information. The context may
(-)compiler/org/eclipse/jdt/internal/compiler/flow/InitializationFlowContext.java (-4 / +4 lines)
Lines 26-42 Link Here
26
	public TypeBinding[] thrownExceptions = new TypeBinding[5];
26
	public TypeBinding[] thrownExceptions = new TypeBinding[5];
27
	public ASTNode[] exceptionThrowers = new ASTNode[5];
27
	public ASTNode[] exceptionThrowers = new ASTNode[5];
28
	public FlowInfo[] exceptionThrowerFlowInfos = new FlowInfo[5];
28
	public FlowInfo[] exceptionThrowerFlowInfos = new FlowInfo[5];
29
	public FlowInfo	initsBeforeContext;
29
	
30
	
30
	public InitializationFlowContext(
31
	public InitializationFlowContext(FlowContext parent, ASTNode associatedNode, FlowInfo initsBeforeContext, FlowContext initializationParent, BlockScope scope) {
31
		FlowContext parent,
32
		ASTNode associatedNode,
33
		BlockScope scope) {
34
		super(
32
		super(
35
			parent,
33
			parent,
36
			associatedNode,
34
			associatedNode,
37
			Binding.NO_EXCEPTIONS, // no exception allowed by default
35
			Binding.NO_EXCEPTIONS, // no exception allowed by default
36
			initializationParent,
38
			scope, 
37
			scope, 
39
			FlowInfo.DEAD_END);
38
			FlowInfo.DEAD_END);
39
		this.initsBeforeContext = initsBeforeContext;
40
	}
40
	}
41
41
42
	public void checkInitializerExceptions(
42
	public void checkInitializerExceptions(
(-)compiler/org/eclipse/jdt/internal/compiler/flow/ExceptionHandlingFlowContext.java (-1 / +4 lines)
Lines 41-47 Link Here
41
	boolean isMethodContext;
41
	boolean isMethodContext;
42
42
43
	public UnconditionalFlowInfo initsOnReturn;
43
	public UnconditionalFlowInfo initsOnReturn;
44
44
	public FlowContext initializationParent; // special parent relationship only for initialization purpose
45
	
45
	// for dealing with anonymous constructor thrown exceptions
46
	// for dealing with anonymous constructor thrown exceptions
46
	public ArrayList extendedExceptions;
47
	public ArrayList extendedExceptions;
47
	
48
	
Lines 49-54 Link Here
49
		FlowContext parent,
50
		FlowContext parent,
50
		ASTNode associatedNode,
51
		ASTNode associatedNode,
51
		ReferenceBinding[] handledExceptions,
52
		ReferenceBinding[] handledExceptions,
53
		FlowContext initializationParent,
52
		BlockScope scope,
54
		BlockScope scope,
53
		UnconditionalFlowInfo flowInfo) {
55
		UnconditionalFlowInfo flowInfo) {
54
56
Lines 79-84 Link Here
79
		System.arraycopy(this.isReached, 0, this.isNeeded, 0, cacheSize);
81
		System.arraycopy(this.isReached, 0, this.isNeeded, 0, cacheSize);
80
	}
82
	}
81
	this.initsOnReturn = FlowInfo.DEAD_END;	
83
	this.initsOnReturn = FlowInfo.DEAD_END;	
84
	this.	initializationParent = initializationParent;	
82
}
85
}
83
86
84
public void complainIfUnusedExceptionHandlers(AbstractMethodDeclaration method) {
87
public void complainIfUnusedExceptionHandlers(AbstractMethodDeclaration method) {
(-)compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java (-9 / +4 lines)
Lines 594-601 Link Here
594
			this.scope.problemReporter().unusedPrivateType(this);
594
			this.scope.problemReporter().unusedPrivateType(this);
595
		}
595
		}
596
	}
596
	}
597
	InitializationFlowContext initializerContext = new InitializationFlowContext(null, this, this.initializerScope);
597
	InitializationFlowContext initializerContext = new InitializationFlowContext(null, this, flowInfo, flowContext, this.initializerScope);
598
	InitializationFlowContext staticInitializerContext = new InitializationFlowContext(null, this, this.staticInitializerScope);
598
	InitializationFlowContext staticInitializerContext = new InitializationFlowContext(null, this, flowInfo, flowContext, this.staticInitializerScope);
599
	FlowInfo nonStaticFieldInfo = flowInfo.unconditionalFieldLessCopy();
599
	FlowInfo nonStaticFieldInfo = flowInfo.unconditionalFieldLessCopy();
600
	FlowInfo staticFieldInfo = flowInfo.unconditionalFieldLessCopy();
600
	FlowInfo staticFieldInfo = flowInfo.unconditionalFieldLessCopy();
601
	if (this.fields != null) {
601
	if (this.fields != null) {
Lines 610-620 Link Here
610
				} else {*/
610
				} else {*/
611
				staticInitializerContext.handledExceptions = Binding.ANY_EXCEPTION; // tolerate them all, and record them
611
				staticInitializerContext.handledExceptions = Binding.ANY_EXCEPTION; // tolerate them all, and record them
612
				/*}*/
612
				/*}*/
613
				staticFieldInfo =
613
				staticFieldInfo = field.analyseCode(this.staticInitializerScope, staticInitializerContext, staticFieldInfo);
614
					field.analyseCode(
615
						this.staticInitializerScope,
616
						staticInitializerContext,
617
						staticFieldInfo);
618
				// in case the initializer is not reachable, use a reinitialized flowInfo and enter a fake reachable
614
				// in case the initializer is not reachable, use a reinitialized flowInfo and enter a fake reachable
619
				// branch, since the previous initializer already got the blame.
615
				// branch, since the previous initializer already got the blame.
620
				if (staticFieldInfo == FlowInfo.DEAD_END) {
616
				if (staticFieldInfo == FlowInfo.DEAD_END) {
Lines 630-637 Link Here
630
				} else {*/
626
				} else {*/
631
					initializerContext.handledExceptions = Binding.ANY_EXCEPTION; // tolerate them all, and record them
627
					initializerContext.handledExceptions = Binding.ANY_EXCEPTION; // tolerate them all, and record them
632
				/*}*/
628
				/*}*/
633
				nonStaticFieldInfo =
629
				nonStaticFieldInfo = field.analyseCode(this.initializerScope, initializerContext, nonStaticFieldInfo);
634
					field.analyseCode(this.initializerScope, initializerContext, nonStaticFieldInfo);
635
				// in case the initializer is not reachable, use a reinitialized flowInfo and enter a fake reachable
630
				// in case the initializer is not reachable, use a reinitialized flowInfo and enter a fake reachable
636
				// branch, since the previous initializer already got the blame.
631
				// branch, since the previous initializer already got the blame.
637
				if (nonStaticFieldInfo == FlowInfo.DEAD_END) {
632
				if (nonStaticFieldInfo == FlowInfo.DEAD_END) {
(-)compiler/org/eclipse/jdt/internal/compiler/ast/Clinit.java (+1 lines)
Lines 53-58 Link Here
53
					staticInitializerFlowContext.parent,
53
					staticInitializerFlowContext.parent,
54
					this,
54
					this,
55
					Binding.NO_EXCEPTIONS,
55
					Binding.NO_EXCEPTIONS,
56
					staticInitializerFlowContext,
56
					scope,
57
					scope,
57
					FlowInfo.DEAD_END);
58
					FlowInfo.DEAD_END);
58
59
(-)compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java (+2 lines)
Lines 87-92 Link Here
87
				flowContext,
87
				flowContext,
88
				this,
88
				this,
89
				this.caughtExceptionTypes,
89
				this.caughtExceptionTypes,
90
				null,
90
				this.scope,
91
				this.scope,
91
				flowInfo.unconditionalInits());
92
				flowInfo.unconditionalInits());
92
		handlingContext.initsOnFinally =
93
		handlingContext.initsOnFinally =
Lines 198-203 Link Here
198
				insideSubContext,
199
				insideSubContext,
199
				this,
200
				this,
200
				this.caughtExceptionTypes,
201
				this.caughtExceptionTypes,
202
				null,
201
				this.scope,
203
				this.scope,
202
				flowInfo.unconditionalInits());
204
				flowInfo.unconditionalInits());
203
		handlingContext.initsOnFinally =
205
		handlingContext.initsOnFinally =
(-)compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java (+1 lines)
Lines 77-82 Link Here
77
				initializerFlowContext.parent,
77
				initializerFlowContext.parent,
78
				this,
78
				this,
79
				this.binding.thrownExceptions,
79
				this.binding.thrownExceptions,
80
				initializerFlowContext,
80
				this.scope,
81
				this.scope,
81
				FlowInfo.DEAD_END);
82
				FlowInfo.DEAD_END);
82
		initializerFlowContext.checkInitializerExceptions(
83
		initializerFlowContext.checkInitializerExceptions(
(-)compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java (-2 / +4 lines)
Lines 62-68 Link Here
62
				FieldBinding fieldBinding;
62
				FieldBinding fieldBinding;
63
				if ((fieldBinding = (FieldBinding) this.binding).isBlankFinal() 
63
				if ((fieldBinding = (FieldBinding) this.binding).isBlankFinal() 
64
						&& currentScope.needBlankFinalFieldInitializationCheck(fieldBinding)) {
64
						&& currentScope.needBlankFinalFieldInitializationCheck(fieldBinding)) {
65
					if (!flowInfo.isDefinitelyAssigned(fieldBinding)) {
65
					FlowInfo fieldInits = flowContext.getInitsForFinalBlankInitializationCheck(fieldBinding.declaringClass.original(), flowInfo);
66
					if (!fieldInits.isDefinitelyAssigned(fieldBinding)) {
66
						currentScope.problemReporter().uninitializedBlankFinalField(fieldBinding, this);
67
						currentScope.problemReporter().uninitializedBlankFinalField(fieldBinding, this);
67
					}
68
					}
68
				}
69
				}
Lines 148-154 Link Here
148
			// check if reading a final blank field
149
			// check if reading a final blank field
149
			FieldBinding fieldBinding = (FieldBinding) this.binding;
150
			FieldBinding fieldBinding = (FieldBinding) this.binding;
150
			if (fieldBinding.isBlankFinal() && currentScope.needBlankFinalFieldInitializationCheck(fieldBinding)) {
151
			if (fieldBinding.isBlankFinal() && currentScope.needBlankFinalFieldInitializationCheck(fieldBinding)) {
151
				if (!flowInfo.isDefinitelyAssigned(fieldBinding)) {
152
				FlowInfo fieldInits = flowContext.getInitsForFinalBlankInitializationCheck(fieldBinding.declaringClass.original(), flowInfo);
153
				if (!fieldInits.isDefinitelyAssigned(fieldBinding)) {
152
					currentScope.problemReporter().uninitializedBlankFinalField(fieldBinding, this);
154
					currentScope.problemReporter().uninitializedBlankFinalField(fieldBinding, this);
153
				}
155
				}
154
			}
156
			}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java (-5 / +7 lines)
Lines 57-71 Link Here
57
57
58
}
58
}
59
59
60
public FlowInfo analyseAssignment(BlockScope currentScope, 	FlowContext flowContext, 	FlowInfo flowInfo, Assignment assignment, boolean isCompound) {
60
public FlowInfo analyseAssignment(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo, Assignment assignment, boolean isCompound) {
61
	// compound assignment extra work
61
	// compound assignment extra work
62
	if (isCompound) { // check the variable part is initialized if blank final
62
	if (isCompound) { // check the variable part is initialized if blank final
63
		if (this.binding.isBlankFinal()
63
		if (this.binding.isBlankFinal()
64
			&& this.receiver.isThis()
64
			&& this.receiver.isThis()
65
			&& currentScope.needBlankFinalFieldInitializationCheck(this.binding)
65
			&& currentScope.needBlankFinalFieldInitializationCheck(this.binding)) {
66
			&& (!flowInfo.isDefinitelyAssigned(this.binding))) {
66
			FlowInfo fieldInits = flowContext.getInitsForFinalBlankInitializationCheck(this.binding.declaringClass.original(), flowInfo);
67
			currentScope.problemReporter().uninitializedBlankFinalField(this.binding, this);
67
			if (!fieldInits.isDefinitelyAssigned(this.binding)) {
68
			// we could improve error msg here telling "cannot use compound assignment on final blank field"
68
				currentScope.problemReporter().uninitializedBlankFinalField(this.binding, this);
69
				// we could improve error msg here telling "cannot use compound assignment on final blank field"
70
			}
69
		}
71
		}
70
		manageSyntheticAccessIfNecessary(currentScope, flowInfo, true /*read-access*/);
72
		manageSyntheticAccessIfNecessary(currentScope, flowInfo, true /*read-access*/);
71
	}
73
	}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java (-10 / +13 lines)
Lines 74-83 Link Here
74
			if (lastFieldBinding.isBlankFinal()
74
			if (lastFieldBinding.isBlankFinal()
75
				    && this.otherBindings != null // the last field binding is only assigned
75
				    && this.otherBindings != null // the last field binding is only assigned
76
	 				&& currentScope.needBlankFinalFieldInitializationCheck(lastFieldBinding)) {
76
	 				&& currentScope.needBlankFinalFieldInitializationCheck(lastFieldBinding)) {
77
				if (!flowInfo.isDefinitelyAssigned(lastFieldBinding)) {
77
				FlowInfo fieldInits = flowContext.getInitsForFinalBlankInitializationCheck(lastFieldBinding.declaringClass.original(), flowInfo);
78
					currentScope.problemReporter().uninitializedBlankFinalField(
78
				if (!fieldInits.isDefinitelyAssigned(lastFieldBinding)) {
79
						lastFieldBinding,
79
					currentScope.problemReporter().uninitializedBlankFinalField(lastFieldBinding, this);
80
						this);
81
				}
80
				}
82
			}
81
			}
83
			break;
82
			break;
Lines 122-130 Link Here
122
	if (isCompound) {
121
	if (isCompound) {
123
		if (otherBindingsCount == 0
122
		if (otherBindingsCount == 0
124
				&& lastFieldBinding.isBlankFinal()
123
				&& lastFieldBinding.isBlankFinal()
125
				&& currentScope.needBlankFinalFieldInitializationCheck(lastFieldBinding)
124
				&& currentScope.needBlankFinalFieldInitializationCheck(lastFieldBinding)) {
126
				&& (!flowInfo.isDefinitelyAssigned(lastFieldBinding))) {
125
			FlowInfo fieldInits = flowContext.getInitsForFinalBlankInitializationCheck(lastFieldBinding.declaringClass.original(), flowInfo);
127
			currentScope.problemReporter().uninitializedBlankFinalField(lastFieldBinding, this);
126
			if (!fieldInits.isDefinitelyAssigned(lastFieldBinding)) {
127
				currentScope.problemReporter().uninitializedBlankFinalField(lastFieldBinding, this);
128
			}
128
		}
129
		}
129
		TypeBinding lastReceiverType;
130
		TypeBinding lastReceiverType;
130
		switch (otherBindingsCount) {
131
		switch (otherBindingsCount) {
Lines 212-220 Link Here
212
				FieldBinding fieldBinding = (FieldBinding) this.binding;
213
				FieldBinding fieldBinding = (FieldBinding) this.binding;
213
				// check if reading a final blank field
214
				// check if reading a final blank field
214
				if (fieldBinding.isBlankFinal()
215
				if (fieldBinding.isBlankFinal()
215
						&& currentScope.needBlankFinalFieldInitializationCheck(fieldBinding)
216
						&& currentScope.needBlankFinalFieldInitializationCheck(fieldBinding)) {
216
						&& !flowInfo.isDefinitelyAssigned(fieldBinding)) {
217
					FlowInfo fieldInits = flowContext.getInitsForFinalBlankInitializationCheck(fieldBinding.declaringClass.original(), flowInfo);
217
					currentScope.problemReporter().uninitializedBlankFinalField(fieldBinding, this);
218
					if (!fieldInits.isDefinitelyAssigned(fieldBinding)) {
219
						currentScope.problemReporter().uninitializedBlankFinalField(fieldBinding, this);
220
					}
218
				}
221
				}
219
			}
222
			}
220
			break;
223
			break;
(-)compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java (+1 lines)
Lines 72-77 Link Here
72
					initializationContext,
72
					initializationContext,
73
					this,
73
					this,
74
					this.binding.thrownExceptions,
74
					this.binding.thrownExceptions,
75
					null,
75
					this.scope,
76
					this.scope,
76
					FlowInfo.DEAD_END);
77
					FlowInfo.DEAD_END);
77
78
(-)eval/org/eclipse/jdt/internal/eval/CodeSnippetSingleNameReference.java (-1 / +2 lines)
Lines 45-51 Link Here
45
			FieldBinding fieldBinding;
45
			FieldBinding fieldBinding;
46
			if ((fieldBinding = (FieldBinding) this.binding).isBlankFinal() 
46
			if ((fieldBinding = (FieldBinding) this.binding).isBlankFinal() 
47
					&& currentScope.needBlankFinalFieldInitializationCheck(fieldBinding)) {
47
					&& currentScope.needBlankFinalFieldInitializationCheck(fieldBinding)) {
48
				if (!flowInfo.isDefinitelyAssigned(fieldBinding)) {
48
				FlowInfo fieldInits = flowContext.getInitsForFinalBlankInitializationCheck(fieldBinding.declaringClass.original(), flowInfo);
49
				if (!fieldInits.isDefinitelyAssigned(fieldBinding)) {
49
					currentScope.problemReporter().uninitializedBlankFinalField(fieldBinding, this);
50
					currentScope.problemReporter().uninitializedBlankFinalField(fieldBinding, this);
50
				}
51
				}
51
			}
52
			}
(-)Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/InitializationTest.java (+319 lines)
Lines 5535-5540 Link Here
5535
		}, 
5535
		}, 
5536
		"");
5536
		"");
5537
}
5537
}
5538
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257716
5539
public void test196() {
5540
	this.runConformTest(
5541
		new String[] {
5542
			"X.java",
5543
			"public class X {\n" + 
5544
			"	final int hello;\n" + 
5545
			"	public X() {\n" + 
5546
			"		hello = 0;\n" + 
5547
			"		new Object() {\n" + 
5548
			"			int i = hello;\n" + 
5549
			"		};\n" + 
5550
			"	}\n" + 
5551
			"}\n"
5552
		},
5553
		"");
5554
}
5555
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257716
5556
public void test197() {
5557
	this.runNegativeTest(
5558
		new String[] {
5559
			"X.java",
5560
			"public class X {\n" + 
5561
			"	final int hello;\n" + 
5562
			"	public X(int i) {\n" + 
5563
			"		new Object() {\n" + 
5564
			"			int j = hello;\n" + 
5565
			"		};\n" + 
5566
			"	}\n" + 
5567
			"}\n"
5568
		},
5569
		"----------\n" + 
5570
		"1. ERROR in X.java (at line 3)\n" + 
5571
		"	public X(int i) {\n" + 
5572
		"	       ^^^^^^^^\n" + 
5573
		"The blank final field hello may not have been initialized\n" + 
5574
		"----------\n" + 
5575
		"2. WARNING in X.java (at line 5)\n" + 
5576
		"	int j = hello;\n" + 
5577
		"	    ^\n" + 
5578
		"The field new Object(){}.j is never read locally\n" + 
5579
		"----------\n" + 
5580
		"3. ERROR in X.java (at line 5)\n" + 
5581
		"	int j = hello;\n" + 
5582
		"	        ^^^^^\n" + 
5583
		"The blank final field hello may not have been initialized\n" + 
5584
		"----------\n");
5585
}
5586
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257716
5587
public void test198() {
5588
	this.runNegativeTest(
5589
		new String[] {
5590
			"X.java",
5591
			"public class X {\n" + 
5592
			"	final int hello;\n" + 
5593
			"	public X(long l) {\n" + 
5594
			"		if (l > 0) {\n" + 
5595
			"			new Object() {\n" + 
5596
			"				int j = hello;\n" + 
5597
			"			};\n" + 
5598
			"		}\n" + 
5599
			"	}	\n" + 
5600
			"}\n"
5601
		},
5602
		"----------\n" + 
5603
		"1. ERROR in X.java (at line 3)\n" + 
5604
		"	public X(long l) {\n" + 
5605
		"	       ^^^^^^^^^\n" + 
5606
		"The blank final field hello may not have been initialized\n" + 
5607
		"----------\n" + 
5608
		"2. WARNING in X.java (at line 6)\n" + 
5609
		"	int j = hello;\n" + 
5610
		"	    ^\n" + 
5611
		"The field new Object(){}.j is never read locally\n" + 
5612
		"----------\n" + 
5613
		"3. ERROR in X.java (at line 6)\n" + 
5614
		"	int j = hello;\n" + 
5615
		"	        ^^^^^\n" + 
5616
		"The blank final field hello may not have been initialized\n" + 
5617
		"----------\n");
5618
}
5619
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257716 - variation
5620
public void test199() {
5621
	this.runNegativeTest(
5622
		new String[] {
5623
			"X.java",
5624
			"public class X {\n" + 
5625
			"	final int hello;\n" + 
5626
			"	public X() {\n" + 
5627
			"		hello = 0;\n" + 
5628
			"		new Object() {\n" + 
5629
			"			int i = X.this.hello;\n" + 
5630
			"		};\n" + 
5631
			"	}\n" + 
5632
			"	public X(int a) {\n" + 
5633
			"		new Object() {\n" + 
5634
			"			int j = X.this.hello;\n" + 
5635
			"		};\n" + 
5636
			"	}\n" + 			
5637
			"}\n"
5638
		},
5639
		"----------\n" + 
5640
		"1. WARNING in X.java (at line 6)\n" + 
5641
		"	int i = X.this.hello;\n" + 
5642
		"	    ^\n" + 
5643
		"The field new Object(){}.i is never read locally\n" + 
5644
		"----------\n" + 
5645
		"2. ERROR in X.java (at line 9)\n" + 
5646
		"	public X(int a) {\n" + 
5647
		"	       ^^^^^^^^\n" + 
5648
		"The blank final field hello may not have been initialized\n" + 
5649
		"----------\n" + 
5650
		"3. WARNING in X.java (at line 11)\n" + 
5651
		"	int j = X.this.hello;\n" + 
5652
		"	    ^\n" + 
5653
		"The field new Object(){}.j is never read locally\n" + 
5654
		"----------\n");
5655
}
5656
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257716 - variation
5657
public void test200() {
5658
	this.runNegativeTest(
5659
		new String[] {
5660
			"X.java",
5661
			"public class X {\n" + 
5662
			"	final int hello;\n" + 
5663
			"	public X() {\n" + 
5664
			"		hello = 0;\n" + 
5665
			"		new Object() {\n" + 
5666
			"			X x = X.this;\n" + 
5667
			"			int i = x.hello;\n" + 
5668
			"		};\n" + 
5669
			"	}\n" + 
5670
			"	public X(int a) {\n" + 
5671
			"		new Object() {\n" + 
5672
			"			X x = X.this;\n" + 
5673
			"			int j = x.hello;\n" + 
5674
			"		};\n" + 
5675
			"	}\n" + 
5676
			"}\n"
5677
		},
5678
		"----------\n" + 
5679
		"1. WARNING in X.java (at line 7)\n" + 
5680
		"	int i = x.hello;\n" + 
5681
		"	    ^\n" + 
5682
		"The field new Object(){}.i is never read locally\n" + 
5683
		"----------\n" + 
5684
		"2. ERROR in X.java (at line 10)\n" + 
5685
		"	public X(int a) {\n" + 
5686
		"	       ^^^^^^^^\n" + 
5687
		"The blank final field hello may not have been initialized\n" + 
5688
		"----------\n" + 
5689
		"3. WARNING in X.java (at line 13)\n" + 
5690
		"	int j = x.hello;\n" + 
5691
		"	    ^\n" + 
5692
		"The field new Object(){}.j is never read locally\n" + 
5693
		"----------\n");
5694
}
5695
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257716 - variation
5696
public void test201() {
5697
	this.runNegativeTest(
5698
		new String[] {
5699
			"X.java",
5700
			"public class X {\n" + 
5701
			"	final int hello;\n" + 
5702
			"	class M {\n" + 
5703
			"		public M() {\n" + 
5704
			"			hello = 0;\n" + 
5705
			"			new Object() {\n" + 
5706
			"				int i = hello;\n" + 
5707
			"			};\n" + 
5708
			"		}\n" + 
5709
			"		public M(int a) {\n" + 
5710
			"			new Object() {\n" + 
5711
			"				int j = hello;\n" + 
5712
			"			};\n" + 
5713
			"		}\n" + 
5714
			"	}\n" + 
5715
			"}\n"
5716
		},
5717
		"----------\n" + 
5718
		"1. ERROR in X.java (at line 1)\n" + 
5719
		"	public class X {\n" + 
5720
		"	             ^\n" + 
5721
		"The blank final field hello may not have been initialized\n" + 
5722
		"----------\n" + 
5723
		"2. ERROR in X.java (at line 5)\n" + 
5724
		"	hello = 0;\n" + 
5725
		"	^^^^^\n" + 
5726
		"The final field X.hello cannot be assigned\n" + 
5727
		"----------\n" + 
5728
		"3. WARNING in X.java (at line 7)\n" + 
5729
		"	int i = hello;\n" + 
5730
		"	    ^\n" + 
5731
		"The field new Object(){}.i is never read locally\n" + 
5732
		"----------\n" + 
5733
		"4. WARNING in X.java (at line 12)\n" + 
5734
		"	int j = hello;\n" + 
5735
		"	    ^\n" + 
5736
		"The field new Object(){}.j is never read locally\n" + 
5737
		"----------\n");
5738
}
5739
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257716 - variation
5740
public void test202() {
5741
	this.runNegativeTest(
5742
		new String[] {
5743
			"X.java",
5744
			"public class X {\n" + 
5745
			"	final int hello;\n" + 
5746
			"	public X() {\n" + 
5747
			"		hello = 0;\n" + 
5748
			"		class Local {\n" + 
5749
			"			Object o = new Object() {\n" + 
5750
			"				int i = hello;\n" + 
5751
			"			};\n" + 
5752
			"		}\n" + 
5753
			"	}\n" + 
5754
			"	public X(int a) {\n" + 
5755
			"		class Local {\n" + 
5756
			"			Object o = new Object() {\n" + 
5757
			"				int j = hello;\n" + 
5758
			"			};\n" + 
5759
			"		}\n" + 
5760
			"	}\n" + 
5761
			"}\n"
5762
5763
		},
5764
		"----------\n" + 
5765
		"1. WARNING in X.java (at line 5)\n" + 
5766
		"	class Local {\n" + 
5767
		"	      ^^^^^\n" + 
5768
		"The type Local is never used locally\n" + 
5769
		"----------\n" + 
5770
		"2. WARNING in X.java (at line 6)\n" + 
5771
		"	Object o = new Object() {\n" + 
5772
		"	       ^\n" + 
5773
		"The field Local.o is never read locally\n" + 
5774
		"----------\n" + 
5775
		"3. WARNING in X.java (at line 7)\n" + 
5776
		"	int i = hello;\n" + 
5777
		"	    ^\n" + 
5778
		"The field new Object(){}.i is never read locally\n" + 
5779
		"----------\n" + 
5780
		"4. ERROR in X.java (at line 11)\n" + 
5781
		"	public X(int a) {\n" + 
5782
		"	       ^^^^^^^^\n" + 
5783
		"The blank final field hello may not have been initialized\n" + 
5784
		"----------\n" + 
5785
		"5. WARNING in X.java (at line 12)\n" + 
5786
		"	class Local {\n" + 
5787
		"	      ^^^^^\n" + 
5788
		"The type Local is never used locally\n" + 
5789
		"----------\n" + 
5790
		"6. WARNING in X.java (at line 13)\n" + 
5791
		"	Object o = new Object() {\n" + 
5792
		"	       ^\n" + 
5793
		"The field Local.o is never read locally\n" + 
5794
		"----------\n" + 
5795
		"7. WARNING in X.java (at line 14)\n" + 
5796
		"	int j = hello;\n" + 
5797
		"	    ^\n" + 
5798
		"The field new Object(){}.j is never read locally\n" + 
5799
		"----------\n");
5800
}
5801
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257716 - variation
5802
public void test203() {
5803
	this.runNegativeTest(
5804
		new String[] {
5805
			"X.java",
5806
			"public class X {\n" + 
5807
			"	final int hello;\n" + 
5808
			"	public X() {\n" + 
5809
			"		hello = 0;\n" + 
5810
			"		new X() {\n" + 
5811
			"			final int world;\n" + 
5812
			"			{\n" + 
5813
			"				world = 0;\n" + 
5814
			"			}\n" + 
5815
			"			int i = new Object() {\n" + 
5816
			"				int j = hello + world; \n" + 
5817
			"			}.j;\n" + 
5818
			"		};\n" + 
5819
			"	}\n" + 
5820
			"	public X(int i) {\n" + 
5821
			"		new X() {\n" + 
5822
			"			final int world;\n" + 
5823
			"			{\n" + 
5824
			"				world = 0;\n" + 
5825
			"			}			\n" + 
5826
			"			int k = new Object() { \n" + 
5827
			"				int l = hello + world; \n" + 
5828
			"			}.l;\n" + 
5829
			"		};\n" + 
5830
			"	}\n" + 
5831
			"}\n"
5832
5833
		},
5834
		"----------\n" + 
5835
		"1. WARNING in X.java (at line 10)\n" + 
5836
		"	int i = new Object() {\n" + 
5837
		"	    ^\n" + 
5838
		"The field new X(){}.i is never read locally\n" + 
5839
		"----------\n" + 
5840
		"2. ERROR in X.java (at line 15)\n" + 
5841
		"	public X(int i) {\n" + 
5842
		"	       ^^^^^^^^\n" + 
5843
		"The blank final field hello may not have been initialized\n" + 
5844
		"----------\n" + 
5845
		"3. WARNING in X.java (at line 21)\n" + 
5846
		"	int k = new Object() { \n" + 
5847
		"	    ^\n" + 
5848
		"The field new X(){}.k is never read locally\n" + 
5849
		"----------\n" + 
5850
		"4. ERROR in X.java (at line 22)\n" + 
5851
		"	int l = hello + world; \n" + 
5852
		"	        ^^^^^\n" + 
5853
		"The blank final field hello may not have been initialized\n" + 
5854
		"----------\n");
5855
}
5856
5538
public static Class testClass() {
5857
public static Class testClass() {
5539
	return InitializationTest.class;
5858
	return InitializationTest.class;
5540
}
5859
}

Return to bug 257716