7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
Reviewed-by: alanb, sherman
--- a/jdk/src/share/classes/com/sun/java/util/jar/pack/Driver.java Fri Jul 13 16:02:26 2012 -0700
+++ b/jdk/src/share/classes/com/sun/java/util/jar/pack/Driver.java Sat Jul 14 18:00:42 2012 -0700
@@ -36,6 +36,7 @@
import java.io.PrintStream;
import java.text.MessageFormat;
import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -381,12 +382,15 @@
String prefix = base.getName();
if (prefix.length() < 3) prefix += "tmp";
- File where = base.getParentFile();
+ File where = (base.getParentFile() == null && suffix.equals(".bak"))
+ ? new File(".").getAbsoluteFile()
+ : base.getParentFile();
- if ( base.getParentFile() == null && suffix.equals(".bak"))
- where = new File(".").getAbsoluteFile();
+ Path tmpfile = (where == null)
+ ? Files.createTempFile(prefix, suffix)
+ : Files.createTempFile(where.toPath(), prefix, suffix);
- return Files.createTempFile(where.toPath(), prefix, suffix).toFile();
+ return tmpfile.toFile();
}
static private
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/tools/pack200/RepackTest.java Sat Jul 14 18:00:42 2012 -0700
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2012, 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.
+ */
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+/*
+ * @test
+ * @bug 7184145
+ * @summary tests repacking of a simple named jarfile.
+ * @compile -XDignore.symbol.file Utils.java RepackTest.java
+ * @run main RepackTest
+ * @author ksrini
+ */
+public class RepackTest {
+
+ public static void main(String... args) throws Exception {
+ testRepack();
+ }
+
+ /*
+ * there are two cases we need to test, where the file in question is
+ * orpaned, ie. without a parent ie. not qualified by a parent path
+ * relative nor absolute
+ * case 1: src and dest are the same
+ * case 2: src and dest are different
+ */
+ static void testRepack() throws IOException {
+
+ // make a copy of the test specimen to local directory
+ File testFile = new File("src_tools.jar");
+ Utils.copyFile(Utils.locateJar("golden.jar"), testFile);
+ List<String> cmdsList = new ArrayList<>();
+
+ // case 1:
+ cmdsList.add(Utils.getPack200Cmd());
+ cmdsList.add("--repack");
+ cmdsList.add(testFile.getName());
+ Utils.runExec(cmdsList);
+
+ // case 2:
+ File dstFile = new File("dst_tools.jar");
+ cmdsList.clear();
+ cmdsList.add(Utils.getPack200Cmd());
+ cmdsList.add("--repack");
+ cmdsList.add(dstFile.getName());
+ cmdsList.add(testFile.getName());
+ Utils.runExec(cmdsList);
+
+ // tidy up
+ testFile.delete();
+ dstFile.delete();
+ }
+}