--- old/src/java.base/share/classes/jdk/internal/module/ModuleInfo.java 2017-02-07 13:13:44.826027095 +0000 +++ new/src/java.base/share/classes/jdk/internal/module/ModuleInfo.java 2017-02-07 13:13:44.658015557 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -37,7 +37,6 @@ import java.lang.module.ModuleDescriptor.Requires; import java.lang.module.ModuleDescriptor.Exports; import java.lang.module.ModuleDescriptor.Opens; -import java.lang.module.ModuleDescriptor.Version; import java.nio.ByteBuffer; import java.nio.BufferUnderflowException; import java.util.ArrayList; @@ -51,7 +50,6 @@ import jdk.internal.misc.JavaLangModuleAccess; import jdk.internal.misc.SharedSecrets; -import jdk.internal.module.ModuleResolution; import static jdk.internal.module.ClassFileConstants.*; @@ -221,7 +219,7 @@ Set attributes = new HashSet<>(); Builder builder = null; - Set packages = null; + Set allPackages = null; String mainClass = null; String[] osValues = null; ModuleHashes hashes = null; @@ -245,7 +243,7 @@ break; case MODULE_PACKAGES : - packages = readModulePackagesAttribute(in, cpool); + allPackages = readModulePackagesAttribute(in, cpool); break; case MODULE_MAIN_CLASS : @@ -284,51 +282,44 @@ throw invalidModuleDescriptor(MODULE + " attribute not found"); } + // ModuleMainClass and ModuleTarget attributes + if (mainClass != null) { + builder.mainClass(mainClass); + } + if (osValues != null) { + if (osValues[0] != null) builder.osName(osValues[0]); + if (osValues[1] != null) builder.osArch(osValues[1]); + if (osValues[2] != null) builder.osVersion(osValues[2]); + } + // If the ModulePackages attribute is not present then the packageFinder // is used to find the set of packages boolean usedPackageFinder = false; - if (packages == null && packageFinder != null) { + if (allPackages == null && packageFinder != null) { try { - packages = new HashSet<>(packageFinder.get()); + allPackages = packageFinder.get(); } catch (UncheckedIOException x) { throw x.getCause(); } usedPackageFinder = true; } - if (packages != null) { - Set exportedPackages = JLMA.exportedPackages(builder); - Set openPackages = JLMA.openPackages(builder); - if (packages.containsAll(exportedPackages) - && packages.containsAll(openPackages)) { - packages.removeAll(exportedPackages); - packages.removeAll(openPackages); - } else { - // the set of packages is not complete - Set exportedAndOpenPackages = new HashSet<>(); - exportedAndOpenPackages.addAll(exportedPackages); - exportedAndOpenPackages.addAll(openPackages); - for (String pn : exportedAndOpenPackages) { - if (!packages.contains(pn)) { - String tail; - if (usedPackageFinder) { - tail = " not found by package finder"; - } else { - tail = " missing from ModulePackages attribute"; - } - throw invalidModuleDescriptor("Package " + pn + tail); - } + if (allPackages != null) { + Set knownPackages = JLMA.packages(builder); + if (!allPackages.containsAll(knownPackages)) { + Set missingPackages = new HashSet<>(knownPackages); + missingPackages.removeAll(allPackages); + assert !missingPackages.isEmpty(); + String missingPackage = missingPackages.iterator().next(); + String tail; + if (usedPackageFinder) { + tail = " not found in module"; + } else { + tail = " missing from ModulePackages class file attribute"; } - assert false; // should not get here - } - builder.contains(packages); - } + throw invalidModuleDescriptor("Package " + missingPackage + tail); - if (mainClass != null) - builder.mainClass(mainClass); - if (osValues != null) { - if (osValues[0] != null) builder.osName(osValues[0]); - if (osValues[1] != null) builder.osArch(osValues[1]); - if (osValues[2] != null) builder.osVersion(osValues[2]); + } + builder.packages(allPackages); } ModuleDescriptor descriptor = builder.build(); @@ -347,10 +338,17 @@ String mn = cpool.getModuleName(module_name_index); int module_flags = in.readUnsignedShort(); + + Set modifiers = new HashSet<>(); boolean open = ((module_flags & ACC_OPEN) != 0); - boolean synthetic = ((module_flags & ACC_SYNTHETIC) != 0); + if (open) + modifiers.add(ModuleDescriptor.Modifier.OPEN); + if ((module_flags & ACC_SYNTHETIC) != 0) + modifiers.add(ModuleDescriptor.Modifier.SYNTHETIC); + if ((module_flags & ACC_MANDATED) != 0) + modifiers.add(ModuleDescriptor.Modifier.MANDATED); - Builder builder = JLMA.newModuleBuilder(mn, false, open, synthetic); + Builder builder = JLMA.newModuleBuilder(mn, false, modifiers); int module_version_index = in.readUnsignedShort(); if (module_version_index != 0) { @@ -381,16 +379,11 @@ } int requires_version_index = in.readUnsignedShort(); - Version compiledVersion = null; - if (requires_version_index != 0) { - String vs = cpool.getUtf8(requires_version_index); - compiledVersion = Version.parse(vs); - } - - if (compiledVersion == null) { + if (requires_version_index == 0) { builder.requires(mods, dn); } else { - builder.requires(mods, dn, compiledVersion); + String vs = cpool.getUtf8(requires_version_index); + JLMA.requires(builder, mods, dn, vs); } if (dn.equals("java.base")) @@ -629,10 +622,7 @@ /** * Return true if the given attribute name is the name of a pre-defined - * attribute that is not allowed in the class file. - * - * Except for Module, InnerClasses, SourceFile, SourceDebugExtension, and - * Deprecated, none of the pre-defined attributes in JVMS 4.7 may appear. + * attribute in JVMS 4.7 that is not allowed in a module-info class. */ private static boolean isAttributeDisallowed(String name) { Set notAllowed = predefinedNotAllowed; @@ -640,6 +630,7 @@ notAllowed = Set.of( "ConstantValue", "Code", + "Deprecated", "StackMapTable", "Exceptions", "EnclosingMethod",