< prev index next >
src/java.base/share/classes/java/lang/module/ModuleInfo.java
Print this page
@@ -45,13 +45,14 @@
import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;
import jdk.internal.module.ModuleHashes;
+import jdk.internal.module.WarnIfResolvedReason;
import static jdk.internal.module.ClassFileConstants.*;
-
+import static jdk.internal.module.WarnIfResolvedReason.fromClassFileFlags;
/**
* Read module information from a {@code module-info} class file.
*
* @implNote The rationale for the hand-coded reader is startup performance
@@ -191,10 +192,11 @@
Set<String> packages = null;
String version = null;
String mainClass = null;
String[] osValues = null;
ModuleHashes hashes = null;
+ int moduleResolution = 0;
for (int i = 0; i < attributes_count ; i++) {
int name_index = in.readUnsignedShort();
String attribute_name = cpool.getUtf8(name_index);
int length = in.readInt();
@@ -233,10 +235,14 @@
} else {
in.skipBytes(length);
}
break;
+ case MODULE_RESOLUTION :
+ moduleResolution = readModuleResolution(in, cpool);
+ break;
+
default:
if (isAttributeDisallowed(attribute_name)) {
throw invalidModuleDescriptor(attribute_name
+ " attribute not allowed");
} else {
@@ -287,10 +293,14 @@
if (osValues[1] != null) builder.osArch(osValues[1]);
if (osValues[2] != null) builder.osVersion(osValues[2]);
}
if (hashes != null)
builder.hashes(hashes);
+ if (moduleResolution != 0) {
+ builder.doNotResolveByDefault(doNotResolveFromFlags(moduleResolution));
+ builder.warnIfResolved(fromClassFileFlags(moduleResolution));
+ }
return builder.build();
}
/**
@@ -527,10 +537,38 @@
}
return new ModuleHashes(algorithm, map);
}
+ /**
+ * Reads the ModuleResolution attribute.
+ */
+ private int readModuleResolution(DataInput in, ConstantPool cpool)
+ throws IOException
+ {
+ int flags = in.readUnsignedShort();
+
+ // just some basic validation
+ int reason = 0;
+ if ((flags & WARN_DEPRECATED) != 0)
+ reason = WARN_DEPRECATED;
+ if ((flags & WARN_DEPRECATED_FOR_REMOVAL) != 0) {
+ if (reason != 0)
+ throw invalidModuleDescriptor("Bad module resolution flags:" + flags);
+ reason = WARN_DEPRECATED_FOR_REMOVAL;
+ }
+ if ((flags & WARN_INCUBATING) != 0) {
+ if (reason != 0)
+ throw invalidModuleDescriptor("Bad module resolution flags:" + flags);
+ }
+
+ return flags;
+ }
+
+ private boolean doNotResolveFromFlags(int flags) {
+ return (flags & DO_NOT_RESOLVE_BY_DEFAULT) != 0;
+ }
/**
* Returns true if the given attribute can be present at most once
* in the class file. Returns false otherwise.
*/
@@ -541,11 +579,12 @@
name.equals(SDE) ||
name.equals(MODULE_PACKAGES) ||
name.equals(MODULE_VERSION) ||
name.equals(MODULE_MAIN_CLASS) ||
name.equals(MODULE_TARGET) ||
- name.equals(MODULE_HASHES))
+ name.equals(MODULE_HASHES) ||
+ name.equals(MODULE_RESOLUTION))
return true;
return false;
}
< prev index next >