mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8205533: Class.getPackage() fails with InternalError if class is defined to the bootstrap class loader but module is not in the boot layer
Reviewed-by: mchung
This commit is contained in:
parent
d705440d39
commit
24b5afda01
3 changed files with 82 additions and 9 deletions
|
@ -44,6 +44,7 @@ import java.util.stream.Stream;
|
|||
|
||||
import jdk.internal.misc.JavaLangAccess;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
import jdk.internal.module.Modules;
|
||||
import jdk.internal.module.ServicesCatalog;
|
||||
|
||||
/**
|
||||
|
@ -249,15 +250,16 @@ public class BootLoader {
|
|||
}
|
||||
}
|
||||
|
||||
// return the Module object for the module name. The Module may
|
||||
// in the boot layer or a child layer for the case that the module
|
||||
// is loaded into a running VM
|
||||
if (mn != null) {
|
||||
// named module from runtime image or exploded module
|
||||
Optional<Module> om = ModuleLayer.boot().findModule(mn);
|
||||
if (!om.isPresent())
|
||||
throw new InternalError(mn + " not in boot layer");
|
||||
return om.get();
|
||||
String name = mn;
|
||||
return Modules.findLoadedModule(mn)
|
||||
.orElseThrow(() -> new InternalError(name + " not loaded"));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -35,6 +35,7 @@ import java.security.AccessController;
|
|||
import java.security.PrivilegedAction;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -249,7 +250,19 @@ public class Modules {
|
|||
|
||||
}
|
||||
|
||||
// the top-most system layer
|
||||
private static ModuleLayer topLayer;
|
||||
/**
|
||||
* Finds the module with the given name in the boot layer or any child
|
||||
* layers created to load the "java.instrument" or "jdk.management.agent"
|
||||
* modules into a running VM.
|
||||
*/
|
||||
public static Optional<Module> findLoadedModule(String name) {
|
||||
ModuleLayer top = topLayer;
|
||||
if (top == null)
|
||||
top = ModuleLayer.boot();
|
||||
return top.findModule(name);
|
||||
}
|
||||
|
||||
// the top-most layer
|
||||
private static volatile ModuleLayer topLayer;
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue