JDK-6408781 : jar file created without error when the input file is same as archive file name
  • Type: Bug
  • Component: tools
  • Sub-Component: jar
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Won't Fix
  • OS: generic
  • CPU: x86
  • Submitted: 2006-04-05
  • Updated: 2017-12-13
  • Resolved: 2017-12-13
Description
jar file created without error when the input file is same as archive file name

Tested Build : mustang jdk b78
Tested OS : windows and solaris

Steps to reproduce :

1. Install mustang jdk b78
2. Go to jdk1.6.0/bin
3. Create a jar file with the source name file as same as destination file like the following :. 

*On windows*
 > jar -cvf c:\temp\test.jar c:\temp\test.jar (test.jar does not exist and same as archive file name)
added manifest

(though test.jar does not exist, it tries to create with test.jar as the input file)
 >jar -xvf c:\temp\test.jar
java.io.IOException: META-INF : could not create directory
.
.
.


*On solaris*
 > jar -cvf /tmp/malathi/test.jar /tmp/malathi/test.jar
added manifest
adding: tmp/malathi/test.jar(in = 111) (out= 67)(deflated 39%) (this part is missing on Windows)

(though test.jar does not exist, it tries to add test.jar as the input file)

 > jar -xvf /tmp/malathi/test.jar
(2 more folders /tmp/malathi and test.jar file got created under /tmp/malathi)

rohit:/tmp/malathi/tmp/malathi 107 % jar -xvf test.jar
  created: META-INF/
java.io.EOFException: Unexpected end of ZLIB input stream
        at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:215)
        at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:134)
        at java.util.zip.ZipInputStream.read(ZipInputStream.java:140)
        at sun.tools.jar.Main.extractFile(Main.java:715)
        at sun.tools.jar.Main.extract(Main.java:678)
        at sun.tools.jar.Main.run(Main.java:190)
        at sun.tools.jar.Main.main(Main.java:904)

Expected behavior : Instead of creating a jar file, it should throw error message like "/tmp/malathi/test.jar : no such file or directory" or something like "test.jar same as archive file."

Comments
EVALUATION The bug is trickier than just name-based comparison might suggest. Consider this on Solaris: % jar cf /tmp/test.jar someFiles... % ln -s /tmp/test.jar /tmp/symtest.jar % rm /tmp/test.jar % jar cvf /tmp/test.jar /tmp/symtest.jar added manifest adding: tmp/symtest.jar(in = 111) (out= 64)(deflated 42%) % jar xvf /tmp/test.jar created: META-INF/ inflated: META-INF/MANIFEST.MF inflated: tmp/symtest.jar % cd tmp % jar xvf symtest.jar created: META-INF/ java.io.EOFException: Unexpected end of ZLIB input stream ... as per the Description
05-04-2006

SUGGESTED FIX During create (and probably also update), ensure that the destination archive is not in the set of inputfiles.
05-04-2006