FULL PRODUCT VERSION :
java version "1.6.0_29"
Java(TM) SE Runtime Environment (build 1.6.0_29-b11)
Java HotSpot(TM) Client VM (build 20.4-b02, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
The problem maybe not reproduce-able every time. but when it can reproduce one time. it's reproduce-able from then on.
I created a zip file on windows server 2008 by:
1. right click the mouse->New->Compressed(zipped) Folder
2. rename it to a.zip
3. then create a empty folder named: a
4. then in folder a create a new txt file named: b.txt
5. drag the folder a to the zipped folder: a.zip
6. add any another jar file to the zip.
7. use the java code to unzip the zip.
8. there is an exception thrown:java.io.FileNotFoundException: C:\installTest\tmp\1343099963134\a\c.txt (The system cannot find the path specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:194)
at java.io.FileOutputStream.<init>(FileOutputStream.java:84)
at Test.extractZip(Test.java:41)
at Test.main(Test.java:62)
REGRESSION. Last worked in version 6u31
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
I created a zip file on windows server 2008 by:
1. right click the mouse->New->Compressed(zipped) Folder
2. rename it to a.zip
3. then create a empty folder named: a
4. then in folder a create a new txt file named: b.txt
5. drag the folder a to the zipped folder: a.zip
6. add any another jar file to the zip.
7. use the java code to unzip the zip.
8. there is an exception thrown:java.io.FileNotFoundException: C:\installTest\tmp\1343099963134\a\c.txt (The system cannot find the path specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:194)
at java.io.FileOutputStream.<init>(FileOutputStream.java:84)
at Test.extractZip(Test.java:41)
at Test.main(Test.java:62)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The problem maybe: it should find the folder a first, then find the file b.txt under it.
ACTUAL -
But it seems found the file a/b.txt directlly and skip the folder a
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.io.FileNotFoundException: C:\installTest\tmp\1343099963134\a\c.txt (The system cannot find the path specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:194)
at java.io.FileOutputStream.<init>(FileOutputStream.java:84)
at Test.extractZip(Test.java:41)
at Test.main(Test.java:62)
REPRODUCIBILITY :
This bug can be reproduced often.
---------- BEGIN SOURCE ----------
public static void extractZip(String sourcePath, String fileName, String destPath){
File destFile = new File(destPath);
if(!destFile.exists()){
destFile.mkdirs();
}
try
{
byte[] buf = new byte[1024];
ZipInputStream zipinputstream = null;
ZipEntry zipentry;
zipinputstream = new ZipInputStream(new BufferedInputStream(
new FileInputStream(sourcePath+File.separator+fileName)));
zipentry = zipinputstream.getNextEntry();
while (zipentry != null)
{
//for each entry to be extracted
String entryName = destPath +File.separator+ zipentry.getName();
int n;
FileOutputStream fileoutputstream;
File newFile = new File(entryName);
if (zipentry.isDirectory()) {
if (!newFile.mkdirs()) {
break;
}
zipentry = zipinputstream.getNextEntry();
continue;
}
fileoutputstream = new FileOutputStream(entryName);
while ((n = zipinputstream.read(buf, 0, 1024)) > -1) {
fileoutputstream.write(buf, 0, n);
}
fileoutputstream.close();
zipinputstream.closeEntry();
zipentry = zipinputstream.getNextEntry();
}//while
zipinputstream.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
the exception was thrown by this line:
fileoutputstream = new FileOutputStream(entryName);
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
before execute the above line, check if the parent of the file exists or not, if not, make dirs first
java version "1.6.0_29"
Java(TM) SE Runtime Environment (build 1.6.0_29-b11)
Java HotSpot(TM) Client VM (build 20.4-b02, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
The problem maybe not reproduce-able every time. but when it can reproduce one time. it's reproduce-able from then on.
I created a zip file on windows server 2008 by:
1. right click the mouse->New->Compressed(zipped) Folder
2. rename it to a.zip
3. then create a empty folder named: a
4. then in folder a create a new txt file named: b.txt
5. drag the folder a to the zipped folder: a.zip
6. add any another jar file to the zip.
7. use the java code to unzip the zip.
8. there is an exception thrown:java.io.FileNotFoundException: C:\installTest\tmp\1343099963134\a\c.txt (The system cannot find the path specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:194)
at java.io.FileOutputStream.<init>(FileOutputStream.java:84)
at Test.extractZip(Test.java:41)
at Test.main(Test.java:62)
REGRESSION. Last worked in version 6u31
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
I created a zip file on windows server 2008 by:
1. right click the mouse->New->Compressed(zipped) Folder
2. rename it to a.zip
3. then create a empty folder named: a
4. then in folder a create a new txt file named: b.txt
5. drag the folder a to the zipped folder: a.zip
6. add any another jar file to the zip.
7. use the java code to unzip the zip.
8. there is an exception thrown:java.io.FileNotFoundException: C:\installTest\tmp\1343099963134\a\c.txt (The system cannot find the path specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:194)
at java.io.FileOutputStream.<init>(FileOutputStream.java:84)
at Test.extractZip(Test.java:41)
at Test.main(Test.java:62)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The problem maybe: it should find the folder a first, then find the file b.txt under it.
ACTUAL -
But it seems found the file a/b.txt directlly and skip the folder a
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.io.FileNotFoundException: C:\installTest\tmp\1343099963134\a\c.txt (The system cannot find the path specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:194)
at java.io.FileOutputStream.<init>(FileOutputStream.java:84)
at Test.extractZip(Test.java:41)
at Test.main(Test.java:62)
REPRODUCIBILITY :
This bug can be reproduced often.
---------- BEGIN SOURCE ----------
public static void extractZip(String sourcePath, String fileName, String destPath){
File destFile = new File(destPath);
if(!destFile.exists()){
destFile.mkdirs();
}
try
{
byte[] buf = new byte[1024];
ZipInputStream zipinputstream = null;
ZipEntry zipentry;
zipinputstream = new ZipInputStream(new BufferedInputStream(
new FileInputStream(sourcePath+File.separator+fileName)));
zipentry = zipinputstream.getNextEntry();
while (zipentry != null)
{
//for each entry to be extracted
String entryName = destPath +File.separator+ zipentry.getName();
int n;
FileOutputStream fileoutputstream;
File newFile = new File(entryName);
if (zipentry.isDirectory()) {
if (!newFile.mkdirs()) {
break;
}
zipentry = zipinputstream.getNextEntry();
continue;
}
fileoutputstream = new FileOutputStream(entryName);
while ((n = zipinputstream.read(buf, 0, 1024)) > -1) {
fileoutputstream.write(buf, 0, n);
}
fileoutputstream.close();
zipinputstream.closeEntry();
zipentry = zipinputstream.getNextEntry();
}//while
zipinputstream.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
the exception was thrown by this line:
fileoutputstream = new FileOutputStream(entryName);
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
before execute the above line, check if the parent of the file exists or not, if not, make dirs first