8163382: ResourcePoolManager.findEntry has a bug in startsWith call
authorsundar
Tue, 09 Aug 2016 09:44:25 +0530
changeset 40209 68e8944f4424
parent 40208 4554a9ae19ef
child 40210 f13fa56f89ba
8163382: ResourcePoolManager.findEntry has a bug in startsWith call Reviewed-by: jlaskey, redestad
jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ResourcePoolManager.java
jdk/test/tools/jlink/JLinkTest.java
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ResourcePoolManager.java	Mon Aug 08 13:58:14 2016 -0700
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ResourcePoolManager.java	Tue Aug 09 09:44:25 2016 +0530
@@ -83,8 +83,8 @@
             if (!path.startsWith("/")) {
                 path = "/" + path;
             }
-            if (!path.startsWith("/" + name)) {
-                path = "/" + name + path;
+            if (!path.startsWith("/" + name + "/")) {
+                path = "/" + name + path; // path already starts with '/'
             }
             return Optional.ofNullable(moduleContent.get(path));
         }
--- a/jdk/test/tools/jlink/JLinkTest.java	Mon Aug 08 13:58:14 2016 -0700
+++ b/jdk/test/tools/jlink/JLinkTest.java	Tue Aug 09 09:44:25 2016 +0530
@@ -131,6 +131,25 @@
         }
 
         {
+            String moduleName = "m"; // 8163382
+            Path jmod = helper.generateDefaultJModule(moduleName).assertSuccess();
+            JImageGenerator.getJLinkTask()
+                    .modulePath(helper.defaultModulePath())
+                    .output(helper.createNewImageDir(moduleName))
+                    .addMods("m")
+                    .option("")
+                    .call().assertSuccess();
+            moduleName = "mod";
+            jmod = helper.generateDefaultJModule(moduleName).assertSuccess();
+            JImageGenerator.getJLinkTask()
+                    .modulePath(helper.defaultModulePath())
+                    .output(helper.createNewImageDir(moduleName))
+                    .addMods("m")
+                    .option("")
+                    .call().assertSuccess();
+        }
+
+        {
             // Help
             StringWriter writer = new StringWriter();
             jdk.tools.jlink.internal.Main.run(new String[]{"--help"}, new PrintWriter(writer));