java/1386: private method overloading when inner class extends its enclosing class

bryce@albatross.co.nz bryce@albatross.co.nz
Wed Dec 20 12:25:00 GMT 2000


>Number:         1386
>Category:       java
>Synopsis:       private method overloading when inner class extends its enclosing class
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    apbianco
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Dec 20 12:19:30 PST 2000
>Closed-Date:    
>Last-Modified:  
>Originator:     Bryce McKinlay
>Release:        gcc version 2.97 20001015 (experimental)
>Organization:
>Environment:
*
>Description:
If an inner class extends its enclosing class and
"overloads" a private method declared in the enclosing class,
which method gets called?

In class files compiled with javac, it depends on the 
declared type of the variable (see test code below):

$ java InnerPvt
InnerPvt
A
A
InnerPvt
A
InnerPvt
InnerPvt

With gcj however, the outer method is always called from 
the outer class (but calls from the inner class behave
correctly):

$ ./ip
InnerPvt
InnerPvt
InnerPvt
InnerPvt
A
InnerPvt
InnerPvt
>How-To-Repeat:
class InnerPvt
{
  private void a()
  {
    System.out.println ("InnerPvt");
  }

  public static void main(String[] args)
  {
    InnerPvt ip = new InnerPvt().new A();
    ip.a();
    InnerPvt.A ipa = new InnerPvt().new A();
    ipa.a();
    ipa = (InnerPvt.A) ip;
    ipa.a();    
    ip = ipa;
    ip.a();
    ipa.b();    
  }

  class A extends InnerPvt
  {
    private void a()
    {
      System.out.println ("A");    
    }
    
    void b()
    {      
      this.a();
      InnerPvt ip = this;
      ip.a();
      InnerPvt.this.a();
    }
  }
}
>Fix:

>Release-Note:
>Audit-Trail:

Formerly PR gcj/358

>Unformatted:



More information about the Gcc-prs mailing list