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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/core/compiler/IProblem.java (+2 lines)
Lines 1151-1156 Link Here
1151
1151
1152
	/** @since 3.7.1 */
1152
	/** @since 3.7.1 */
1153
	int DuplicateInheritedMethods = MethodRelated + 583;
1153
	int DuplicateInheritedMethods = MethodRelated + 583;
1154
	/** @since 3.8 */
1155
	int MethodNameClashHidden = MethodRelated + 584;
1154
	
1156
	
1155
	/**
1157
	/**
1156
	 * 1.5 Syntax errors (when source level < 1.5)
1158
	 * 1.5 Syntax errors (when source level < 1.5)
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java (-1 / +7 lines)
Lines 230-236 Link Here
230
	//		class A implements I<Integer> { public void test(Integer i) {} }
230
	//		class A implements I<Integer> { public void test(Integer i) {} }
231
	//		class B extends A { public void test(Comparable i) {} }
231
	//		class B extends A { public void test(Comparable i) {} }
232
232
233
	if (inheritedMethod.isStatic()) return;
233
	if (inheritedMethod.isStatic() || currentMethod.isStatic()) {
234
		MethodBinding original = inheritedMethod.original(); // can be the same as inherited
235
		if (this.type.scope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_7 && currentMethod.areParameterErasuresEqual(original)) {
236
			problemReporter(currentMethod).methodNameClashHidden(currentMethod, inheritedMethod.declaringClass.isRawType() ? inheritedMethod : original);
237
		}
238
		return; // no chance of bridge method's clashing
239
	}
234
240
235
	if (!detectNameClash(currentMethod, inheritedMethod, false)) { // check up the hierarchy for skipped inherited methods
241
	if (!detectNameClash(currentMethod, inheritedMethod, false)) { // check up the hierarchy for skipped inherited methods
236
		TypeBinding[] currentParams = currentMethod.parameters;
242
		TypeBinding[] currentParams = currentMethod.parameters;
(-)compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java (+21 lines)
Lines 5115-5120 Link Here
5115
		currentMethod.sourceEnd());
5115
		currentMethod.sourceEnd());
5116
}
5116
}
5117
5117
5118
public void methodNameClashHidden(MethodBinding currentMethod, MethodBinding inheritedMethod) {
5119
	this.handle(
5120
		IProblem.MethodNameClashHidden,
5121
		new String[] {
5122
			new String(currentMethod.selector),
5123
			typesAsString(currentMethod, currentMethod.parameters, false),
5124
			new String(currentMethod.declaringClass.readableName()),
5125
			typesAsString(inheritedMethod, inheritedMethod.parameters, false),
5126
			new String(inheritedMethod.declaringClass.readableName()),
5127
		 },
5128
		new String[] {
5129
			new String(currentMethod.selector),
5130
			typesAsString(currentMethod, currentMethod.parameters, true),
5131
			new String(currentMethod.declaringClass.shortReadableName()),
5132
			typesAsString(inheritedMethod, inheritedMethod.parameters, true),
5133
			new String(inheritedMethod.declaringClass.shortReadableName()),
5134
		 },
5135
		currentMethod.sourceStart(),
5136
		currentMethod.sourceEnd());
5137
}
5138
5118
public void methodNeedBody(AbstractMethodDeclaration methodDecl) {
5139
public void methodNeedBody(AbstractMethodDeclaration methodDecl) {
5119
	this.handle(
5140
	this.handle(
5120
		IProblem.MethodRequiresBody,
5141
		IProblem.MethodRequiresBody,
(-)compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties (+1 lines)
Lines 517-522 Link Here
517
578 = Wildcard is not allowed at this location
517
578 = Wildcard is not allowed at this location
518
579 = Unused type arguments for the non generic method {0}({1}) of type {2}; it should not be parameterized with arguments <{3}>
518
579 = Unused type arguments for the non generic method {0}({1}) of type {2}; it should not be parameterized with arguments <{3}>
519
583 = Duplicate methods named {0} with the parameters ({1}) and ({2}) are inherited from the types {3} and {4}
519
583 = Duplicate methods named {0} with the parameters ({1}) and ({2}) are inherited from the types {3} and {4}
520
584 = Name clash: The method {0}({1}) of type {2} has the same erasure as {0}({3}) of type {4} but does not hide it
520
521
521
### FOREACH
522
### FOREACH
522
580 = Type mismatch: cannot convert from element type {0} to {1}
523
580 = Type mismatch: cannot convert from element type {0} to {1}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java (+9 lines)
Lines 1568-1573 Link Here
1568
	}
1568
	}
1569
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=147647
1569
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=147647
1570
	public void test018() {
1570
	public void test018() {
1571
	if (this.complianceLevel >= ClassFileConstants.JDK1_7)
1572
			return;
1571
	this.runConformTest(
1573
	this.runConformTest(
1572
		new String[] {
1574
		new String[] {
1573
			"Y.java",
1575
			"Y.java",
Lines 1593-1598 Link Here
1593
	// in fact, <W extends String> Y<W> make(Class<W> clazz) is the most
1595
	// in fact, <W extends String> Y<W> make(Class<W> clazz) is the most
1594
	// specific method according to JLS 15.12.2.5
1596
	// specific method according to JLS 15.12.2.5
1595
	public void test019() {
1597
	public void test019() {
1598
	if (this.complianceLevel >= ClassFileConstants.JDK1_7)
1599
		return;
1600
1596
	this.runConformTest(
1601
	this.runConformTest(
1597
		new String[] {
1602
		new String[] {
1598
			"Y.java",
1603
			"Y.java",
Lines 1619-1624 Link Here
1619
	}
1624
	}
1620
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=147647
1625
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=147647
1621
	public void test020() {
1626
	public void test020() {
1627
	if (this.complianceLevel >= ClassFileConstants.JDK1_7)
1628
		return;
1622
	this.runConformTest(
1629
	this.runConformTest(
1623
		new String[] {
1630
		new String[] {
1624
			"Y.java",
1631
			"Y.java",
Lines 2680-2685 Link Here
2680
}
2687
}
2681
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=184190
2688
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=184190
2682
public void test056() {
2689
public void test056() {
2690
	if (this.complianceLevel >= ClassFileConstants.JDK1_7)
2691
		return;
2683
	this.runConformTest(
2692
	this.runConformTest(
2684
		new String[] {
2693
		new String[] {
2685
			"X.java",
2694
			"X.java",
(-)src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java (+2 lines)
Lines 677-682 Link Here
677
		expectedProblemAttributes.put("MethodMustOverride", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
677
		expectedProblemAttributes.put("MethodMustOverride", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
678
		expectedProblemAttributes.put("MethodMustOverrideOrImplement", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
678
		expectedProblemAttributes.put("MethodMustOverrideOrImplement", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
679
		expectedProblemAttributes.put("MethodNameClash", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
679
		expectedProblemAttributes.put("MethodNameClash", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
680
		expectedProblemAttributes.put("MethodNameClashHidden", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
680
		expectedProblemAttributes.put("MethodReducesVisibility", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
681
		expectedProblemAttributes.put("MethodReducesVisibility", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
681
		expectedProblemAttributes.put("MethodRequiresBody", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
682
		expectedProblemAttributes.put("MethodRequiresBody", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
682
		expectedProblemAttributes.put("MethodReturnsVoid", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
683
		expectedProblemAttributes.put("MethodReturnsVoid", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
Lines 1344-1349 Link Here
1344
		expectedProblemAttributes.put("MethodMustOverride", SKIP);
1345
		expectedProblemAttributes.put("MethodMustOverride", SKIP);
1345
		expectedProblemAttributes.put("MethodMustOverrideOrImplement", SKIP);
1346
		expectedProblemAttributes.put("MethodMustOverrideOrImplement", SKIP);
1346
		expectedProblemAttributes.put("MethodNameClash", SKIP);
1347
		expectedProblemAttributes.put("MethodNameClash", SKIP);
1348
		expectedProblemAttributes.put("MethodNameClashHidden", SKIP);
1347
		expectedProblemAttributes.put("MethodReducesVisibility", SKIP);
1349
		expectedProblemAttributes.put("MethodReducesVisibility", SKIP);
1348
		expectedProblemAttributes.put("MethodRequiresBody", SKIP);
1350
		expectedProblemAttributes.put("MethodRequiresBody", SKIP);
1349
		expectedProblemAttributes.put("MethodReturnsVoid", SKIP);
1351
		expectedProblemAttributes.put("MethodReturnsVoid", SKIP);
(-)src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java (-35 / +141 lines)
Lines 6437-6442 Link Here
6437
				"	@Override void instanceCase2(Collection c) {}\n" +
6437
				"	@Override void instanceCase2(Collection c) {}\n" +
6438
				"}"
6438
				"}"
6439
			},
6439
			},
6440
			this.complianceLevel < ClassFileConstants.JDK1_7 ?
6440
			"----------\n" +
6441
			"----------\n" +
6441
			"1. WARNING in Parent.java (at line 3)\n" +
6442
			"1. WARNING in Parent.java (at line 3)\n" +
6442
			"	static void staticCase1(Collection c) {}\n" +
6443
			"	static void staticCase1(Collection c) {}\n" +
Lines 6462-6468 Link Here
6462
			"	@Override void instanceCase2(Collection c) {}\n" +
6463
			"	@Override void instanceCase2(Collection c) {}\n" +
6463
			"	                             ^^^^^^^^^^\n" +
6464
			"	                             ^^^^^^^^^^\n" +
6464
			"Collection is a raw type. References to generic type Collection<E> should be parameterized\n" +
6465
			"Collection is a raw type. References to generic type Collection<E> should be parameterized\n" +
6465
			"----------\n"
6466
			"----------\n":
6467
				"----------\n" + 
6468
				"1. WARNING in Parent.java (at line 3)\n" + 
6469
				"	static void staticCase1(Collection c) {}\n" + 
6470
				"	                        ^^^^^^^^^^\n" + 
6471
				"Collection is a raw type. References to generic type Collection<E> should be parameterized\n" + 
6472
				"----------\n" + 
6473
				"2. WARNING in Parent.java (at line 5)\n" + 
6474
				"	void instanceCase1(Collection c) {}\n" + 
6475
				"	                   ^^^^^^^^^^\n" + 
6476
				"Collection is a raw type. References to generic type Collection<E> should be parameterized\n" + 
6477
				"----------\n" + 
6478
				"3. ERROR in Parent.java (at line 9)\n" + 
6479
				"	static void staticCase1(Collection<String> c) {}\n" + 
6480
				"	            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
6481
				"Name clash: The method staticCase1(Collection<String>) of type Child has the same erasure as staticCase1(Collection) of type Parent but does not hide it\n" + 
6482
				"----------\n" + 
6483
				"4. WARNING in Parent.java (at line 10)\n" + 
6484
				"	static void staticCase2(Collection c) {}\n" + 
6485
				"	                        ^^^^^^^^^^\n" + 
6486
				"Collection is a raw type. References to generic type Collection<E> should be parameterized\n" + 
6487
				"----------\n" + 
6488
				"5. ERROR in Parent.java (at line 11)\n" + 
6489
				"	void instanceCase1(Collection<String> c) {}\n" + 
6490
				"	     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
6491
				"Name clash: The method instanceCase1(Collection<String>) of type Child has the same erasure as instanceCase1(Collection) of type Parent but does not override it\n" + 
6492
				"----------\n" + 
6493
				"6. WARNING in Parent.java (at line 12)\n" + 
6494
				"	@Override void instanceCase2(Collection c) {}\n" + 
6495
				"	                             ^^^^^^^^^^\n" + 
6496
				"Collection is a raw type. References to generic type Collection<E> should be parameterized\n" + 
6497
				"----------\n"
6466
			// @Override is an error for instanceCase1
6498
			// @Override is an error for instanceCase1
6467
			// name clash: instanceCase1(Collection<String>) in Child and instanceCase1(Collection) in Parent have the same erasure, yet neither overrides the other
6499
			// name clash: instanceCase1(Collection<String>) in Child and instanceCase1(Collection) in Parent have the same erasure, yet neither overrides the other
6468
		);
6500
		);
Lines 9246-9285 Link Here
9246
			"class X {}\n" +
9278
			"class X {}\n" +
9247
			"class Y<T> {}"
9279
			"class Y<T> {}"
9248
		},
9280
		},
9249
		"----------\n" +
9281
		this.complianceLevel < ClassFileConstants.JDK1_7 ?
9250
		"1. ERROR in B.java (at line 2)\n" +
9282
		"----------\n" + 
9251
		"	static void a(X x) {}\n" +
9283
		"1. ERROR in B.java (at line 2)\n" + 
9252
		"	            ^^^^^^\n" +
9284
		"	static void a(X x) {}\n" + 
9253
		"This static method cannot hide the instance method from A\n" +
9285
		"	            ^^^^^^\n" + 
9254
		"----------\n" +
9286
		"This static method cannot hide the instance method from A\n" + 
9255
		"2. ERROR in B.java (at line 3)\n" +
9287
		"----------\n" + 
9256
		"	static void b(Y<String> y) {}\n" +
9288
		"----------\n" + 
9257
		"	            ^^^^^^^^^^^^^^\n" +
9289
		"1. ERROR in B2.java (at line 2)\n" + 
9258
		"Name clash: The method b(Y<String>) of type B has the same erasure as b(Y<Integer>) of type A but does not override it\n" +
9290
		"	static void b(Y<Integer> y) {}\n" + 
9259
		"----------\n" +
9291
		"	            ^^^^^^^^^^^^^^^\n" + 
9260
		"----------\n" +
9292
		"This static method cannot hide the instance method from A\n" + 
9261
		"1. ERROR in B2.java (at line 2)\n" +
9293
		"----------\n" + 
9262
		"	static void b(Y<Integer> y) {}\n" +
9294
		"----------\n" + 
9263
		"	            ^^^^^^^^^^^^^^^\n" +
9295
		"1. ERROR in C.java (at line 3)\n" + 
9264
		"This static method cannot hide the instance method from A\n" +
9296
		"	void b(Y<String> y) {}\n" + 
9265
		"----------\n" +
9297
		"	     ^^^^^^^^^^^^^^\n" + 
9266
		"----------\n" +
9298
		"Name clash: The method b(Y<String>) of type C has the same erasure as b(Y<Integer>) of type A but does not override it\n" + 
9267
		"1. ERROR in C.java (at line 3)\n" +
9299
		"----------\n" + 
9268
		"	void b(Y<String> y) {}\n" +
9300
		"2. ERROR in C.java (at line 4)\n" + 
9269
		"	     ^^^^^^^^^^^^^^\n" +
9301
		"	void c(X x) {}\n" + 
9270
		"Name clash: The method b(Y<String>) of type C has the same erasure as b(Y<Integer>) of type A but does not override it\n" +
9302
		"	     ^^^^^^\n" + 
9271
		"----------\n" +
9303
		"This instance method cannot override the static method from A\n" + 
9272
		"2. ERROR in C.java (at line 4)\n" +
9304
		"----------\n" + 
9273
		"	void c(X x) {}\n" +
9305
		"----------\n" + 
9274
		"	     ^^^^^^\n" +
9306
		"1. ERROR in C2.java (at line 3)\n" + 
9275
		"This instance method cannot override the static method from A\n" +
9307
		"	void d(Y<Integer> y) {}\n" + 
9276
		"----------\n" +
9308
		"	     ^^^^^^^^^^^^^^^\n" + 
9277
		"----------\n" +
9309
		"This instance method cannot override the static method from A\n" + 
9278
		"1. ERROR in C2.java (at line 3)\n" +
9310
		"----------\n" :
9279
		"	void d(Y<Integer> y) {}\n" +
9311
			"----------\n" + 
9280
		"	     ^^^^^^^^^^^^^^^\n" +
9312
			"1. ERROR in B.java (at line 2)\n" + 
9281
		"This instance method cannot override the static method from A\n" +
9313
			"	static void a(X x) {}\n" + 
9282
		"----------\n"
9314
			"	            ^^^^^^\n" + 
9315
			"This static method cannot hide the instance method from A\n" + 
9316
			"----------\n" + 
9317
			"2. ERROR in B.java (at line 3)\n" + 
9318
			"	static void b(Y<String> y) {}\n" + 
9319
			"	            ^^^^^^^^^^^^^^\n" + 
9320
			"Name clash: The method b(Y<String>) of type B has the same erasure as b(Y<Integer>) of type A but does not hide it\n" + 
9321
			"----------\n" + 
9322
			"3. ERROR in B.java (at line 5)\n" + 
9323
			"	static void d(Y<String> y) {}\n" + 
9324
			"	            ^^^^^^^^^^^^^^\n" + 
9325
			"Name clash: The method d(Y<String>) of type B has the same erasure as d(Y<Integer>) of type A but does not hide it\n" + 
9326
			"----------\n" + 
9327
			"----------\n" + 
9328
			"1. ERROR in B2.java (at line 2)\n" + 
9329
			"	static void b(Y<Integer> y) {}\n" + 
9330
			"	            ^^^^^^^^^^^^^^^\n" + 
9331
			"This static method cannot hide the instance method from A\n" + 
9332
			"----------\n" + 
9333
			"----------\n" + 
9334
			"1. ERROR in C.java (at line 3)\n" + 
9335
			"	void b(Y<String> y) {}\n" + 
9336
			"	     ^^^^^^^^^^^^^^\n" + 
9337
			"Name clash: The method b(Y<String>) of type C has the same erasure as b(Y<Integer>) of type A but does not override it\n" + 
9338
			"----------\n" + 
9339
			"2. ERROR in C.java (at line 4)\n" + 
9340
			"	void c(X x) {}\n" + 
9341
			"	     ^^^^^^\n" + 
9342
			"This instance method cannot override the static method from A\n" + 
9343
			"----------\n" + 
9344
			"3. ERROR in C.java (at line 5)\n" + 
9345
			"	void d(Y<String> y) {}\n" + 
9346
			"	     ^^^^^^^^^^^^^^\n" + 
9347
			"Name clash: The method d(Y<String>) of type C has the same erasure as d(Y<Integer>) of type A but does not hide it\n" + 
9348
			"----------\n" + 
9349
			"----------\n" + 
9350
			"1. ERROR in C2.java (at line 3)\n" + 
9351
			"	void d(Y<Integer> y) {}\n" + 
9352
			"	     ^^^^^^^^^^^^^^^\n" + 
9353
			"This instance method cannot override the static method from A\n" + 
9354
			"----------\n"
9283
	);
9355
	);
9284
}
9356
}
9285
public void test150() {
9357
public void test150() {
Lines 13420-13423 Link Here
13420
		},
13492
		},
13421
		output);
13493
		output);
13422
}
13494
}
13495
public void test345949a() throws Exception {
13496
	if (new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_7) return;
13497
	this.runNegativeTest(
13498
		new String[] {
13499
			"Sub.java",
13500
			"class A<T> {}\n" +
13501
			"class Super {\n" +
13502
			"    public static void foo(A<Number> p) {}\n" +
13503
			"}\n" +
13504
			"public class Sub extends Super {\n" +
13505
			"	 public static void foo(A<Integer> p) {}\n" +
13506
			"}\n"
13507
		},
13508
		"----------\n" + 
13509
		"1. ERROR in Sub.java (at line 6)\n" + 
13510
		"	public static void foo(A<Integer> p) {}\n" + 
13511
		"	                   ^^^^^^^^^^^^^^^^^\n" + 
13512
		"Name clash: The method foo(A<Integer>) of type Sub has the same erasure as foo(A<Number>) of type Super but does not hide it\n" + 
13513
		"----------\n");
13514
}
13515
public void _test345949b() throws Exception {
13516
	this.runNegativeTest(
13517
		new String[] {
13518
			"Sub.java",
13519
			"class Super {\n" +
13520
			"    public static void foo() {}\n" +
13521
			"}\n" +
13522
			"public class Sub extends Super {\n" +
13523
			"	 public static <T> void foo() {}\n" +
13524
			"}\n"
13525
		},
13526
		"");
13527
}
13528
 
13423
}
13529
}

Return to bug 345949