United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7184145 (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
JDK-7184145 : (pack200) pack200 --repack throws NullPointerException when JAR file specified without path

Details
Type:
Bug
Submit Date:
2012-07-14
Status:
Closed
Updated Date:
2012-10-29
Project Name:
JDK
Resolved Date:
2012-08-02
Component:
core-libs
OS:
generic
Sub-Component:
java.util.jar
CPU:
generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
7u6
Fixed Versions:
7u6 (b22)

Related Reports
Backport:
Backport:

Sub Tasks

Description
This is a regression reported on jdk7u-dev here:

http://mail.openjdk.java.net/pipermail/jdk7u-dev/2012-July/003722.html

Basically "pack200 -repack foo.jar" fails as follows since 7u5 b01

Exception in thread "main" java.lang.NullPointerException
	at com.sun.java.util.jar.pack.Driver.createTempFile(Driver.java:389)
	at com.sun.java.util.jar.pack.Driver.main(Driver.java:244)

The issue is Driver.createTempFile attempts to call Files.createTempFile with where.toPath but "where" is null when the argument is a simple file name.

                                    

Comments
EVALUATION

This is a regression since 7u5 b01 caused by the changes for 7143606. The code needs better handling for the case that the given file name doesn't have a parent and the suffix is something other than .bak. The changes to fix should be low risk.
                                     
2012-07-14
SUGGESTED FIX

diff --git a/src/share/classes/com/sun/java/util/jar/pack/Driver.java b/src/share/classes/com/sun/java/util/jar/pack/Driver.java
--- a/src/share/classes/com/sun/java/util/jar/pack/Driver.java
+++ b/src/share/classes/com/sun/java/util/jar/pack/Driver.java
@@ -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;
@@ -386,7 +387,10 @@
         if ( base.getParentFile() == null && suffix.equals(".bak"))
             where = new File(".").getAbsoluteFile();
 
-        return Files.createTempFile(where.toPath(), prefix, suffix).toFile();
+        Path tmpfile = (where == null) ?
+            Files.createTempFile(prefix, suffix) :
+            Files.createTempFile(where.toPath(), prefix, suffix);
+        return tmpfile.toFile();
     }
 
     static private
                                     
2012-07-14
SUGGESTED FIX

Added modified patch with some cleanups.
                                     
2012-07-14
SUGGESTED FIX

Kumar has added a test and pushed the changes to jdk8/tl/jdk:

http://hg.openjdk.java.net/jdk8/tl/jdk/rev/9e5150e8bcf5
                                     
2012-07-15
EVALUATION

http://hg.openjdk.java.net/hsx/hotspot-comp/jdk/rev/9e5150e8bcf5
                                     
2012-08-14



Hardware and Software, Engineered to Work Together