Skip to content

Commit

Permalink
Fix #1789 NullPointerException: The fileObject parameter cannot be null
Browse files Browse the repository at this point in the history
  • Loading branch information
eduramiba committed Sep 26, 2017
1 parent 2d22d1d commit 8d5864d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,19 +210,38 @@ public void report(String message, String errorType, Object relatedInformation,
}
}

public static FileObject getArchivedFile(FileObject fileObject) {
public static boolean isArchiveFile(FileObject fileObject) {
if (fileObject == null) {
return null;
return false;
}

if (fileObject.getExt().toLowerCase().startsWith("xls")) {//Seems to break it otherwise!
return false;
}

boolean isGz = fileObject.getExt().equalsIgnoreCase("gz");
boolean isBzip = fileObject.getExt().equalsIgnoreCase("bz2");

if (isGz || isBzip) {
return true;
}

return FileUtil.isArchiveFile(fileObject);
}

public static FileObject getArchivedFile(final FileObject fileObject) {
if (!isArchiveFile(fileObject)) {
return fileObject;
}

FileObject result = fileObject;

// ZIP and JAR archives
if (FileUtil.isArchiveFile(fileObject)) {
FileObject[] children = FileUtil.getArchiveRoot(fileObject).getChildren();
fileObject = children.length > 0 ? children[0] : null;
if (children.length > 0) {
result = children[0];
}
} else { // GZ or BZIP2 archives
boolean isGz = fileObject.getExt().equalsIgnoreCase("gz");
boolean isBzip = fileObject.getExt().equalsIgnoreCase("bz2");
Expand Down Expand Up @@ -260,14 +279,18 @@ public static FileObject getArchivedFile(FileObject fileObject) {
}
tempFile.deleteOnExit();
tempFile = FileUtil.normalizeFile(tempFile);
fileObject = FileUtil.toFileObject(tempFile);
result = FileUtil.toFileObject(tempFile);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
}

return fileObject;

if (result == null) {
result = fileObject;//Never return null if the archive is empty, broken or anything
}

return result;
}

public static File getBzipFile(FileObject in, File out, boolean isTar) throws IOException {
Expand Down
2 changes: 1 addition & 1 deletion modules/ImportAPI/src/main/nbm/manifest.mf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Manifest-Version: 1.0
AutoUpdate-Essential-Module: true
OpenIDE-Module-Localizing-Bundle: org/gephi/io/importer/api/Bundle.properties
OpenIDE-Module-Specification-Version: ${gephi.modules.specification.version}
OpenIDE-Module-Specification-Version: 0.9.2.1
OpenIDE-Module-Display-Category: Gephi Core
OpenIDE-Module-Name: Import API

0 comments on commit 8d5864d

Please sign in to comment.