-
Enhancement
-
Resolution: Unresolved
-
P4
-
7
-
Fix Understood
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b77)
Java HotSpot(TM) Client VM (build 17.0-b05, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
If you create a base class with a static method, and then create a subclass with a generic static method that has the same name, the compiler fails. It thinks that the two methods have the same erasure but neither overrides the other; this doesn't make any sense because a static method can't override another static method. It also reports that a reference to that method is ambiguous, even when the method reference is qualified with an explicit class name.
Note that the problem only occurs when the static method in the subclass is generic. If you remove the generic type parameter from the sample code included below then it compiles correctly.
This appears to be a regression defect as it worked with javac 1.6.0_17 (it also works with the Eclipse 3.5.1 internal java compiler).
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the sample code with javac build 1.7.0-ea-b77.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expected the compilation to succeed.
ACTUAL -
The compilation failed with the error message shown below.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
J:\>javac.exe Test.java
Test.java:8: name clash: <T>foo() in Sub and foo() in Base have the same erasure, yet neither overrides the other
static <T> void foo() {
^
where T is a type-variable:
T extends Object declared in method <T>foo()
Test.java:16: reference to foo is ambiguous, both method foo() in Base and method <T>foo() in Sub match
Sub.<Object>foo();
^
where T is a type-variable:
T extends Object declared in method <T>foo()
2 errors
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
class Base {
static void foo() {
System.out.println("Base");
}
}
class Sub extends Base {
static <T> void foo() {
System.out.println("Sub");
}
}
public class Test {
public static void main(final String[] args) {
Base.foo();
Sub.<Object>foo();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Change the name of one of the static methods.
Release Regression From : 6u17
The above release value was the last known release where this
bug was not reproducible. Since then there has been a regression.
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b77)
Java HotSpot(TM) Client VM (build 17.0-b05, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
If you create a base class with a static method, and then create a subclass with a generic static method that has the same name, the compiler fails. It thinks that the two methods have the same erasure but neither overrides the other; this doesn't make any sense because a static method can't override another static method. It also reports that a reference to that method is ambiguous, even when the method reference is qualified with an explicit class name.
Note that the problem only occurs when the static method in the subclass is generic. If you remove the generic type parameter from the sample code included below then it compiles correctly.
This appears to be a regression defect as it worked with javac 1.6.0_17 (it also works with the Eclipse 3.5.1 internal java compiler).
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the sample code with javac build 1.7.0-ea-b77.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expected the compilation to succeed.
ACTUAL -
The compilation failed with the error message shown below.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
J:\>javac.exe Test.java
Test.java:8: name clash: <T>foo() in Sub and foo() in Base have the same erasure, yet neither overrides the other
static <T> void foo() {
^
where T is a type-variable:
T extends Object declared in method <T>foo()
Test.java:16: reference to foo is ambiguous, both method foo() in Base and method <T>foo() in Sub match
Sub.<Object>foo();
^
where T is a type-variable:
T extends Object declared in method <T>foo()
2 errors
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
class Base {
static void foo() {
System.out.println("Base");
}
}
class Sub extends Base {
static <T> void foo() {
System.out.println("Sub");
}
}
public class Test {
public static void main(final String[] args) {
Base.foo();
Sub.<Object>foo();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Change the name of one of the static methods.
Release Regression From : 6u17
The above release value was the last known release where this
bug was not reproducible. Since then there has been a regression.
- relates to
-
JDK-5009937 hiding versus generics versus binary compatibility
- Closed
-
JDK-7022054 Invalid compiler error on covariant overriding methods with the same erasure
- Closed
-
JDK-7023317 The compiler allows a class with multiple methods the same signature.
- Closed