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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java (-6 / +12 lines)
Lines 1163-1178 Link Here
1163
				} else if (!method.areParametersEqual(method2)) { // prior to 1.5, parameter identity meant a collision case
1163
				} else if (!method.areParametersEqual(method2)) { // prior to 1.5, parameter identity meant a collision case
1164
					continue nextSibling;
1164
					continue nextSibling;
1165
				}
1165
				}
1166
				boolean isEnumSpecialMethod = isEnum() && (CharOperation.equals(selector,TypeConstants.VALUEOF) || CharOperation.equals(selector,TypeConstants.VALUES));
1167
				// report duplicate
1166
				// report duplicate
1168
				AbstractMethodDeclaration method2Decl = method2.sourceMethod();
1167
				AbstractMethodDeclaration methodToBlame = method2.sourceMethod();
1169
				if (method2Decl != null && method2Decl.binding != null) { // ensure its a valid user defined method
1168
				if (methodToBlame == null) { // if method2 is synthetic (like enum#valueOf) blame it on first method instead
1169
					if (methodDecl == null) {
1170
						methodDecl = method.sourceMethod();
1171
					}
1172
					methodToBlame = methodDecl; 
1173
				}
1174
				if (methodToBlame != null && methodToBlame.binding != null) { // ensure its a valid user defined method
1175
					boolean isEnumSpecialMethod = isEnum() && (CharOperation.equals(selector,TypeConstants.VALUEOF) || CharOperation.equals(selector,TypeConstants.VALUES));
1170
					if (isEnumSpecialMethod) {
1176
					if (isEnumSpecialMethod) {
1171
						this.scope.problemReporter().duplicateEnumSpecialMethod(this, method2Decl);
1177
						this.scope.problemReporter().duplicateEnumSpecialMethod(this, methodToBlame);
1172
					} else {
1178
					} else {
1173
						this.scope.problemReporter().duplicateMethodInType(this, method2Decl, method.areParametersEqual(method2));
1179
						this.scope.problemReporter().duplicateMethodInType(this, methodToBlame, method.areParametersEqual(method2));
1174
					}
1180
					}
1175
					method2Decl.binding = null;
1181
					methodToBlame.binding = null;
1176
					// do not alter original method array until resolution is over, due to reentrance (143259)
1182
					// do not alter original method array until resolution is over, due to reentrance (143259)
1177
					if (resolvedMethods == this.methods)
1183
					if (resolvedMethods == this.methods)
1178
						System.arraycopy(this.methods, 0, resolvedMethods = new MethodBinding[length], 0, length);
1184
						System.arraycopy(this.methods, 0, resolvedMethods = new MethodBinding[length], 0, length);
(-)src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java (+17 lines)
Lines 5683-5686 Link Here
5683
			},
5683
			},
5684
			"");
5684
			"");
5685
}
5685
}
5686
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239225 - variation
5687
public void test164() {
5688
	this.runNegativeTest(
5689
			new String[] {
5690
				"X.java", // =================
5691
				"public enum X {\n" + 
5692
				"	;\n" + 
5693
				"	private X valueOf(String arg0) { return null; }\n" + 
5694
				"}\n", // =================
5695
			},
5696
			"----------\n" + 
5697
			"1. ERROR in X.java (at line 3)\n" + 
5698
			"	private X valueOf(String arg0) { return null; }\n" + 
5699
			"	          ^^^^^^^^^^^^^^^^^^^^\n" + 
5700
			"The enum X already defines the method valueOf(String) implicitly\n" + 
5701
			"----------\n");
5702
}
5686
}
5703
}

Return to bug 251523