### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java,v retrieving revision 1.169 diff -u -r1.169 MethodVerifyTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java 6 Nov 2008 17:22:26 -0000 1.169 +++ src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java 12 Nov 2008 19:49:27 -0000 +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=255035 +public void test182() { + this.runNegativeTest( + new String[] { + "X.java", + "class S {\n" + + " String foo() { return null; }\n" + + "}\n" + + "class X extends S {\n" + + " foo() { return null; }\n" + + " @Override String foo() { return null; }\n" + // should keep this definition + " Number foo() { return null; }\n" + + " void test() { foo(); }\n" + // no secondary error + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " foo() { return null; }\n" + + " ^^^^^\n" + + "Return type for the method is missing\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " foo() { return null; }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " @Override String foo() { return null; }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " Number foo() { return null; }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type X\n" + + "----------\n" + ); +} } #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.169 diff -u -r1.169 SourceTypeBinding.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java 6 Nov 2008 10:15:30 -0000 1.169 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java 12 Nov 2008 19:49:28 -0000 @@ -1165,38 +1165,48 @@ } boolean isEnumSpecialMethod = isEnum() && (CharOperation.equals(selector,TypeConstants.VALUEOF) || CharOperation.equals(selector,TypeConstants.VALUES)); // report duplicate + boolean removeMethod2 = true; if (methodDecl == null) { methodDecl = method.sourceMethod(); // cannot be retrieved after binding is lost & may still be null if method is special if (methodDecl != null && methodDecl.binding != null) { // ensure its a valid user defined method + boolean removeMethod = method.returnType == null && method2.returnType != null; if (isEnumSpecialMethod) { this.scope.problemReporter().duplicateEnumSpecialMethod(this, methodDecl); // remove user defined methods & keep the synthetic + removeMethod = true; + } else { + this.scope.problemReporter().duplicateMethodInType(this, methodDecl, method.areParametersEqual(method2)); + } + if (removeMethod) { + removeMethod2 = false; 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)); } } } AbstractMethodDeclaration method2Decl = method2.sourceMethod(); if (method2Decl != null && method2Decl.binding != null) { // ensure its a valid user defined method - if (isEnumSpecialMethod) + if (isEnumSpecialMethod) { this.scope.problemReporter().duplicateEnumSpecialMethod(this, method2Decl); - else + removeMethod2 = true; + } else { this.scope.problemReporter().duplicateMethodInType(this, method2Decl, method.areParametersEqual(method2)); - method2Decl.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[j] = null; - failed++; + } + if (removeMethod2) { + method2Decl.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[j] = null; + failed++; + } } } - if (method.returnType == null && methodDecl == null) { // forget method with invalid return type... was kept to detect possible collisions + if (method.returnType == null && resolvedMethods[i] != null) { // forget method with invalid return type... was kept to detect possible collisions methodDecl = method.sourceMethod(); if (methodDecl != null) methodDecl.binding = null;