-
Bug
-
Resolution: Fixed
-
P3
-
1.4.0, 5.0u6, 6
-
b86
-
generic, x86
-
generic, windows_nt, windows_2000, windows_xp
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2141066 | 5.0u15 | Abhijit Saha | P3 | Resolved | Fixed | b02 |
OPERATING SYSTEM(S):
Windows
FULL JDK VERSION(S):
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode)
DESCRIPTION:
Sunbug 6182812 allowed unicode and long filenames within Java classes including FileOutputStream.
java.util.zip.ZipFile remains unable to cope with long filenames on both Java 1.5 u06, and 1.6 b65.
I think that this is related to 6329168 "new ZipFile(name) fails on Windows when name contains non-Latin1".
E:\long_filenames_in_zip>java -version
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode)
E:\long_filenames_in_zip>java TestLongJarName
Test failed - problem reading the Jar file back in.
java.util.zip.ZipException: Filename too long
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:203)
at java.util.zip.ZipFile.<init>(ZipFile.java:234)
at ReadLongNameZipFile.main(ReadLongNameZipFile.java:43)
You can verify that the long filename is causing the problem by reducing the value of
minRequiredLength in the attached testcase. The test passes with a smaller number like 30.
//-- Testcase: -------
import java.io.*;
import java.util.jar.*;
import java.util.zip.*;
public class ReadLongNameZipFile {
public static void main (String args[]) {
String longDirName = "abcdefghijklmnopqrstuvwx"; // 24 chars.
String jarFileName = "areallylargejarfilename.jar"; // 27 chars.
File file = null;
File myJarFile = null;
int currentFileLength = 0;
int minRequiredLength = 300; // try something big enough to definitely fail.
String sb = "."+File.separator;
try {
// create a directory structure long enough that the filename will put us over the minRequiredLength
do {
sb=sb+longDirName+File.separator;
file = new File(sb);
file.mkdir();
currentFileLength = file.getCanonicalPath().length();
file.deleteOnExit();
} while (currentFileLength < (minRequiredLength - jarFileName.length()));
// create a new Jar file - this passes OK
sb=sb+jarFileName;
FileOutputStream destJar = new FileOutputStream(sb.toString());
JarOutputStream out = new JarOutputStream(new BufferedOutputStream(destJar));
JarEntry jarEntry = new JarEntry("testFile.txt");
out.putNextEntry(jarEntry);
out.write(1);
out.close();
myJarFile = new File(sb.toString());
currentFileLength = myJarFile.getCanonicalPath().length();
if(!myJarFile.exists()) {
System.err.println("Jar file does not exist.");
}
} catch (IOException e) {
System.err.println("Problem creating the Jar file.");
e.printStackTrace();
}
try {
// create a new ZipFile object (also fails with JarFile - a subclass of ZipFile) using the myJarFile File object...
ZipFile readJarFile = new ZipFile(myJarFile);
readJarFile.close();
System.out.println("Test passed - opened Jar file for reading with a name "+currentFileLength+" characters long!");
} catch (IOException e) {
System.err.println("Test failed - problem reading the Jar file back in.");
e.printStackTrace();
} finally {
// clean up a bit
if(myJarFile!=null) {
if(myJarFile.exists()) {
if(!myJarFile.delete()) {
System.err.println("Jar file cannot be deleted.");
}
}
if(file.exists()) {
if(!file.delete()) {
System.err.println("Directory structure cannot be deleted.");
}
}
}
}
}
}
//-----------------------
Windows
FULL JDK VERSION(S):
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode)
DESCRIPTION:
Sunbug 6182812 allowed unicode and long filenames within Java classes including FileOutputStream.
java.util.zip.ZipFile remains unable to cope with long filenames on both Java 1.5 u06, and 1.6 b65.
I think that this is related to 6329168 "new ZipFile(name) fails on Windows when name contains non-Latin1".
E:\long_filenames_in_zip>java -version
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode)
E:\long_filenames_in_zip>java TestLongJarName
Test failed - problem reading the Jar file back in.
java.util.zip.ZipException: Filename too long
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:203)
at java.util.zip.ZipFile.<init>(ZipFile.java:234)
at ReadLongNameZipFile.main(ReadLongNameZipFile.java:43)
You can verify that the long filename is causing the problem by reducing the value of
minRequiredLength in the attached testcase. The test passes with a smaller number like 30.
//-- Testcase: -------
import java.io.*;
import java.util.jar.*;
import java.util.zip.*;
public class ReadLongNameZipFile {
public static void main (String args[]) {
String longDirName = "abcdefghijklmnopqrstuvwx"; // 24 chars.
String jarFileName = "areallylargejarfilename.jar"; // 27 chars.
File file = null;
File myJarFile = null;
int currentFileLength = 0;
int minRequiredLength = 300; // try something big enough to definitely fail.
String sb = "."+File.separator;
try {
// create a directory structure long enough that the filename will put us over the minRequiredLength
do {
sb=sb+longDirName+File.separator;
file = new File(sb);
file.mkdir();
currentFileLength = file.getCanonicalPath().length();
file.deleteOnExit();
} while (currentFileLength < (minRequiredLength - jarFileName.length()));
// create a new Jar file - this passes OK
sb=sb+jarFileName;
FileOutputStream destJar = new FileOutputStream(sb.toString());
JarOutputStream out = new JarOutputStream(new BufferedOutputStream(destJar));
JarEntry jarEntry = new JarEntry("testFile.txt");
out.putNextEntry(jarEntry);
out.write(1);
out.close();
myJarFile = new File(sb.toString());
currentFileLength = myJarFile.getCanonicalPath().length();
if(!myJarFile.exists()) {
System.err.println("Jar file does not exist.");
}
} catch (IOException e) {
System.err.println("Problem creating the Jar file.");
e.printStackTrace();
}
try {
// create a new ZipFile object (also fails with JarFile - a subclass of ZipFile) using the myJarFile File object...
ZipFile readJarFile = new ZipFile(myJarFile);
readJarFile.close();
System.out.println("Test passed - opened Jar file for reading with a name "+currentFileLength+" characters long!");
} catch (IOException e) {
System.err.println("Test failed - problem reading the Jar file back in.");
e.printStackTrace();
} finally {
// clean up a bit
if(myJarFile!=null) {
if(myJarFile.exists()) {
if(!myJarFile.delete()) {
System.err.println("Jar file cannot be deleted.");
}
}
if(file.exists()) {
if(!file.delete()) {
System.err.println("Directory structure cannot be deleted.");
}
}
}
}
}
}
//-----------------------
- backported by
-
JDK-2141066 ZipFile class cannot open zip files with long filenames
- Resolved
- duplicates
-
JDK-4519027 Zip file names should support Unicode on NT
- Closed
-
JDK-4885817 java.util.zip.ZipException when filename contains Japanese characters
- Closed
- relates to
-
JDK-6423026 Java.util.zip doesn't allow more than 2036 zip files to be concurrently open on Windows
- Resolved