View | Details | Raw Unified | Return to bug 264991
Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java (-1 / +1 lines)
Lines 59-65 Link Here
59
		if (constructorBinding.isPrivate()) {
59
		if (constructorBinding.isPrivate()) {
60
			if ((this.binding.declaringClass.tagBits & TagBits.HasNonPrivateConstructor) == 0)
60
			if ((this.binding.declaringClass.tagBits & TagBits.HasNonPrivateConstructor) == 0)
61
				break checkUnused; // tolerate as known pattern to block instantiation
61
				break checkUnused; // tolerate as known pattern to block instantiation
62
		} else if (!constructorBinding.isOrEnclosedByPrivateType()) {
62
		} else if ((this.binding.declaringClass.tagBits & (TagBits.IsAnonymousType|TagBits.IsLocalType)) != TagBits.IsLocalType) {
63
			break checkUnused;
63
			break checkUnused;
64
		}
64
		}
65
		// complain unused
65
		// complain unused
(-)src/org/eclipse/jdt/core/tests/compiler/regression/InnerEmulationTest.java (-9 / +4 lines)
Lines 6443-6469 Link Here
6443
				"	              ^^^^^\n" +
6443
				"	              ^^^^^\n" +
6444
				"The type X.Test4 is never used locally\n" +
6444
				"The type X.Test4 is never used locally\n" +
6445
				"----------\n" +
6445
				"----------\n" +
6446
				"2. WARNING in X.java (at line 13)\n" +
6446
				"2. ERROR in X.java (at line 16)\n" +
6447
				"	public Test4() {\n" +
6448
				"	       ^^^^^^^\n" +
6449
				"The constructor X.Test4() is never used locally\n" + 
6450
				"----------\n" +
6451
				"3. ERROR in X.java (at line 16)\n" +
6452
				"	System.out.println(X.this.var1.trim());\n" +
6447
				"	System.out.println(X.this.var1.trim());\n" +
6453
				"	                   ^^^^^^\n" +
6448
				"	                   ^^^^^^\n" +
6454
				"No enclosing instance of the type X is accessible in scope\n" +
6449
				"No enclosing instance of the type X is accessible in scope\n" +
6455
				"----------\n" +
6450
				"----------\n" +
6456
				"4. WARNING in X.java (at line 16)\n" +
6451
				"3. WARNING in X.java (at line 16)\n" +
6457
				"	System.out.println(X.this.var1.trim());\n" +
6452
				"	System.out.println(X.this.var1.trim());\n" +
6458
				"	                          ^^^^\n" +
6453
				"	                          ^^^^\n" +
6459
				"Read access to enclosing field X.var1 is emulated by a synthetic accessor method\n" +
6454
				"Read access to enclosing field X.var1 is emulated by a synthetic accessor method\n" +
6460
				"----------\n" +
6455
				"----------\n" +
6461
				"5. WARNING in X.java (at line 17)\n" +
6456
				"4. WARNING in X.java (at line 17)\n" +
6462
				"	System.out.println(var1.trim());\n" +
6457
				"	System.out.println(var1.trim());\n" +
6463
				"	                   ^^^^\n" +
6458
				"	                   ^^^^\n" +
6464
				"Read access to enclosing field X.var1 is emulated by a synthetic accessor method\n" +
6459
				"Read access to enclosing field X.var1 is emulated by a synthetic accessor method\n" +
6465
				"----------\n" +
6460
				"----------\n" +
6466
				"6. ERROR in X.java (at line 17)\n" +
6461
				"5. ERROR in X.java (at line 17)\n" +
6467
				"	System.out.println(var1.trim());\n" +
6462
				"	System.out.println(var1.trim());\n" +
6468
				"	                   ^^^^\n" +
6463
				"	                   ^^^^\n" +
6469
				"No enclosing instance of the type X is accessible in scope\n" +
6464
				"No enclosing instance of the type X is accessible in scope\n" +
(-)src/org/eclipse/jdt/core/tests/compiler/regression/ProblemConstructorTest.java (-7 / +30 lines)
Lines 177-197 Link Here
177
			"	           ^^^^^^^^^^^^^^\n" + 
177
			"	           ^^^^^^^^^^^^^^\n" + 
178
			"The method unusedMethod() from the type X.M is never used locally\n" + 
178
			"The method unusedMethod() from the type X.M is never used locally\n" + 
179
			"----------\n" + 
179
			"----------\n" + 
180
			"2. WARNING in X.java (at line 5)\n" + 
180
			"2. WARNING in X.java (at line 6)\n" + 
181
			"	public M (int state) { this.state = state;} \n" + 
182
			"	       ^^^^^^^^^^^^^\n" + 
183
			"The constructor X.M(int) is never used locally\n" + 
184
			"----------\n" + 
185
			"3. WARNING in X.java (at line 6)\n" + 
186
			"	public int unusedField = 0;\n" + 
181
			"	public int unusedField = 0;\n" + 
187
			"	           ^^^^^^^^^^^\n" + 
182
			"	           ^^^^^^^^^^^\n" + 
188
			"The field X.M.unusedField is never read locally\n" + 
183
			"The field X.M.unusedField is never read locally\n" + 
189
			"----------\n" + 
184
			"----------\n" + 
190
			"4. WARNING in X.java (at line 7)\n" + 
185
			"3. WARNING in X.java (at line 7)\n" + 
191
			"	public class N {}\n" + 
186
			"	public class N {}\n" + 
192
			"	             ^\n" + 
187
			"	             ^\n" + 
193
			"The type X.M.N is never used locally\n" + 
188
			"The type X.M.N is never used locally\n" + 
194
			"----------\n"
189
			"----------\n"
195
			);
190
			);
196
}
191
}
192
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=264991, wrong unused warning reported. Test to ensure that
193
// we DON'T complain about the constructor of B not being used (as its removal would result in a compile
194
// error since its base class does not have a no-arg constructor for the synthesized default constructor
195
// to invoke.
196
public void test005() {
197
	this.runNegativeTest(
198
		new String[] {
199
				"A.java",
200
				"public class A {\n" +
201
			    "    public A(String s) {\n" +
202
			    "            B.test();\n" +
203
			    "    }\n" +
204
                "\n" +
205
			    "    private static class B extends A {\n" +
206
			    "       public B () { super(\"\"); }\n" +
207
			    "\n" +
208
			    "            private static void test() {\n" +
209
			    "            };\n" +
210
			    "   }\n" +
211
				"}\n"
212
			},
213
			"----------\n" + 
214
			"1. WARNING in A.java (at line 3)\n" + 
215
			"	B.test();\n" + 
216
			"	^^^^^^^^\n" + 
217
			"Access to enclosing method test() from the type A.B is emulated by a synthetic accessor method\n" + 
218
			"----------\n");
219
}
197
}
220
}

Return to bug 264991