MagicAccessorImpl

Henri Tremblay henri.tremblay at gmail.com
Thu Jun 8 15:16:34 UTC 2017


Hi,

As usual I'm doing evil things and I need your help.

I'm trying to use MagicAccessorImpl in Java 9 (jigsaw). So I am not using
jdk.internal.reflect.MagicAccessorImpl.

So I'm generating a class extending MagicAccessorImpl. And I'm getting the
following exception:

Caused by: java.lang.IllegalAccessError: class org.objenesis.instantiator.
sun.MagicInstantiator$$$EmptyClass loaded by
jdk/internal/loader/ClassLoaders$AppClassLoader
cannot access jdk/internal/reflect superclass jdk.internal.reflect.
MagicAccessorImpl

org.objenesis.instantiator.sun.MagicInstantiator$$$EmptyClass is the name
of the generated class.

Is there a way to make it work? Ideally through code or if it's impossible
through parameters.

I already tried -Xverify:none --add-opens java.base/jdk.internal.
reflect=ALL-UNNAMED

The defineClass is the following (I did also ClassLoader.defineClass):

PROTECTION_DOMAIN = AccessController.doPrivileged(new
PrivilegedAction<ProtectionDomain>() {
   public ProtectionDomain run() {
      return ClassDefinitionUtils.class.getProtectionDomain();
   }
});

Class<T> c = (Class<T>) UnsafeUtil.getUnsafe().defineClass(className,
b, 0, b.length, loader, PROTECTION_DOMAIN);

Thanks,

Henri


More information about the jdk9-dev mailing list