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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java (+4 lines)
Lines 779-784 Link Here
779
	if ((this.bits & ASTNode.RestrictiveFlagMASK) == Binding.LOCAL) {
779
	if ((this.bits & ASTNode.RestrictiveFlagMASK) == Binding.LOCAL) {
780
		LocalVariableBinding localVariableBinding = (LocalVariableBinding) this.binding;
780
		LocalVariableBinding localVariableBinding = (LocalVariableBinding) this.binding;
781
		if (localVariableBinding != null) {
781
		if (localVariableBinding != null) {
782
			if ((localVariableBinding.tagBits & TagBits.NotInitialized) != 0) {
783
				// local was tagged as uninitialized
784
				return;
785
			}
782
			switch(localVariableBinding.useFlag) {
786
			switch(localVariableBinding.useFlag) {
783
				case LocalVariableBinding.FAKE_USED :
787
				case LocalVariableBinding.FAKE_USED :
784
				case LocalVariableBinding.USED :
788
				case LocalVariableBinding.USED :
(-)compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java (+4 lines)
Lines 727-732 Link Here
727
	if ((this.bits & ASTNode.RestrictiveFlagMASK) == Binding.LOCAL) {
727
	if ((this.bits & ASTNode.RestrictiveFlagMASK) == Binding.LOCAL) {
728
		LocalVariableBinding localVariableBinding = (LocalVariableBinding) this.binding;
728
		LocalVariableBinding localVariableBinding = (LocalVariableBinding) this.binding;
729
		if (localVariableBinding != null) {
729
		if (localVariableBinding != null) {
730
			if ((localVariableBinding.tagBits & TagBits.NotInitialized) != 0) {
731
				// local was tagged as uninitialized
732
				return;
733
			}
730
			switch(localVariableBinding.useFlag) {
734
			switch(localVariableBinding.useFlag) {
731
				case LocalVariableBinding.FAKE_USED :
735
				case LocalVariableBinding.FAKE_USED :
732
				case LocalVariableBinding.USED :
736
				case LocalVariableBinding.USED :
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/TagBits.java (+3 lines)
Lines 33-38 Link Here
33
	// for method
33
	// for method
34
	long HasUncheckedTypeArgumentForBoundCheck = ASTNode.Bit9;
34
	long HasUncheckedTypeArgumentForBoundCheck = ASTNode.Bit9;
35
	
35
	
36
	// local variable
37
	long NotInitialized = ASTNode.Bit9;
38
36
	// set when method has argument(s) that couldn't be resolved
39
	// set when method has argument(s) that couldn't be resolved
37
	long HasUnresolvedArguments = ASTNode.Bit10;
40
	long HasUnresolvedArguments = ASTNode.Bit10;
38
	
41
	
(-)compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java (+1 lines)
Lines 6777-6782 Link Here
6777
		nodeSourceEnd(field, location));
6777
		nodeSourceEnd(field, location));
6778
}
6778
}
6779
public void uninitializedLocalVariable(LocalVariableBinding binding, ASTNode location) {
6779
public void uninitializedLocalVariable(LocalVariableBinding binding, ASTNode location) {
6780
	binding.tagBits |= TagBits.NotInitialized;
6780
	String[] arguments = new String[] {new String(binding.readableName())};
6781
	String[] arguments = new String[] {new String(binding.readableName())};
6781
	this.handle(
6782
	this.handle(
6782
		IProblem.UninitializedLocalVariable,
6783
		IProblem.UninitializedLocalVariable,
(-)src/org/eclipse/jdt/core/tests/compiler/regression/InitializationTests.java (-1 / +55 lines)
Lines 338-344 Link Here
338
			"----------\n",
338
			"----------\n",
339
			null, false, options);
339
			null, false, options);
340
}
340
}
341
341
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=325567
342
public void test325567() {
343
	Map options = getCompilerOptions();
344
	options.put(CompilerOptions.OPTION_ReportDeadCode, CompilerOptions.IGNORE);
345
	this.runNegativeTest(
346
			new String[] {
347
				"X.java",
348
				"import java.io.IOException;\n" + 
349
				"\n" + 
350
				"public class X {\n" + 
351
				"	public static void main(String[] args) {\n" + 
352
				"		bar(3);\n" + 
353
				"	}\n" + 
354
				"	public static void bar(int i) {\n" + 
355
				"		final String before;\n" + 
356
				"		try {\n" + 
357
				"			before = foo();\n" + 
358
				"		} catch (IOException e) {\n" + 
359
				"			// ignore\n" + 
360
				"		}\n" + 
361
				"		B b = new B(new I() {\n" + 
362
				"			public String bar() {\n" + 
363
				"				return new String(before);\n" + 
364
				"			}\n" + 
365
				"		});\n" + 
366
				"		try {\n" + 
367
				"			b.i.bar();\n" + 
368
				"		} catch(Exception e) {\n" + 
369
				"			// ignore\n" + 
370
				"		}\n" + 
371
				"	}\n" + 
372
				"\n" + 
373
				"	private static String foo() throws IOException {\n" + 
374
				"		return null;\n" + 
375
				"	}\n" + 
376
				"	\n" + 
377
				"	static class B {\n" + 
378
				"		I i;\n" + 
379
				"		B(I i) {\n" + 
380
				"			this.i = i;\n" + 
381
				"		}\n" + 
382
				"	}\n" + 
383
				"	static interface I {\n" + 
384
				"		String bar();\n" + 
385
				"	}\n" + 
386
				"}"
387
			},
388
			"----------\n" + 
389
			"1. ERROR in X.java (at line 16)\n" + 
390
			"	return new String(before);\n" + 
391
			"	                  ^^^^^^\n" + 
392
			"The local variable before may not have been initialized\n" + 
393
			"----------\n",
394
			null, false, options);
395
}
342
public static Class testClass() {
396
public static Class testClass() {
343
	return InitializationTests.class;
397
	return InitializationTests.class;
344
}
398
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java (-1 / +72 lines)
Lines 31-37 Link Here
31
// All specified tests which does not belong to the class are skipped...
31
// All specified tests which does not belong to the class are skipped...
32
static {
32
static {
33
//		TESTS_NAMES = new String[] { "test127" };
33
//		TESTS_NAMES = new String[] { "test127" };
34
//		TESTS_NUMBERS = new int[] { 109 };
34
//		TESTS_NUMBERS = new int[] { 113 };
35
//		TESTS_RANGE = new int[] { 108, -1 };
35
//		TESTS_RANGE = new int[] { 108, -1 };
36
}
36
}
37
37
Lines 5816-5819 Link Here
5816
		"int pe0, int pe1, int pe2, int pe3, int pe4, int pe5, int pe6, int pe7, int pe8, int pe9, int pea, int peb, int pec, int ped, int pee, int pef, \n" + 
5816
		"int pe0, int pe1, int pe2, int pe3, int pe4, int pe5, int pe6, int pe7, int pe8, int pe9, int pea, int peb, int pec, int ped, int pee, int pef, \n" + 
5817
		"int pf0, int pf1, int pf2, int pf3, int pf4, int pf5, int pf6, int pf7, int pf8, int pf9, int pfa, int pfb, int pfc");
5817
		"int pf0, int pf1, int pf2, int pf3, int pf4, int pf5, int pf6, int pf7, int pf8, int pf9, int pfa, int pfb, int pfc");
5818
}
5818
}
5819
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=325567
5820
public void test113() {
5821
	this.runNegativeTest(
5822
		new String[] {
5823
			"X.java",
5824
			"import java.io.IOException;\n" + 
5825
			"public class X {\n" + 
5826
			"	public static void bar(int i) {\n" + 
5827
			"		final String before;\n" + 
5828
			"		try {\n" + 
5829
			"			before = foo();\n" + 
5830
			"		} catch (IOException e) {\n" + 
5831
			"			// ignore\n" + 
5832
			"		}\n" + 
5833
			"		B b = new B(new I() {\n" + 
5834
			"			public String bar() {\n" + 
5835
			"				return new String(before);\n" + 
5836
			"			}\n" + 
5837
			"		});\n" + 
5838
			"		try {\n" + 
5839
			"			b.toString();\n" + 
5840
			"		} catch(Exception e) {\n" + 
5841
			"			// ignore\n" + 
5842
			"		}\n" + 
5843
			"	}\n" + 
5844
			"	private static String foo() throws IOException {\n" + 
5845
			"		return null;\n" + 
5846
			"	}\n" + 
5847
			"	static class B {\n" + 
5848
			"		B(I i) {\n" + 
5849
			"			//ignore\n" + 
5850
			"		}\n" + 
5851
			"	}\n" + 
5852
			"	static interface I {\n" + 
5853
			"		String bar();\n" + 
5854
			"	}\n" + 
5855
			"}"
5856
		},
5857
		"----------\n" + 
5858
		"1. ERROR in X.java (at line 12)\n" + 
5859
		"	return new String(before);\n" + 
5860
		"	                  ^^^^^^\n" + 
5861
		"The local variable before may not have been initialized\n" + 
5862
		"----------\n",
5863
		null /* no extra class libraries */,
5864
		true /* flush output directory */,
5865
		null /* no custom options */,
5866
		true /* do not generate output */,
5867
		false /* do not show category */,
5868
		false /* do not show warning token */,
5869
		false  /* do not skip javac for this peculiar test */,
5870
		false  /* do not perform statements recovery */
5871
	);
5872
	this.runConformTest(
5873
		new String[] {
5874
			"Y.java", //-----------------------------------------------------------------------
5875
			"public class Y {\n" + 
5876
			"	public static void main(String[] args) {\n" + 
5877
			"		try {\n" +
5878
			"			X.bar(3);\n" + 
5879
			"		} catch(VerifyError e) {\n" +
5880
			"			System.out.println(\"FAILED\");\n" +
5881
			"		}\n" +
5882
			"	}\n" + 
5883
			"}",
5884
		},
5885
		"",
5886
		null,
5887
		false,
5888
		null);
5889
}
5819
}
5890
}

Return to bug 325567