### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java,v retrieving revision 1.166 diff -u -r1.166 SourceTypeBinding.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java 17 Oct 2008 18:07:19 -0000 1.166 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java 21 Oct 2008 12:24:40 -0000 @@ -1163,16 +1163,22 @@ } else if (!method.areParametersEqual(method2)) { // prior to 1.5, parameter identity meant a collision case continue nextSibling; } - boolean isEnumSpecialMethod = isEnum() && (CharOperation.equals(selector,TypeConstants.VALUEOF) || CharOperation.equals(selector,TypeConstants.VALUES)); // report duplicate - AbstractMethodDeclaration method2Decl = method2.sourceMethod(); - if (method2Decl != null && method2Decl.binding != null) { // ensure its a valid user defined method + AbstractMethodDeclaration methodToBlame = method2.sourceMethod(); + if (methodToBlame == null) { // if method2 is synthetic (like enum#valueOf) blame it on first method instead + if (methodDecl == null) { + methodDecl = method.sourceMethod(); + } + methodToBlame = methodDecl; + } + if (methodToBlame != null && methodToBlame.binding != null) { // ensure its a valid user defined method + boolean isEnumSpecialMethod = isEnum() && (CharOperation.equals(selector,TypeConstants.VALUEOF) || CharOperation.equals(selector,TypeConstants.VALUES)); if (isEnumSpecialMethod) { - this.scope.problemReporter().duplicateEnumSpecialMethod(this, method2Decl); + this.scope.problemReporter().duplicateEnumSpecialMethod(this, methodToBlame); } else { - this.scope.problemReporter().duplicateMethodInType(this, method2Decl, method.areParametersEqual(method2)); + this.scope.problemReporter().duplicateMethodInType(this, methodToBlame, method.areParametersEqual(method2)); } - method2Decl.binding = null; + methodToBlame.binding = null; // do not alter original method array until resolution is over, due to reentrance (143259) if (resolvedMethods == this.methods) System.arraycopy(this.methods, 0, resolvedMethods = new MethodBinding[length], 0, length); #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java,v retrieving revision 1.131 diff -u -r1.131 EnumTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java 17 Oct 2008 18:07:27 -0000 1.131 +++ src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java 21 Oct 2008 12:24:42 -0000 @@ -5683,4 +5683,21 @@ }, ""); } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239225 - variation +public void test164() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public enum X {\n" + + " ;\n" + + " private X valueOf(String arg0) { return null; }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " private X valueOf(String arg0) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The enum X already defines the method valueOf(String) implicitly\n" + + "----------\n"); +} }