# HG changeset patch # User sherman # Date 1343250055 25200 # Node ID e47e40956e1bd13f1463d52fef7f74a136123dae # Parent f2738a05273d05dc720758acf588c12acff21cb2 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path Summary: fixed the null case Reviewed-by: alanb diff -r f2738a05273d -r e47e40956e1b src/share/classes/com/sun/java/util/jar/pack/Driver.java --- a/src/share/classes/com/sun/java/util/jar/pack/Driver.java Tue Jul 24 12:52:33 2012 +0400 +++ b/src/share/classes/com/sun/java/util/jar/pack/Driver.java Wed Jul 25 14:00:55 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 diff -r f2738a05273d -r e47e40956e1b test/tools/pack200/RepackTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/pack200/RepackTest.java Wed Jul 25 14:00:55 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 an orphaned 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 speciment to local directory + File testFile = new File("src_tools.jar"); + Utils.copyFile(Utils.locateJar("golden.jar"), testFile); + List 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(); + } +}