mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8191867: Module attribute in 54.0+ class file cannot contains a requires java.base with ACC_TRANSITIVE or ACC_STATIC_PHASE
Reviewed-by: psandoz, mchung
This commit is contained in:
parent
e2d38d5f6a
commit
800f9ab58a
3 changed files with 128 additions and 6 deletions
|
@ -63,6 +63,9 @@ import static jdk.internal.module.ClassFileConstants.*;
|
|||
|
||||
public final class ModuleInfo {
|
||||
|
||||
private final int JAVA_MIN_SUPPORTED_VERSION = 53;
|
||||
private final int JAVA_MAX_SUPPORTED_VERSION = 54;
|
||||
|
||||
private static final JavaLangModuleAccess JLMA
|
||||
= SharedSecrets.getJavaLangModuleAccess();
|
||||
|
||||
|
@ -188,8 +191,10 @@ public final class ModuleInfo {
|
|||
|
||||
int minor_version = in.readUnsignedShort();
|
||||
int major_version = in.readUnsignedShort();
|
||||
if (major_version < 53) {
|
||||
throw invalidModuleDescriptor("Must be >= 53.0");
|
||||
if (major_version < JAVA_MIN_SUPPORTED_VERSION ||
|
||||
major_version > JAVA_MAX_SUPPORTED_VERSION) {
|
||||
throw invalidModuleDescriptor("Unsupported major.minor version "
|
||||
+ major_version + "." + minor_version);
|
||||
}
|
||||
|
||||
ConstantPool cpool = new ConstantPool(in);
|
||||
|
@ -245,7 +250,7 @@ public final class ModuleInfo {
|
|||
switch (attribute_name) {
|
||||
|
||||
case MODULE :
|
||||
builder = readModuleAttribute(in, cpool);
|
||||
builder = readModuleAttribute(in, cpool, major_version);
|
||||
break;
|
||||
|
||||
case MODULE_PACKAGES :
|
||||
|
@ -334,7 +339,7 @@ public final class ModuleInfo {
|
|||
* Reads the Module attribute, returning the ModuleDescriptor.Builder to
|
||||
* build the corresponding ModuleDescriptor.
|
||||
*/
|
||||
private Builder readModuleAttribute(DataInput in, ConstantPool cpool)
|
||||
private Builder readModuleAttribute(DataInput in, ConstantPool cpool, int major)
|
||||
throws IOException
|
||||
{
|
||||
// module_name
|
||||
|
@ -390,8 +395,21 @@ public final class ModuleInfo {
|
|||
JLMA.requires(builder, mods, dn, vs);
|
||||
}
|
||||
|
||||
if (dn.equals("java.base"))
|
||||
if (dn.equals("java.base")) {
|
||||
if (major >= 54
|
||||
&& (mods.contains(Requires.Modifier.TRANSITIVE)
|
||||
|| mods.contains(Requires.Modifier.STATIC))) {
|
||||
String flagName;
|
||||
if (mods.contains(Requires.Modifier.TRANSITIVE)) {
|
||||
flagName = "ACC_TRANSITIVE";
|
||||
} else {
|
||||
flagName = "ACC_STATIC_PHASE";
|
||||
}
|
||||
throw invalidModuleDescriptor("The requires entry for java.base"
|
||||
+ " has " + flagName + " set");
|
||||
}
|
||||
requiresJavaBase = true;
|
||||
}
|
||||
}
|
||||
if (mn.equals("java.base")) {
|
||||
if (requires_count > 0) {
|
||||
|
|
|
@ -80,7 +80,7 @@ public final class ModuleInfoWriter {
|
|||
*/
|
||||
private static byte[] toModuleInfo(ModuleDescriptor md, ModuleTarget target) {
|
||||
ClassWriter cw = new ClassWriter(0);
|
||||
cw.visit(Opcodes.V9, ACC_MODULE, "module-info", null, null, null);
|
||||
cw.visit(Opcodes.V10, ACC_MODULE, "module-info", null, null, null);
|
||||
|
||||
int moduleFlags = md.modifiers().stream()
|
||||
.map(MODULE_MODS_TO_FLAGS::get)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue