JDK-6248405 : Calling final generics method via interface causes AbstractMethodError
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2005-03-30
  • Updated: 2010-04-02
  • Resolved: 2005-03-31
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
Since bug #5021445 was fixed, javac generates the expected bridging methods except when the inherited generic method is final, in which case no bridging method is created but the class is compiled and not rejected.

While I'd not expect javac to create a bridge method for a final generic method, I would expect javac to reject the source when this is the case, as the absent bridge method causes AbstractMethodError to be thrown at runtime.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
javac *.java
java -classpath . TestObject

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
compiler should refuse to compile TestObject as the synthic bridging method for foo(String obj) cannot be generated as foo(T obj) is final
ACTUAL -
Code compiles without error causing an AbstractMethodError to be thrown.



ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.AbstractMethodError: TestObject.foo(Ljava/lang/String;)V
        at TestObject.main(TestObject.java:8)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class GenObject<T>
{
        public final void foo(T obj)
        {
                System.out.println("obj = "+obj);
        }
}
public interface TestInterface
{
        void foo(String blah);
}
public class TestObject extends GenObject<String> implements TestInterface
{
        public static void main(String[] args)
        {
                TestObject test = new TestObject();
                TestInterface test2 = test;

                // works
                test.foo("blah");

                // fails with AbstractMethodError
                test2.foo("blah");
        }
}
---------- END SOURCE ----------
###@###.### 2005-03-30 23:58:46 GMT

Comments
EVALUATION This is indeed a dupe of 6245699. Good idea for an additional testcase. ###@###.### 2005-03-31 21:40:27 GMT
31-03-2005