[Kaffe] ease of use patch.

Alexandre Oliva oliva at dcc.unicamp.br
Wed Feb 24 12:59:14 PST 1999


On Feb 24, 1999, Archie Cobbs <archie at whistle.com> wrote:

> Alexandre Oliva writes:
>> > Could you elaborate on this, eg, with an example? I don't see
>> > what you're talking about.
>> 
>> It's not that private variables are ``promoted'' to package-protected
>> ones; package-protected accessor methods are may be created to grant
>> access to private variables of a class to its inner classes.
>> 
>> class foo { private int bar; class baz { int foobar() { return bar; }}}
>> 
>> there will be an accessor bar$something() that baz.foobar() will call
>> to obtain the value of foo.bar.

> That's not the way I think about it. Rather, every inner class
> is given two things: (1) an implicit object reference to its
> enclosing class, and (2) the same access as the enclosing class.

That's the point.  In order to keep access control in the JVM
unchanged, the compiler must arrange that class foo$baz can get to
foo.bar, and so it would either provide package access to foo.bar in
the bytecode level, that would allow for unwanted reflection access,
or access through an accessor method, that might still be abused with
hand-crafted classfiles, but Reflection can still properly check for
permissions, and so can an improved verifier.

> So "return bar" really does this:

>   return specialImplicitReferenceToFoo.bar;

> There is no bar$something() method created as far as I know.

Run javap and you'll be surprised.

-- 
Alexandre Oliva http://www.dcc.unicamp.br/~oliva aoliva@{acm.org,computer.org}
oliva@{dcc.unicamp.br,gnu.org,egcs.cygnus.com,samba.org}
Instituto de Computação, Universidade Estadual de Campinas, SP, Brasil



More information about the kaffe mailing list