JDK-7184145 : (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.jar
  • Affected Version: 7u6
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2012-07-14
  • Updated: 2013-06-26
  • Resolved: 2012-08-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8
7u45Fixed 8Fixed
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 http://hg.openjdk.java.net/hsx/hotspot-comp/jdk/rev/9e5150e8bcf5
14-08-2012

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
15-07-2012

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

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
14-07-2012

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.
14-07-2012