[kaffe] difference between kaffe and Sun's JDK: IllegalAccessException
Rob Gonzalez
rgonzale at wso.williams.edu
Mon Apr 19 09:49:12 PDT 2004
Hi Ito,
I don't know if you've tried this, but if you add this method to A1 it
works fine. It is the same method as it exists in B, only when it is
compiled all static references to it are set to A1.getFoo() instead of
B.getFoo(), where "this" definitely refers to an A1).
public void execFoo() throws Exception {
getFoo().invoke(this, null);
}
So my guess is that it's a bug in Sun's VM which is not appropriately
using "this" in type checking at runtime...that is, in invoking the method
getFoo() from within A1 it uses the type "B" which is statically bound to
"this" in the bytecode instead of checking out the object's dynamic type.
Rob
On Mon, 19 Apr 2004, Ito Kazumitsu wrote:
> Hi,
>
> The attached program,
>
> - when run with Sun's JDK (java version "1.4.2_04"), throws
> java.lang.IllegalAccessException.
> - when run with Kaffe, ends normally.
>
> Is this Sun's bug incorrectly checking the accessibility,
> or Kaffe's bug neglecting a necessary accessibility checking?
> I would like to think this is Sun's bug.
>
> bash$ cat a/A.java
> package a;
> import java.lang.reflect.Method;
>
> public class A {
> public static void main(String[] args) throws Exception {
> new A();
> }
>
> public A() throws Exception {
> new A1();
> }
>
> private class A1 extends b.B {
>
> A1() throws Exception {
> execFoo();
> }
>
> public Method getFoo() {
> try {
> return A1.class.getMethod("foo", null);
> }
> catch (NoSuchMethodException e) {
> return null;
> }
> }
>
> public void foo() {
> System.out.println("foo");
> }
> }
>
> }
> bash$ cat b/B.java
> package b;
> import java.lang.reflect.Method;
>
> public abstract class B {
> public abstract Method getFoo();
> public void execFoo() throws Exception {
> getFoo().invoke(this, null);
> }
> }
> bash$ java a.A
> java.lang.IllegalAccessException: Class b.B can not access a member of class a.A$A1 with modifiers "public"
> at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:57)
> at java.lang.reflect.Method.invoke(Method.java:317)
> at b.B.execFoo(B.java:7)
> at a.A$A1.<init>(A.java:16)
> at a.A.<init>(A.java:10)
> at a.A.main(A.java:6)
> Exception in thread "main" bash$
> bash$ kaffe a.A
> foo
>
> _______________________________________________
> kaffe mailing list
> kaffe at kaffe.org
> http://kaffe.org/cgi-bin/mailman/listinfo/kaffe
>
More information about the kaffe
mailing list