Discussion:
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
2018-06-24 14:32:56 UTC
Permalink
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.
mandy chung
2018-06-24 14:40:24 UTC
Permalink
Post by 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.
  http://cr.openjdk.java.net/~alanb/8205533/webrev/index.html
Looks good.

Mandy

Loading...