8205533: Class.getPackage() fails with InternalError if class is defined to the bootstrap class loader but module is not in the boot layer

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

8205533: Class.getPackage() fails with InternalError if class is defined to the bootstrap class loader but module is not in the boot layer

Alan Bateman
This is a corner case that showed up while chasing an issue in another area.

If a tool uses the attach mechanism to start the JMX agent in a running
VM that doesn't have the jdk.management.agent module in the boot layer
then the module is resolved and defined to the VM in its own module
layer.  This results in Java SE and JDK specific modules, such as
java.management and jdk.management.agent, being loaded and mapped to the
bootstrap class loader but the modules aren't in the boot layer.

In this scenario, using Class::getPackage to get the legacy Package
object of a class in one of these modules trips up with an
InternalError. This is because the implementation assumes that modules
defined to the bootstrap class loader are in boot layer. To fix this,
the code that creates Package objects for the packages in modules mapped
to the bootstrap class loader needs to use the stack of layers that
supports the dynamic loading of the JMX and java agents.

The webrev with the proposed changes, and test, is here:
   http://cr.openjdk.java.net/~alanb/8205533/webrev/index.html

-Alan.
Reply | Threaded
Open this post in threaded view
|

Re: 8205533: Class.getPackage() fails with InternalError if class is defined to the bootstrap class loader but module is not in the boot layer

Mandy Chung
On 6/24/18 7:32 AM, Alan Bateman wrote:

> This is a corner case that showed up while chasing an issue in another
> area.
>
> If a tool uses the attach mechanism to start the JMX agent in a running
> VM that doesn't have the jdk.management.agent module in the boot layer
> then the module is resolved and defined to the VM in its own module
> layer.  This results in Java SE and JDK specific modules, such as
> java.management and jdk.management.agent, being loaded and mapped to the
> bootstrap class loader but the modules aren't in the boot layer.
>
> In this scenario, using Class::getPackage to get the legacy Package
> object of a class in one of these modules trips up with an
> InternalError. This is because the implementation assumes that modules
> defined to the bootstrap class loader are in boot layer. To fix this,
> the code that creates Package objects for the packages in modules mapped
> to the bootstrap class loader needs to use the stack of layers that
> supports the dynamic loading of the JMX and java agents.
>
> The webrev with the proposed changes, and test, is here:
>    http://cr.openjdk.java.net/~alanb/8205533/webrev/index.html

Looks good.

Mandy