Bug 21447 - Wrong method invoked at runtime
Summary: Wrong method invoked at runtime
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P2 normal (vote)
Target Milestone: 2.0.1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 21482 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-07-10 11:48 EDT by Philipe Mulet CLA
Modified: 2002-09-20 09:13 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Philipe Mulet CLA 2002-07-10 11:48:05 EDT
Build R2.0

On the following test case, the protected inner emulation seems incorrect since 
it leads to the wrong method invocation at runtime:

pa/X.java------------------
package pa;

public class X {
  protected void foo(){
    System.out.println("X.foo()");
  }
}

pb/T.java------------------
package pb;
import pa.X;

public class T extends X {
  public void bar(){
    new Object(){
      void do1(){
        T.this.foo();
      }
    }.do1();
  }
}

pb/Y.java------------------
package pb;
import pa.X;

public class Y extends T {

  public static void main(String[] args) {
    new Y().bar();
  }
	
  protected void foo(){
    System.out.println("Y.foo()");
  }
}

When running pb.Y, it should display "Y.foo()", but does display "X.foo()" 
instead. Same code compiled with javac 1.4.1 does display "Y.foo()" as expected.
Comment 1 Philipe Mulet CLA 2002-07-11 09:44:27 EDT
Problem is that the synthetic accessor for a method incorrectly diagnose a 
super method access (based on the fact the current class and the target method 
aren't part of the same class - this was true only for private access 
emulation, but not once protected jumped in).

Need to pass the information along, and generate separate access methods 
depending on whether the accessed method is used normally or with a super 
access so that the invocation bytecode is the right one.

Fixed in latest. 
Comment 2 Philipe Mulet CLA 2002-07-11 09:46:35 EDT
*** Bug 21482 has been marked as a duplicate of this bug. ***
Comment 3 David Audel CLA 2002-08-19 11:53:38 EDT
Verified.
Comment 4 Jerome Lanneluc CLA 2002-08-19 12:32:20 EDT
Verified
Comment 5 David Audel CLA 2002-09-20 09:13:56 EDT
Verified in 2.1 M1