changeset 14820:135353aa285a

Fix for 8135173, jlink: IllegalAccessError thrown if the module does not require necessary modules
author jfdenise
date Wed, 23 Dec 2015 09:13:09 +0100
parents b8d6539ab73b
children 85beaf633296
files src/jdk.jlink/share/classes/jdk/tools/jlink/internal/PluginRepository.java test/jdk/jigsaw/tools/jlink/JLink2Test.java
diffstat 2 files changed, 19 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/PluginRepository.java	Wed Dec 23 09:13:08 2015 +0100
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/PluginRepository.java	Wed Dec 23 09:13:09 2015 +0100
@@ -141,19 +141,23 @@
     private static <T extends Plugin> List<T> getPlugins(Class<T> clazz, Layer pluginsLayer) {
         Objects.requireNonNull(pluginsLayer);
         List<T> factories = new ArrayList<>();
-        Iterator<T> providers
-                = ServiceLoader.load(pluginsLayer, clazz).iterator();
-        while (providers.hasNext()) {
-            factories.add(providers.next());
+        try {
+            Iterator<T> providers
+                    = ServiceLoader.load(pluginsLayer, clazz).iterator();
+            while (providers.hasNext()) {
+                factories.add(providers.next());
+            }
+            registeredPlugins.values().stream().forEach((fact) -> {
+                if (clazz.isInstance(fact)) {
+                    @SuppressWarnings("unchecked")
+                    T trans = (T) fact;
+                    factories.add(trans);
+                }
+            });
+            return factories;
+        } catch (Exception ex) {
+            throw new PluginException(ex);
         }
-        registeredPlugins.values().stream().forEach((fact) -> {
-            if (clazz.isInstance(fact)) {
-                @SuppressWarnings("unchecked")
-                T trans = (T) fact;
-                factories.add(trans);
-            }
-        });
-        return factories;
     }
 
 }
--- a/test/jdk/jigsaw/tools/jlink/JLink2Test.java	Wed Dec 23 09:13:08 2015 +0100
+++ b/test/jdk/jigsaw/tools/jlink/JLink2Test.java	Wed Dec 23 09:13:09 2015 +0100
@@ -80,16 +80,16 @@
         JImageGenerator.getJLinkTask()
                 .pluginModulePath(unknownDir)
                 .option("--help")
-                .call().assertFailure("(\n|\r|.)*Error: java.nio.file.NoSuchFileException: .*jar.image(\n|\r|.)*");
+                .call().assertFailure("(\n|\r|.)*Error: Invalid modules in the plugins path: .*jar.image(\n|\r|.)*");
         Files.createFile(jar);
         JImageGenerator.getJLinkTask()
                 .pluginModulePath(jar)
                 .option("--help")
-                .call().assertFailure("(\n|\r|.)*Error: java.nio.file.NotDirectoryException: .*bad.jar(\n|\r|.)*");
+                .call().assertFailure("(\n|\r|.)*Error: Invalid modules in the plugins path: .*bad.jar(\n|\r|.)*");
         JImageGenerator.getJLinkTask()
                 .pluginModulePath(jar.getParent())
                 .option("--help")
-                .call().assertFailure("Error: java.util.zip.ZipException: zip file is empty");
+                .call().assertFailure("Error: Invalid modules in the plugins path: .*zip file is empty(\n|\r|.)*");
         try (JarOutputStream out = new JarOutputStream(new FileOutputStream(jar.toFile()))) {
             JarEntry entry = new JarEntry("class");
             out.putNextEntry(entry);