From d44ae3fc93472060857f06ee8eae75f50f6c2366 Mon Sep 17 00:00:00 2001 From: Eamonn Saunders Date: Fri, 29 May 2015 14:05:09 -0400 Subject: [PATCH 1/2] Return empty lists instead of null to prevent null pointer exception happening in Collections.sort() --- .../directorytree/ExtractUnallocAction.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/directorytree/ExtractUnallocAction.java b/Core/src/org/sleuthkit/autopsy/directorytree/ExtractUnallocAction.java index c8a9f25c12..138583e31a 100644 --- a/Core/src/org/sleuthkit/autopsy/directorytree/ExtractUnallocAction.java +++ b/Core/src/org/sleuthkit/autopsy/directorytree/ExtractUnallocAction.java @@ -178,7 +178,7 @@ import org.sleuthkit.datamodel.VolumeSystem; } catch (TskCoreException tce) { logger.log(Level.WARNING, "Couldn't get a list of Unallocated Files, failed at sending out the visitor ", tce); //NON-NLS } - return null; + return Collections.emptyList(); } /** @@ -372,7 +372,7 @@ import org.sleuthkit.datamodel.VolumeSystem; * return the single instance of unallocated space. * * @param lf the LayoutFile the visitor encountered - * @return A list of size 1, returns null if it fails + * @return A list of size 1 */ @Override public List visit(final org.sleuthkit.datamodel.LayoutFile lf) { @@ -389,7 +389,7 @@ import org.sleuthkit.datamodel.VolumeSystem; * * @param fs the FileSystem the visitor encountered * @return A list containing the layout files from - * subsequent Visits(), returns null if it fails + * subsequent Visits(), or an empty list */ @Override public List visit(FileSystem fs) { @@ -402,7 +402,7 @@ import org.sleuthkit.datamodel.VolumeSystem; } catch (TskCoreException tce) { logger.log(Level.WARNING, "Couldn't get a list of Unallocated Files, failed at visiting FileSystem " + fs.getId(), tce); //NON-NLS } - return null; + return Collections.emptyList(); } /** @@ -410,12 +410,12 @@ import org.sleuthkit.datamodel.VolumeSystem; * * @param vd VirtualDirectory the visitor encountered * @return A list containing all the LayoutFile in ld, - * returns null if it fails + * or an empty list. */ @Override public List visit(VirtualDirectory vd) { try { - List lflst = new ArrayList(); + List lflst = new ArrayList<>(); for (Content layout : vd.getChildren()) { lflst.add((LayoutFile) layout); } @@ -423,7 +423,7 @@ import org.sleuthkit.datamodel.VolumeSystem; } catch (TskCoreException tce) { logger.log(Level.WARNING, "Could not get list of Layout Files, failed at visiting Layout Directory", tce); //NON-NLS } - return null; + return Collections.emptyList(); } /** @@ -432,7 +432,7 @@ import org.sleuthkit.datamodel.VolumeSystem; * * @param dir the directory this visitor encountered * @return A list containing LayoutFiles encountered during - * subsequent Visits(), returns null if it fails + * subsequent Visits(), or an empty list. */ @Override public List visit(Directory dir) { @@ -445,12 +445,12 @@ import org.sleuthkit.datamodel.VolumeSystem; } catch (TskCoreException tce) { logger.log(Level.WARNING, "Couldn't get a list of Unallocated Files, failed at visiting Directory " + dir.getId(), tce); //NON-NLS } - return null; + return Collections.emptyList(); } @Override protected List defaultVisit(Content cntnt) { - return null; + return Collections.emptyList(); } } From 5c8e41eba1b923b2635c6838e5bbe633a9ebd505 Mon Sep 17 00:00:00 2001 From: Eamonn Saunders Date: Fri, 29 May 2015 14:08:31 -0400 Subject: [PATCH 2/2] Missed a comment change in last checkin. --- .../sleuthkit/autopsy/directorytree/ExtractUnallocAction.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/directorytree/ExtractUnallocAction.java b/Core/src/org/sleuthkit/autopsy/directorytree/ExtractUnallocAction.java index 138583e31a..9f4ac8d4c8 100644 --- a/Core/src/org/sleuthkit/autopsy/directorytree/ExtractUnallocAction.java +++ b/Core/src/org/sleuthkit/autopsy/directorytree/ExtractUnallocAction.java @@ -165,8 +165,7 @@ import org.sleuthkit.datamodel.VolumeSystem; * Gets all the unallocated files in a given Content. * * @param c Content to get Unallocated Files from - * @return A list if it didn't crash List may be empty. Returns - * null on failure. + * @return A list if it didn't crash List may be empty. */ private List getUnallocFiles(Content c) { UnallocVisitor uv = new UnallocVisitor();