RFR 8058575: IllegalAccessError trying to access package-private class from VM anonymous class

Coleen Phillimore coleen.phillimore at oracle.com
Fri Aug 12 18:47:21 UTC 2016


*+ const Klass* host_klass;*
*+ if (_host_klass->is_objArray_klass()) {*
*+ host_klass = ObjArrayKlass::cast(_host_klass)->element_klass();*
*+ } else {*
*+ host_klass = _host_klass;*
*+ }*
*+ assert(host_klass->is_instance_klass(), "host klass is not an 
instance class");*

Can host_class really be an array class or is this code trying to be 
defensive since host_class is Klass* and not InstanceKlass?  If it can 
be an objArray class,then I think you want bottom_klass() not 
element_klass(),  but if it can also be a typeArrayKlass, or [[I 
objArrayKlass, then you don't have any sort of InstanceKlass.   It seems 
like the check for what sort of Klass host_class can be should be 
further up the stack and the more specific type passed here.  I don't 
see such a check though.  This doesn't seem right.

Apart from this, everything else looks great.  I even reviewed your test.


On 8/3/16 8:15 AM, harold seigel wrote:
> Hi,
> Please review this fix for bug 8058575.  The fix prevents a class 
> created using Unsafe.defineAnonymousClass() from being in a different 
> package than its host class.  Being in different packages would create 
> access problems if the packages were in different modules.
> With this fix, If the anonymous class is in a different package then 
> the JVM will throw IllegalArgumentException.  If the anonymous class 
> is in the unnamed package then the JVM will move the anonymous class 
> into its host class's package.
> JBS Bug: https://bugs.openjdk.java.net/browse/JDK-8058575
> Open webrevs:
>    http://cr.openjdk.java.net/~hseigel/bug_8058575.hs/
>    http://cr.openjdk.java.net/~hseigel/bug_8058575.jdk/
> The fix was tested with the JCK Lang and VM tests, the hotpot, and 
> java/lang, java/util and other JTreg tests, the NSK quick tests, and 
> with the RBT runtime nightly tests.
> Thanks, Harold

More information about the hotspot-runtime-dev mailing list