Bug 132831

Summary: [1.5][compiler] Compiler generate brige when not needed
Product: [Eclipse Project] JDT Reporter: Rémi Forax <forax>
Component: CoreAssignee: Kent Johnson <kent_johnson>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.2   
Target Milestone: 3.2 RC1   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Rémi Forax CLA 2006-03-22 09:01:30 EST
The following code compiles with javac not with eclipse.
Eclipse compiler generate a bridge method that
generates an IllegalAccessError at runtime.

----------------------------------------
package fr.umlv.bridgebug;
abstract class A implements I{
  public A m() {
    return null;
  }
}
---------------------------------------
package fr.umlv.bridgebug;
public abstract class B extends A {
}
---------------------------------------
package fr.umlv.bridgebug;
public interface I {
  I m();
}
-------------------------------------
package fr.umlv.bridgebug.test;

import fr.umlv.bridgebug.B;
import fr.umlv.bridgebug.I;

public class C extends B {
    public static boolean test(I i) {
      return i.m()==null;
    }
    
    public static void main(String[] args) {
      I i=new C();
     System.out.println(test(i));
    }

}

the exception at runtime :

Exception in thread "main" java.lang.IllegalAccessError: tried to access class fr.umlv.bridgebug.A from class fr.umlv.bridgebug.test.C
	at fr.umlv.bridgebug.test.C.m(C.java:1)
	at fr.umlv.bridgebug.test.C.test(C.java:8)
	at fr.umlv.bridgebug.test.C.main(C.java:13)

Using javap, eclipse generated a bridge method m() in C ??
and the bridge method in B has I as return type I and not A.

Rémi Forax
Comment 1 Kent Johnson CLA 2006-04-04 11:51:25 EDT
Added MethodVerifyTest 83

We were mistakenly adding a bridge method to C because its superclasses are abstract.
Comment 2 David Audel CLA 2006-04-14 04:58:48 EDT
Verified for 3.2RC1 with build I20060413-1718