Bug 136543

Summary: [1.5][compiler] Eclipse gives a "name clash" error while javac accepts the code
Product: [Eclipse Project] JDT Reporter: Zorzella Mising name <zorzella>
Component: CoreAssignee: Kent Johnson <kent_johnson>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P3    
Version: 3.2   
Target Milestone: 3.2 RC2   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Zorzella Mising name CLA 2006-04-13 01:46:54 EDT
The code below gives forth this compilation error, but javac is OK with it:

clash: The method error(Collection<String>) of type Parent.Child has the same erasure as error(Collection) of type Parent but does not override it

*********** Parent.java *************

import java.util.Collection;

public class Parent {
    public static void error (Collection c){
    }
	
    public static class Child extends Parent {
        public static void error(Collection<String> c) {
        }
    }
}
Comment 1 Zorzella Mising name CLA 2006-04-13 02:39:27 EDT
I don't know if it's the same root, but an error also happens when using @Override with static methods. This code has both conditions:


import java.util.Collection;

public class Parent {
    public static void error (Collection c){}
    public static void error2 () {}

    public static class Child extends Parent {
        public static void error(Collection<String> c) {}
        @Override public static void error2() {}
    }
}
Comment 2 Philipe Mulet CLA 2006-04-13 08:43:24 EDT
Reproduced first problem in latest.

Second issue is expected behavior. Static methods are not overriding.
Javac1.6 says:
X.java:9: method does not override a method from its superclass
        @Override public static void error2() {}
        ^
1 error
Comment 3 Kent Johnson CLA 2006-04-13 12:09:36 EDT
We should not detect name clashes between inherited static methods.

The following case shows that the instance methods do cause a name clash:

import java.util.Collection;

class Parent {
	static void staticCase1(Collection c) {}
	static void staticCase2(Collection<String> c) {}

	void instanceCase1(Collection c) {}
	void instanceCase2(Collection<String> c) {}
}

class Child extends Parent {
	static void staticCase1(Collection<String> c) {}
	static void staticCase2(Collection c) {}

	// @Override is an error for instanceCase1
	// name clash: instanceCase1(Collection<String>) in Child and
	// instanceCase1(Collection) in Parent have the same erasure, yet
	// neither overrides the other
	void instanceCase1(Collection<String> c) {}
	@Override void instanceCase2(Collection c) {}
}

case2 is allowed for compatibility reasons, but case1 is a name clash.
Comment 4 Kent Johnson CLA 2006-04-17 15:40:18 EDT
Added MethodVerifyTest 85
Comment 5 Olivier Thomann CLA 2006-04-28 14:24:11 EDT
Verified with I20060427-1600 for 3.2RC2