-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
11
A DESCRIPTION OF THE PROBLEM :
1. We are trying to unzip a file using ZipInputStream, ZipEntry
2. While traversing zip file, we get zipEntry using API ZipInputStream.getNextEntry()
3. From this ZipEntry, we are fetching filename and from which creating File Object.
4. Now, file object is pointing to directory
a. If Directory contains data -> file.isDirectory() is returing true
b. But, If directory is empty -> file.isDirectory() is returing false which is not expected.
5. Because of above issue, Empty directories are getting copied file type as files instead dirs.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Make a zip file with empty directories
2. Unzip Directory using ZipInputStream, ZipEntry.
3. Verify isDirectory() method for empty directories
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
isDirectory() should return true if it is pointing to a directory irrespective to whether directory is empty or not.
ACTUAL -
isDirectory() is returning false when file object is pointing to empty directory.
---------- BEGIN SOURCE ----------
try (FileInputStream fis = new FileInputStream(zipFilePath); ZipInputStream zis = new ZipInputStream(fis);) {
ZipEntry ze = zis.getNextEntry();
while (ze != null) {
String fileName = ze.getName();
File file = new File(fileName );
if(file .isDirectory){
System.out.println("File type is Directory")
}
else{
System.out.println("File type is file")
}
}
---------- END SOURCE ----------
1. We are trying to unzip a file using ZipInputStream, ZipEntry
2. While traversing zip file, we get zipEntry using API ZipInputStream.getNextEntry()
3. From this ZipEntry, we are fetching filename and from which creating File Object.
4. Now, file object is pointing to directory
a. If Directory contains data -> file.isDirectory() is returing true
b. But, If directory is empty -> file.isDirectory() is returing false which is not expected.
5. Because of above issue, Empty directories are getting copied file type as files instead dirs.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Make a zip file with empty directories
2. Unzip Directory using ZipInputStream, ZipEntry.
3. Verify isDirectory() method for empty directories
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
isDirectory() should return true if it is pointing to a directory irrespective to whether directory is empty or not.
ACTUAL -
isDirectory() is returning false when file object is pointing to empty directory.
---------- BEGIN SOURCE ----------
try (FileInputStream fis = new FileInputStream(zipFilePath); ZipInputStream zis = new ZipInputStream(fis);) {
ZipEntry ze = zis.getNextEntry();
while (ze != null) {
String fileName = ze.getName();
File file = new File(fileName );
if(file .isDirectory){
System.out.println("File type is Directory")
}
else{
System.out.println("File type is file")
}
}
---------- END SOURCE ----------