< prev index next >
test/jdk/tools/jlink/JLinkNegativeTest.java
Print this page
@@ -24,10 +24,11 @@
/*
* @test
* @summary Negative tests for jlink
* @bug 8130861
* @bug 8174718
+ * @bug 8189671
* @author Andrei Eremeev
* @library ../lib
* @modules java.base/jdk.internal.jimage
* java.base/jdk.internal.module
* jdk.jdeps/com.sun.tools.classfile
@@ -37,10 +38,12 @@
* jdk.compiler
* @build tests.*
* @run testng JLinkNegativeTest
*/
+import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.module.ModuleDescriptor;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
@@ -50,10 +53,12 @@
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Arrays;
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;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -197,10 +202,36 @@
} finally {
deleteDirectory(jmod);
}
}
+ 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 {
// String moduleName = "hacked1";
// Path module = helper.generateModuleCompiledClasses(helper.getJmodSrcDir(), helper.getJmodClassesDir(),
< prev index next >