--- old/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JlinkTask.java 2017-10-19 19:28:23.000000000 +0530 +++ new/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JlinkTask.java 2017-10-19 19:28:23.000000000 +0530 @@ -438,6 +438,17 @@ Configuration cf = bindService ? config.resolveAndBind() : config.resolve(); + ModuleFinder finder = config.finder(); + for (String root : config.getModules()) { + Optional modRef = finder.find(root); + if (modRef.isPresent()) { + ModuleDescriptor modDesc = modRef.get().descriptor(); + if (modDesc.isAutomatic()) { + throw new IllegalArgumentException(taskHelper.getMessage("err.automatic.module.as.root", modDesc.name())); + } + } + } + if (verbose && log != null) { // print modules to be linked in cf.modules().stream() --- old/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/jlink.properties 2017-10-19 19:28:25.000000000 +0530 +++ new/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/jlink.properties 2017-10-19 19:28:24.000000000 +0530 @@ -107,6 +107,7 @@ error.prefix=Error: warn.prefix=Warning: +err.automatic.module.as.root:automatic module cannot be used as a root module: {0} err.unknown.byte.order:unknown byte order {0} err.launcher.main.class.empty:launcher main class name cannot be empty: {0} err.launcher.module.name.empty:launcher module name cannot be empty: {0} --- old/test/jdk/tools/jlink/JLinkNegativeTest.java 2017-10-19 19:28:26.000000000 +0530 +++ new/test/jdk/tools/jlink/JLinkNegativeTest.java 2017-10-19 19:28:26.000000000 +0530 @@ -26,6 +26,7 @@ * @summary Negative tests for jlink * @bug 8130861 * @bug 8174718 + * @bug 8189671 * @author Andrei Eremeev * @library ../lib * @modules java.base/jdk.internal.jimage @@ -39,6 +40,8 @@ * @run testng JLinkNegativeTest */ +import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.lang.module.ModuleDescriptor; @@ -52,6 +55,8 @@ import java.util.Collections; import java.util.List; import java.util.Set; +import java.util.jar.JarEntry; +import java.util.jar.JarOutputStream; import jdk.internal.module.ModuleInfoWriter; import org.testng.SkipException; @@ -199,6 +204,32 @@ } } + private static File createJarFile(File dir, String filename, String pkg, String name) throws IOException { + File jarFile = new File(dir, filename + ".jar"); + + try (JarOutputStream output = new JarOutputStream(new FileOutputStream(jarFile))) { + JarEntry entry = new JarEntry(filename + "/" + pkg + "/" + name); + output.putNextEntry(entry); + } + + return jarFile; + } + + public void testAutomaticModuleAsRoot() throws IOException { + Path imageFile = helper.createNewImageDir("test"); + String jarName = "myautomod"; + File jarFile = createJarFile(new File("jars"), jarName, "com/acme", "Bar.class"); + try { + JImageGenerator.getJLinkTask() + .output(imageFile) + .addMods(jarName) + .modulePath(helper.defaultModulePath()) + .call().assertFailure("Error: automatic module cannot be used as a root module: " + jarName); + } finally { + jarFile.delete(); + } + } + // Temporarily exclude; the jmod tool can no longer be used to create a jmod // with a class in the unnamed package. Find another way, or remove. // public void testAddDefaultPackage() throws IOException {