[kaffe] KJC bug report: inner class cannot find the enclosing class's method

Guilhem Lavaux guilhem at kaffe.org
Wed Aug 13 06:03:02 PDT 2003


Ito Kazumitsu wrote:

>Hi,
>
>I think this is a bug of KJC.
>
>While trying to build the CVS verion of HSQLDB
>(http://hsqldb.sourceforge.net/), I found some
>code which kjc cannot compile while both Sun's javac
>and gcj can.
>
>Simplified programs to show this bug are as follows.
>
>bash$ cat a/A.java
>package a;
>public class A {
>  protected void foo() {
>    System.out.println("This is foo.");
>  }
>}
>bash$ cat b/B.java
>package b;
>import a.A;
>public class B extends A {
>  public static void main(String[] args) {
>    (new B()).go();
>  }
>  private void go() {
>    (new B1()).bar();
>  }
>  class B1 {
>    private void bar() {
>      B.this.foo();
>    }
>  }
>}
>bash$ CLASSPATH=kjc.jar java at.dms.kjc.Main a/A.java b/B.java 
>b\B.java:12: error:Cannot find method "b.B.foo()"
>bash$ javac a/A.java b/B.java 
>bash$ java b.B
>This is foo.
>bash$ 
>
I have found where the bug lies ! In CMethod, the test for accessibility 
forget to check whether the calling
context is nested into an authorized class. I have attached the real 
simple patch with this mail.

Cheers,
Guilhem.
-------------- next part --------------
--- src/kjc/CMethod.java	2002-07-15 20:53:32.000000000 +0200
+++ ../kopi-2.1B.new/src/kjc/CMethod.java	2003-08-13 15:04:01.000000000 +0200
@@ -89,7 +89,7 @@
         if (primary.isArrayType() && getIdent() == Constants.JAV_CLONE && getParameters().length == 0) {
           return true;
         } else {
-          if (from.isAnonymous() && primary.getCClass().descendsFrom(from.getOwner())) {
+          if ((from.isNested() || from.isAnonymous()) && primary.getCClass().descendsFrom(from.getOwner())) {
             return true;
           }
           return primary.getCClass().descendsFrom(from);


More information about the kaffe mailing list