### 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 13:39:56 -0000 @@ -1101,7 +1101,7 @@ if (method == null) continue; char[] selector = method.selector; - AbstractMethodDeclaration methodDecl = null; + boolean complainedAlready = false; nextSibling: for (int j = i + 1; j < length; j++) { MethodBinding method2 = resolvedMethods[j]; if (method2 == null) @@ -1163,9 +1163,25 @@ } 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 methodDecl = method.sourceMethod(); AbstractMethodDeclaration method2Decl = method2.sourceMethod(); + boolean isEnumSpecialMethod = isEnum() && (CharOperation.equals(selector,TypeConstants.VALUEOF) || CharOperation.equals(selector,TypeConstants.VALUES)); + if (methodDecl != null && !complainedAlready) { + if (isEnumSpecialMethod) { + this.scope.problemReporter().duplicateEnumSpecialMethod(this, methodDecl); + methodDecl.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); + resolvedMethods[i] = null; + failed++; + + } else { + this.scope.problemReporter().duplicateMethodInType(this, methodDecl, method.areParametersEqual(method2)); + } + complainedAlready = true; + } if (method2Decl != null && method2Decl.binding != null) { // ensure its a valid user defined method if (isEnumSpecialMethod) { this.scope.problemReporter().duplicateEnumSpecialMethod(this, method2Decl); @@ -1180,10 +1196,11 @@ failed++; } } - if (method.returnType == null && methodDecl == null) { // forget method with invalid return type... was kept to detect possible collisions - methodDecl = method.sourceMethod(); - if (methodDecl != null) + if (method.returnType == null) { // forget method with invalid return type... was kept to detect possible collisions + AbstractMethodDeclaration methodDecl = method.sourceMethod(); + if (methodDecl != null) { methodDecl.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 13:39:57 -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"); +} }