8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
authorsundar
Tue, 14 Feb 2017 21:56:09 +0530
changeset 43796 c204d2d789dc
parent 43795 526103bd9c57
child 43797 dab6fb7f37a3
8174718: "Module <name>'s descriptor returns inconsistent package set" confusing Reviewed-by: alanb, jlaskey, mchung
jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ResourcePoolConfiguration.java
jdk/test/tools/jlink/JLinkNegativeTest.java
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ResourcePoolConfiguration.java	Tue Feb 14 14:31:41 2017 +0300
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ResourcePoolConfiguration.java	Tue Feb 14 21:56:09 2017 +0530
@@ -97,7 +97,9 @@
             ModuleDescriptor desc = m.descriptor();
             if (!desc.packages().equals(m.packages())) {
                 throw new RuntimeException("Module " + m.name() +
-                   "'s descriptor returns inconsistent package set");
+                   "'s descriptor indicates the set of packages is : " +
+                   desc.packages() + ", but module contains packages: " +
+                   m.packages());
             }
         });
     }
--- a/jdk/test/tools/jlink/JLinkNegativeTest.java	Tue Feb 14 14:31:41 2017 +0300
+++ b/jdk/test/tools/jlink/JLinkNegativeTest.java	Tue Feb 14 21:56:09 2017 +0530
@@ -25,6 +25,7 @@
  * @test
  * @summary Negative tests for jlink
  * @bug 8130861
+ * @bug 8174718
  * @author Andrei Eremeev
  * @library ../lib
  * @modules java.base/jdk.internal.jimage
@@ -50,6 +51,7 @@
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
+import java.util.Set;
 
 import jdk.internal.module.ModuleInfoWriter;
 import org.testng.SkipException;
@@ -346,4 +348,27 @@
             deleteDirectory(jar2);
         }
     }
+
+    public void testInconsistentModuleInfo() throws IOException {
+        String moduleName = "inconsistentJar";
+        List<String> classNames = Arrays.asList("xorg.acme.internal.B");
+        Path module = helper.generateModuleCompiledClasses(
+                helper.getJarSrcDir(), helper.getJarClassesDir(), moduleName, classNames);
+
+        try (OutputStream out = Files.newOutputStream(module.resolve("module-info.class"))) {
+            ModuleInfoWriter.write(ModuleDescriptor.newModule(moduleName)
+                    .requires("java.base")
+                    .packages(Set.of("org.acme.internal"))
+                    .build(), out);
+        }
+
+        Path jar = JImageGenerator.createJarFile(helper.getJarDir().resolve(moduleName + ".jar"), module);
+        try {
+            helper.generateDefaultImage(moduleName)
+                  .assertFailure("Module inconsistentJar's descriptor indicates the set of packages is : " +
+                  "[org.acme.internal], but module contains packages: [xorg.acme.internal]");
+        } finally {
+            deleteDirectory(jar);
+        }
+    }
 }