Aladdin - Scala Bugtracking
[#455] project: compiler priority: low category: bug
submitter assigned to status date submitted
Iulian Iulian fixed 2005-09-21 16:21:11.0
subject IllegalAccessError on (some) method calls to Java inherited methods
code
// A.java
package pA;

// package-level visibility
abstract class A {
    public void doSomething() { System.out.println("A"); }
}

// B.java
package pA;

public class B extends A {
}

// bug.scala
package pB;

import pA._;

object Main with Application {
  val b = new B;
  b.doSomething();
}

what happened

Exception in thread "main" java.lang.IllegalAccessError: tried to access class pA.A from class pB.Main$
        at pB.Main$.(bug.scala:5)
        at pB.Main$.(bug.scala)
        at pB.Main.main(bug.scala:45)

what expected The problem is that the code generator outputs code that references the 'owner' of the 'doSomething' method, which is class A. However, class 'A' lives in a different package and is not visible to object 'Main'. The code should reference the class of the receiver, in this case 'B' (which inherits the method, but does not 'own' it). This problem is difficult to reproduce, as the JVM seems to behave differently if the java classfiles (A and B) are packaged in a jar (if not, it runs without problems).
[back to overview]
Changes of this bug report
Iulian  edited on  2006-08-22 15:41:15.0