Henri Tremblay henri.tremblay at
Fri Jun 9 02:19:21 UTC 2017

It's for Objenesis. Which is used to instantiate classes without calling a
constructor. One of the instantiator is the MagicInstantiator. It's not
used by default but some people are using it.

The code is here:

Basically, I'm creating an instantiator extending MagicAccessorImpl. This
class has one method calling Object default constructor to instantiate
another class.

This used to work in Java 8 but I'm not allowed anymore to extend a package
private class (yes, yes, I know, that make sense).

On 8 June 2017 at 11:55, Alan Bateman <Alan.Bateman at> wrote:

> On 08/06/2017 16:16, Henri Tremblay wrote:
>> 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
> jdk.internal.reflect.MagicAccessorImpl is package private and it looks
> like you are trying to create the sub-type in a different package (and a
> different class loader). There are CLI options for patching java.base at
> both compile-time and run-time. If java.base/jdk.internal.reflect is opened
> then it's possible to inject classes into that package at run-time too.
> Maybe it better if you could start by explaining why you are trying to do,
> maybe there is a way to steer you away from hacking the classes in
> jdk.internal.reflect.
> -Alan

More information about the jdk9-dev mailing list