8030046: javac incorrectly handles absolute paths in manifest classpath
authorpgovereau
Mon, 21 Apr 2014 17:57:47 -0400
changeset 24222 244127f8dd79
parent 24221 2376793dd33b
child 24223 90b07e33a49d
8030046: javac incorrectly handles absolute paths in manifest classpath Reviewed-by: jjg, vromero
langtools/src/share/classes/com/sun/tools/javac/file/FSInfo.java
langtools/test/tools/javac/Paths/AbsolutePathTest.java
langtools/test/tools/javac/lib/ToolBox.java
--- a/langtools/src/share/classes/com/sun/tools/javac/file/FSInfo.java	Fri Apr 18 08:44:53 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/file/FSInfo.java	Mon Apr 21 17:57:47 2014 -0400
@@ -82,8 +82,10 @@
             for (StringTokenizer st = new StringTokenizer(path);
                  st.hasMoreTokens(); ) {
                 String elt = st.nextToken();
-                File f = (parent == null ? new File(elt) : new File(parent, elt));
-                list.add(f);
+                try {
+                    File f = parent == null ? new File(elt): new File(file.toURI().resolve(elt));
+                    list.add(f);
+                } catch (IllegalArgumentException ex) {}
             }
 
             return list;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/Paths/AbsolutePathTest.java	Mon Apr 21 17:57:47 2014 -0400
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8030046
+ * @summary javac incorrectly handles absolute paths in manifest classpath
+ * @author govereau
+ * @library /tools/javac/lib
+ * @build ToolBox
+ * @run main AbsolutePathTest
+ */
+
+import java.io.File;
+
+public class AbsolutePathTest {
+    public static void main(String... cmdline) throws Exception {
+        // compile test.Test
+        ToolBox.JavaToolArgs args = new ToolBox.JavaToolArgs();
+        args.appendArgs("-d", "."); // this is needed to get the classfiles in test
+        ToolBox.javac(args.setSources("package test; public class Test{}"));
+
+        // build test.jar containing test.Test
+        // we need the jars in a directory different from the working
+        // directory to trigger the bug. I will reuse test/
+        ToolBox.jar("cf", "test/test.jar", "test/Test.class");
+
+        // build second jar in test directory using
+        // an absolute path reference to the first jar
+        String path = new File("test/test.jar").getAbsolutePath();
+        ToolBox.mkManifestWithClassPath(null, path);
+        ToolBox.jar("cfm", "test/test2.jar", "MANIFEST.MF");
+
+        // this should not fail
+        args.appendArgs("-cp", ".");
+        ToolBox.javac(args.setSources("import test.Test; class Test2 {}"));
+    }
+}
--- a/langtools/test/tools/javac/lib/ToolBox.java	Fri Apr 18 08:44:53 2014 -0700
+++ b/langtools/test/tools/javac/lib/ToolBox.java	Mon Apr 21 17:57:47 2014 -0400
@@ -902,7 +902,9 @@
                       .append("Main-Class: ")
                       .append(mainClass).toString());
         }
-        Files.write(Paths.get("MANIFEST.MF"), lines, null);
+        Files.write(Paths.get("MANIFEST.MF"), lines,
+                    StandardOpenOption.CREATE, StandardOpenOption.WRITE,
+                    StandardOpenOption.TRUNCATE_EXISTING);
     }
 
     /**