From 689fbec7195875b7376715d87fdfb8a2685ad2ad Mon Sep 17 00:00:00 2001 From: APriestman Date: Fri, 10 Apr 2015 12:33:12 -0400 Subject: [PATCH 1/7] Fixing exceptions in Image Gallery caused by the case closing. --- .../imagegallery/ImageGalleryController.java | 29 +++++++++++++++---- .../autopsy/imagegallery/ThumbnailCache.java | 2 +- .../imagegallery/datamodel/DrawableDB.java | 22 +++++++++++--- .../imagegallery/datamodel/DrawableFile.java | 8 +++++ .../imagegallery/grouping/GroupManager.java | 5 +++- .../imagegallery/gui/SummaryTablePane.java | 2 +- 6 files changed, 56 insertions(+), 12 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index d544011bc5..318a36819e 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -501,7 +501,7 @@ public final class ImageGalleryController { try { // @@@ Could probably do something more fancy here and check if we've been canceled every now and then InnerTask it = workQueue.take(); - + if (it.cancelled == false) { it.run(); } @@ -615,8 +615,16 @@ public final class ImageGalleryController { */ @Override public void run() { - DrawableFile drawableFile = DrawableFile.create(getFile(), true); - db.updateFile(drawableFile); + try{ + DrawableFile drawableFile = DrawableFile.create(getFile(), true); + db.updateFile(drawableFile); + } catch (NullPointerException ex){ + // This is one of the places where we get an error if the case is closed during processing. + // We don't want to print out a ton of exceptions if this is the case. + if(Case.isCaseOpen()){ + Logger.getLogger(UpdateFileTask.class.getName()).log(Level.SEVERE, "Error in UpdateFile task"); + } + } } } @@ -634,7 +642,16 @@ public final class ImageGalleryController { */ @Override public void run() { - db.removeFile(getFile().getId()); + try{ + db.removeFile(getFile().getId()); + } catch (NullPointerException ex){ + // This is one of the places where we get an error if the case is closed during processing. + // We don't want to print out a ton of exceptions if this is the case. + if(Case.isCaseOpen()){ + Logger.getLogger(RemoveFileTask.class.getName()).log(Level.SEVERE, "Case was closed out from underneath RemoveFile task"); + } + } + } } @@ -799,7 +816,9 @@ public final class ImageGalleryController { } catch (TskCoreException ex) { Logger.getLogger(PrePopulateDataSourceFiles.class.getName()).log(Level.WARNING, "failed to transfer all database contents", ex); } catch (IllegalStateException ex) { - Logger.getLogger(PrePopulateDataSourceFiles.class.getName()).log(Level.SEVERE, "Case was closed out from underneath CopyDataSource task", ex); + Logger.getLogger(PrePopulateDataSourceFiles.class.getName()).log(Level.SEVERE, "Case was closed out from underneath prepopulating database"); + } catch (NullPointerException ex) { + Logger.getLogger(PrePopulateDataSourceFiles.class.getName()).log(Level.SEVERE, "Case was closed out from underneath prepopulating database"); } progressHandle.finish(); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ThumbnailCache.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ThumbnailCache.java index 3b4abb684c..0aab44e58c 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ThumbnailCache.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ThumbnailCache.java @@ -233,7 +233,7 @@ public enum ThumbnailCache { } return bi; } catch (IOException ex) { - LOGGER.log(Level.WARNING, "Could not read image: " + file.getName(), ex); + LOGGER.log(Level.WARNING, "Could not read image: " + file.getName()); return null; } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java index b788da2f55..19b02e82d1 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java @@ -613,8 +613,17 @@ public class DrawableDB { tr.addUpdatedFile(f.getId()); } catch (SQLException ex) { - LOGGER.log(Level.SEVERE, "failed to insert/update file" + f.getName(), ex); - } finally { + // This is one of the places where we get an error if the case is closed during processing, + // which doesn't need to be reported. + if(Case.isCaseOpen()){ + LOGGER.log(Level.SEVERE, "failed to insert/update file" + f.getName(), ex); + } + } catch (NullPointerException ex) { + if(Case.isCaseOpen()){ + LOGGER.log(Level.SEVERE, "failed to insert/update file" + f.getName(), ex); + } + } + finally { dbWriteUnlock(); } } @@ -960,7 +969,7 @@ public class DrawableDB { return DrawableFile.create(controller.getSleuthKitCase().getAbstractFileById(id), areFilesAnalyzed(Collections.singleton(id))); } catch (IllegalStateException ex) { - LOGGER.log(Level.SEVERE, "there is no case open; failed to load file with id: " + id, ex); + LOGGER.log(Level.SEVERE, "there is no case open; failed to load file with id: " + id); return null; } } @@ -1168,7 +1177,12 @@ public class DrawableDB { fireRemovedFiles(removedFiles); } } catch (SQLException ex) { - LOGGER.log(Level.SEVERE, "Error commiting drawable.db.", ex); + if(Case.isCaseOpen()){ + LOGGER.log(Level.SEVERE, "Error commiting drawable.db.", ex); + } + else{ + LOGGER.log(Level.WARNING, "Error commiting drawable.db - case is closed."); + } rollback(); } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java index 71febd6449..1b7867bf48 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java @@ -174,6 +174,9 @@ public abstract class DrawableFile extends AbstractFile } catch (TskCoreException ex) { Logger.getAnonymousLogger().log(Level.WARNING, "problem looking up " + DrawableAttribute.TAGS.getDisplayName() + " for " + file.getName(), ex); return Collections.emptySet(); + } catch (IllegalStateException ex) { + Logger.getAnonymousLogger().log(Level.SEVERE, "there is no case open; failed to look up " + DrawableAttribute.TAGS.getDisplayName() + " for " + file.getName()); + return null; } } @@ -282,7 +285,12 @@ public abstract class DrawableFile extends AbstractFile } } catch (TskCoreException ex) { Logger.getLogger(DrawableFile.class.getName()).log(Level.WARNING, "problem looking up category for file " + this.getName(), ex); + } catch (IllegalStateException ex){ + // We get here if the case has been closed, in which case we don't need to print out a ton of warnings. + //Logger.getLogger(DrawableFile.class.getName()).log(Level.WARNING, "problem looking up category for file " + this.getName() + + // " - no case open"); } + } public abstract Image getThumbnail(); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java index 8cf6a704d2..f94c88ea5c 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java @@ -563,7 +563,10 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { } catch (TskCoreException ex) { LOGGER.log(Level.WARNING, "TSK error getting files in Category:" + category.getDisplayName(), ex); throw ex; - } + } catch(IllegalStateException ex){ + // This is one of the places where we get an error if the case is closed during processing. + throw new TskCoreException("Case closed while getting files"); + } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SummaryTablePane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SummaryTablePane.java index 02106c0874..b6627cbab8 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SummaryTablePane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SummaryTablePane.java @@ -111,7 +111,7 @@ public class SummaryTablePane extends AnchorPane implements Category.CategoryLis try { data.add(new Pair<>(cat, ImageGalleryController.getDefault().getGroupManager().countFilesWithCategory(cat))); } catch (TskCoreException ex) { - Exceptions.printStackTrace(ex); + //Exceptions.printStackTrace(ex); } } Platform.runLater(() -> { From 8a1c142f5fe7039b67f87e6c7bd31faf1eada6e8 Mon Sep 17 00:00:00 2001 From: APriestman Date: Wed, 15 Apr 2015 11:25:20 -0400 Subject: [PATCH 2/7] Made locks in DrawableDB not static. Added method to clear out Category listeners. Testing using one dbWorkerThread instead of a new one for each case. --- .../imagegallery/ImageGalleryController.java | 6 ++++- .../imagegallery/datamodel/Category.java | 22 +++++++++++++++++++ .../imagegallery/datamodel/DrawableDB.java | 8 +++---- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index 318a36819e..29cd329abc 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -58,6 +58,7 @@ import org.sleuthkit.autopsy.coreutils.History; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableDB; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; +import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.grouping.GroupManager; import org.sleuthkit.autopsy.imagegallery.grouping.GroupViewState; import org.sleuthkit.autopsy.imagegallery.gui.NoGroupsDialog; @@ -303,7 +304,8 @@ public final class ImageGalleryController { private void restartWorker() { if (dbWorkerThread != null) { - dbWorkerThread.cancelAllTasks(); + return; + //dbWorkerThread.cancelAllTasks(); } dbWorkerThread = new DBWorkerThread(); @@ -330,6 +332,7 @@ public final class ImageGalleryController { // if we add this line icons are made as files are analyzed rather than on demand. // db.addUpdatedFileListener(IconCache.getDefault()); + // @@@ I think we should add a checkhere to see if the thread already exists restartWorker(); historyManager.clear(); groupManager.setDB(db); @@ -342,6 +345,7 @@ public final class ImageGalleryController { public synchronized void reset() { LOGGER.info("resetting ImageGalleryControler to initial state."); selectionModel.clearSelection(); + Category.unregisterAllFileListeners(); Platform.runLater(() -> { historyManager.clear(); }); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java index 2bdf08d70f..2f2fe706c1 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java @@ -25,6 +25,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.Iterator; import java.util.logging.Level; import javafx.event.ActionEvent; import javafx.event.EventHandler; @@ -37,6 +38,7 @@ import javax.annotation.concurrent.GuardedBy; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.TagUtils; import org.sleuthkit.autopsy.imagegallery.actions.CategorizeAction; +import org.sleuthkit.autopsy.imagegallery.gui.SingleDrawableViewBase; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -84,6 +86,26 @@ public enum Category implements Comparable { listeners.remove(aThis); } } + + /** + * Clears out all the existing file-type listeners. + * To be called when the case is closed to prevent + * old abstract files files from trying to access the closed + * database. + */ + public static void unregisterAllFileListeners(){ + synchronized(listeners){ + Iterator it = listeners.iterator(); + while(it.hasNext()){ + + CategoryListener obj = it.next(); + if(obj instanceof SingleDrawableViewBase){ + System.out.println(" Removing file"); + it.remove(); + } + } + } + } public KeyCode getHotKeycode() { return KeyCode.getKeyCode(Integer.toString(id)); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java index 19b02e82d1..d1d1a4eb94 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java @@ -129,9 +129,9 @@ public class DrawableDB { volatile private Connection con; - private static final ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock(true); //use fairness policy + private final ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock(true); //use fairness policy - private static final Lock DBLock = rwLock.writeLock(); //using exclusing lock for all db ops for now + private final Lock DBLock = rwLock.writeLock(); //using exclusing lock for all db ops for now static {//make sure sqlite driver is loaded // possibly redundant try { @@ -149,7 +149,7 @@ public class DrawableDB { * MUST always call dbWriteUnLock() as early as possible, in the same thread * where dbWriteLock() was called */ - public static void dbWriteLock() { + public void dbWriteLock() { //Logger.getLogger("LOCK").log(Level.INFO, "Locking " + rwLock.toString()); DBLock.lock(); } @@ -159,7 +159,7 @@ public class DrawableDB { * dbWriteLock(). Call in "finally" block to ensure the lock is always * released. */ - public static void dbWriteUnlock() { + public void dbWriteUnlock() { //Logger.getLogger("LOCK").log(Level.INFO, "UNLocking " + rwLock.toString()); DBLock.unlock(); } From 1ac7f3f5347908d5c6c36dc10853eecefaf9870a Mon Sep 17 00:00:00 2001 From: Brian Carrier Date: Fri, 17 Apr 2015 08:59:09 -0400 Subject: [PATCH 3/7] Changes to make case closing get pushed down into GroupPane to reset tiles. Not complete yet --- .../autopsy/imagegallery/ImageGalleryController.java | 2 +- .../sleuthkit/autopsy/imagegallery/gui/GroupPane.java | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index 59e01aea6e..3658e4f443 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -744,7 +744,7 @@ public final class ImageGalleryController { * netbeans and ImageGallery progress/status */ class PrePopulateDataSourceFiles extends InnerTask { - private Content dataSource; + private final Content dataSource; /** * here we grab by extension but in file_done listener we look at file diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GroupPane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GroupPane.java index 9019694cb4..0b42c07a04 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GroupPane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GroupPane.java @@ -112,9 +112,9 @@ import org.sleuthkit.autopsy.imagegallery.actions.NextUnseenGroup; import org.sleuthkit.autopsy.imagegallery.actions.SwingMenuItemAdapter; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; +import org.sleuthkit.autopsy.imagegallery.grouping.DrawableGroup; import org.sleuthkit.autopsy.imagegallery.grouping.GroupViewMode; import org.sleuthkit.autopsy.imagegallery.grouping.GroupViewState; -import org.sleuthkit.autopsy.imagegallery.grouping.DrawableGroup; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -371,8 +371,10 @@ public class GroupPane extends BorderPane implements GroupView { resetHeaderString(); //and assign fileIDs to gridView if (grouping.get() == null) { - Platform.runLater(gridView.getItems()::clear); - + Platform.runLater(gridView.getItems()::clear); + // @@@ PROBLEM - This is not causing the DrawableCell listener to get called to free it. + // what if we also manuallly flushed the entires in cellMap at this point and called them with setFile(null). + // would need to expose a reset() method on DrawableCell. } else { grouping.get().fileIds().addListener((Observable observable) -> { updateFiles(); @@ -627,6 +629,7 @@ public class GroupPane extends BorderPane implements GroupView { */ void setViewState(GroupViewState viewState) { if (viewState == null) { + this.grouping.set(null); Platform.runLater(() -> { setCenter(null); groupLabel.setText(null); @@ -655,6 +658,7 @@ public class GroupPane extends BorderPane implements GroupView { itemProperty().addListener((ObservableValue observable, Long oldValue, Long newValue) -> { if (oldValue != null) { cellMap.remove(oldValue, DrawableCell.this); + tile.setFile(null); } if (newValue != null) { cellMap.put(newValue, DrawableCell.this); From 93c20657224edc38e99f37a4c1a72118f698c4a3 Mon Sep 17 00:00:00 2001 From: APriestman Date: Fri, 17 Apr 2015 09:09:17 -0400 Subject: [PATCH 4/7] Remote listeners on TagUtils --- .../imagegallery/ImageGalleryController.java | 4 +++- .../autopsy/imagegallery/TagUtils.java | 21 +++++++++++++++++++ .../imagegallery/datamodel/Category.java | 1 - .../imagegallery/datamodel/DrawableFile.java | 1 + .../gui/SingleDrawableViewBase.java | 1 + 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index 29cd329abc..bf1667cb7d 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -344,8 +344,10 @@ public final class ImageGalleryController { */ public synchronized void reset() { LOGGER.info("resetting ImageGalleryControler to initial state."); - selectionModel.clearSelection(); Category.unregisterAllFileListeners(); + TagUtils.unregisterAllFileListeners(); + selectionModel.clearSelection(); + Platform.runLater(() -> { historyManager.clear(); }); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagUtils.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagUtils.java index f6e17c000c..dc9948c6a2 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagUtils.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagUtils.java @@ -20,6 +20,7 @@ package org.sleuthkit.autopsy.imagegallery; import java.util.ArrayList; import java.util.Collection; +import java.util.Iterator; import java.util.List; import java.util.logging.Level; import javafx.event.ActionEvent; @@ -33,6 +34,7 @@ import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.actions.AddDrawableTagAction; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; +import org.sleuthkit.autopsy.imagegallery.gui.SingleDrawableViewBase; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -110,6 +112,25 @@ public class TagUtils { listeners.remove(aThis); } } + + /** + * Clears out all the existing file-type listeners. + * To be called when the case is closed to prevent + * old abstract files files from trying to access the closed + * database. + */ + public static void unregisterAllFileListeners(){ + synchronized(listeners){ + Iterator it = listeners.iterator(); + while(it.hasNext()){ + + TagListener obj = it.next(); + if(obj instanceof SingleDrawableViewBase){ + it.remove(); + } + } + } + } /** * @param tn the value of tn diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java index 2f2fe706c1..bfd91a4e95 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java @@ -100,7 +100,6 @@ public enum Category implements Comparable { CategoryListener obj = it.next(); if(obj instanceof SingleDrawableViewBase){ - System.out.println(" Removing file"); it.remove(); } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java index 1b7867bf48..21c6516519 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java @@ -215,6 +215,7 @@ public abstract class DrawableFile extends AbstractFile } } } catch (TskCoreException ex) { + Logger.getLogger(DrawableFile.class.getName()).log(Level.WARNING, "problem looking up attributes for file ", ex); Logger.getAnonymousLogger().log(Level.WARNING, "problem looking up {0}/{1}" + " " + " for {2}", new Object[]{artType.getDisplayName(), attrType.getDisplayName(), getName()}); } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SingleDrawableViewBase.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SingleDrawableViewBase.java index 7fc20d4ec7..7ff83043af 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SingleDrawableViewBase.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SingleDrawableViewBase.java @@ -359,6 +359,7 @@ public abstract class SingleDrawableViewBase extends AnchorPane implements Drawa if (Objects.equals(fileID, this.fileID) == false) { this.fileID = fileID; disposeContent(); + if (this.fileID == null || Case.isCaseOpen() == false) { Category.unregisterListener(this); TagUtils.unregisterListener(this); From 8ae696c5b6d443923a821c976b4242f47c198a16 Mon Sep 17 00:00:00 2001 From: APriestman Date: Mon, 20 Apr 2015 08:51:56 -0400 Subject: [PATCH 5/7] Reset groupPane properly between cases --- .../imagegallery/ImageGalleryController.java | 3 +-- .../autopsy/imagegallery/TagUtils.java | 19 ---------------- .../imagegallery/datamodel/Category.java | 21 +----------------- .../autopsy/imagegallery/gui/GroupPane.java | 22 ++++++++++++++++--- 4 files changed, 21 insertions(+), 44 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index dd638c18cd..9b426c9a68 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -347,8 +347,6 @@ public final class ImageGalleryController { */ public synchronized void reset() { LOGGER.info("resetting ImageGalleryControler to initial state."); - Category.unregisterAllFileListeners(); - TagUtils.unregisterAllFileListeners(); selectionModel.clearSelection(); Platform.runLater(() -> { @@ -357,6 +355,7 @@ public final class ImageGalleryController { Toolbar.getDefault().reset(); groupManager.clear(); + if (db != null) { db.closeDBCon(); } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagUtils.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagUtils.java index dc9948c6a2..cc7314b113 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagUtils.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagUtils.java @@ -112,25 +112,6 @@ public class TagUtils { listeners.remove(aThis); } } - - /** - * Clears out all the existing file-type listeners. - * To be called when the case is closed to prevent - * old abstract files files from trying to access the closed - * database. - */ - public static void unregisterAllFileListeners(){ - synchronized(listeners){ - Iterator it = listeners.iterator(); - while(it.hasNext()){ - - TagListener obj = it.next(); - if(obj instanceof SingleDrawableViewBase){ - it.remove(); - } - } - } - } /** * @param tn the value of tn diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java index bfd91a4e95..970db12baa 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java @@ -86,26 +86,7 @@ public enum Category implements Comparable { listeners.remove(aThis); } } - - /** - * Clears out all the existing file-type listeners. - * To be called when the case is closed to prevent - * old abstract files files from trying to access the closed - * database. - */ - public static void unregisterAllFileListeners(){ - synchronized(listeners){ - Iterator it = listeners.iterator(); - while(it.hasNext()){ - - CategoryListener obj = it.next(); - if(obj instanceof SingleDrawableViewBase){ - it.remove(); - } - } - } - } - + public KeyCode getHotKeycode() { return KeyCode.getKeyCode(Integer.toString(id)); } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GroupPane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GroupPane.java index 0b42c07a04..8d9daf1482 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GroupPane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GroupPane.java @@ -94,6 +94,7 @@ import org.openide.util.Lookup; import org.openide.util.actions.Presenter; import org.openide.windows.TopComponent; import org.openide.windows.WindowManager; +import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.corecomponentinterfaces.ContextMenuActionsProvider; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ThreadConfined; @@ -372,9 +373,12 @@ public class GroupPane extends BorderPane implements GroupView { //and assign fileIDs to gridView if (grouping.get() == null) { Platform.runLater(gridView.getItems()::clear); - // @@@ PROBLEM - This is not causing the DrawableCell listener to get called to free it. - // what if we also manuallly flushed the entires in cellMap at this point and called them with setFile(null). - // would need to expose a reset() method on DrawableCell. + // Reset the DrawableCell listeners from the old case + if(! Case.isCaseOpen()){ + for(GroupPane.DrawableCell cell:cellMap.values()){ + cell.resetItem(); + } + } } else { grouping.get().fileIds().addListener((Observable observable) -> { updateFiles(); @@ -661,7 +665,15 @@ public class GroupPane extends BorderPane implements GroupView { tile.setFile(null); } if (newValue != null) { + if(cellMap.containsKey(newValue)){ + if(tile != null){ + // Clear out the old value to prevent out-of-date listeners + // from activating. + cellMap.get(newValue).tile.setFile(null); + } + } cellMap.put(newValue, DrawableCell.this); + } }); @@ -673,6 +685,10 @@ public class GroupPane extends BorderPane implements GroupView { super.updateItem(item, empty); tile.setFile(item); } + + void resetItem(){ + tile.setFile(null); + } } private static final List categoryKeyCodes = Arrays.asList(KeyCode.NUMPAD0, KeyCode.NUMPAD1, KeyCode.NUMPAD2, KeyCode.NUMPAD3, KeyCode.NUMPAD4, KeyCode.NUMPAD5, From 383a070e6d1cc72b93945e911cc0ef4b77407398 Mon Sep 17 00:00:00 2001 From: APriestman Date: Mon, 20 Apr 2015 13:19:40 -0400 Subject: [PATCH 6/7] Cleanup --- .../imagegallery/ImageGalleryController.java | 9 +++------ .../sleuthkit/autopsy/imagegallery/TagUtils.java | 2 -- .../autopsy/imagegallery/datamodel/Category.java | 2 -- .../imagegallery/datamodel/DrawableDB.java | 16 +++++++--------- .../imagegallery/datamodel/DrawableFile.java | 3 +-- .../imagegallery/gui/SummaryTablePane.java | 5 ++++- 6 files changed, 15 insertions(+), 22 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index 9b426c9a68..3c4dc5b773 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -307,8 +307,8 @@ public final class ImageGalleryController { private void restartWorker() { if (dbWorkerThread != null) { + // Keep using the same worker thread if one exists return; - //dbWorkerThread.cancelAllTasks(); } dbWorkerThread = new DBWorkerThread(); @@ -335,7 +335,6 @@ public final class ImageGalleryController { // if we add this line icons are made as files are analyzed rather than on demand. // db.addUpdatedFileListener(IconCache.getDefault()); - // @@@ I think we should add a checkhere to see if the thread already exists restartWorker(); historyManager.clear(); groupManager.setDB(db); @@ -348,14 +347,12 @@ public final class ImageGalleryController { public synchronized void reset() { LOGGER.info("resetting ImageGalleryControler to initial state."); selectionModel.clearSelection(); - Platform.runLater(() -> { historyManager.clear(); }); Toolbar.getDefault().reset(); groupManager.clear(); - if (db != null) { db.closeDBCon(); } @@ -627,7 +624,7 @@ public final class ImageGalleryController { DrawableFile drawableFile = DrawableFile.create(getFile(), true); db.updateFile(drawableFile); } catch (NullPointerException ex){ - // This is one of the places where we get an error if the case is closed during processing. + // This is one of the places where we get many errors if the case is closed during processing. // We don't want to print out a ton of exceptions if this is the case. if(Case.isCaseOpen()){ Logger.getLogger(UpdateFileTask.class.getName()).log(Level.SEVERE, "Error in UpdateFile task"); @@ -653,7 +650,7 @@ public final class ImageGalleryController { try{ db.removeFile(getFile().getId()); } catch (NullPointerException ex){ - // This is one of the places where we get an error if the case is closed during processing. + // This is one of the places where we get many errors if the case is closed during processing. // We don't want to print out a ton of exceptions if this is the case. if(Case.isCaseOpen()){ Logger.getLogger(RemoveFileTask.class.getName()).log(Level.SEVERE, "Case was closed out from underneath RemoveFile task"); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagUtils.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagUtils.java index cc7314b113..f6e17c000c 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagUtils.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagUtils.java @@ -20,7 +20,6 @@ package org.sleuthkit.autopsy.imagegallery; import java.util.ArrayList; import java.util.Collection; -import java.util.Iterator; import java.util.List; import java.util.logging.Level; import javafx.event.ActionEvent; @@ -34,7 +33,6 @@ import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.actions.AddDrawableTagAction; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; -import org.sleuthkit.autopsy.imagegallery.gui.SingleDrawableViewBase; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java index 970db12baa..25627626d3 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java @@ -25,7 +25,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.Iterator; import java.util.logging.Level; import javafx.event.ActionEvent; import javafx.event.EventHandler; @@ -38,7 +37,6 @@ import javax.annotation.concurrent.GuardedBy; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.TagUtils; import org.sleuthkit.autopsy.imagegallery.actions.CategorizeAction; -import org.sleuthkit.autopsy.imagegallery.gui.SingleDrawableViewBase; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java index 6fb62a89cf..4229922a53 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java @@ -604,18 +604,13 @@ public class DrawableDB { tr.addUpdatedFile(f.getId()); - } catch (SQLException ex) { + } catch (SQLException | NullPointerException ex) { // This is one of the places where we get an error if the case is closed during processing, - // which doesn't need to be reported. + // which doesn't need to be reported here. if(Case.isCaseOpen()){ LOGGER.log(Level.SEVERE, "failed to insert/update file" + f.getName(), ex); } - } catch (NullPointerException ex) { - if(Case.isCaseOpen()){ - LOGGER.log(Level.SEVERE, "failed to insert/update file" + f.getName(), ex); - } - } - finally { + } finally { dbWriteUnlock(); } } @@ -924,7 +919,10 @@ public class DrawableDB { insertGroupStmt.setString(2, groupBy.attrName.toString()); insertGroupStmt.execute(); } catch (SQLException sQLException) { - LOGGER.log(Level.SEVERE, "Unable to insert group", sQLException); + // Don't need to report it if the case was closed + if(Case.isCaseOpen()){ + LOGGER.log(Level.SEVERE, "Unable to insert group", sQLException); + } } finally { dbWriteUnlock(); } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java index 21c6516519..4b9ad70f05 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java @@ -175,7 +175,7 @@ public abstract class DrawableFile extends AbstractFile Logger.getAnonymousLogger().log(Level.WARNING, "problem looking up " + DrawableAttribute.TAGS.getDisplayName() + " for " + file.getName(), ex); return Collections.emptySet(); } catch (IllegalStateException ex) { - Logger.getAnonymousLogger().log(Level.SEVERE, "there is no case open; failed to look up " + DrawableAttribute.TAGS.getDisplayName() + " for " + file.getName()); + Logger.getAnonymousLogger().log(Level.WARNING, "there is no case open; failed to look up " + DrawableAttribute.TAGS.getDisplayName() + " for " + file.getName()); return null; } } @@ -215,7 +215,6 @@ public abstract class DrawableFile extends AbstractFile } } } catch (TskCoreException ex) { - Logger.getLogger(DrawableFile.class.getName()).log(Level.WARNING, "problem looking up attributes for file ", ex); Logger.getAnonymousLogger().log(Level.WARNING, "problem looking up {0}/{1}" + " " + " for {2}", new Object[]{artType.getDisplayName(), attrType.getDisplayName(), getName()}); } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SummaryTablePane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SummaryTablePane.java index b6627cbab8..241cbc09d9 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SummaryTablePane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SummaryTablePane.java @@ -22,6 +22,7 @@ import java.net.URL; import java.util.Arrays; import java.util.Collection; import java.util.ResourceBundle; +import java.util.logging.Level; import javafx.application.Platform; import javafx.beans.property.SimpleObjectProperty; import javafx.collections.FXCollections; @@ -36,8 +37,10 @@ import javafx.scene.layout.VBox; import javafx.util.Pair; import org.openide.util.Exceptions; import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.FXMLConstructor; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; +import org.sleuthkit.autopsy.imagegallery.TagUtils; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.datamodel.TskCoreException; @@ -111,7 +114,7 @@ public class SummaryTablePane extends AnchorPane implements Category.CategoryLis try { data.add(new Pair<>(cat, ImageGalleryController.getDefault().getGroupManager().countFilesWithCategory(cat))); } catch (TskCoreException ex) { - //Exceptions.printStackTrace(ex); + Logger.getLogger(SummaryTablePane.class.getName()).log(Level.WARNING, "Error performing category file count"); } } Platform.runLater(() -> { From 4f526d39cb2c8af35be3734415e7f4355d5b0975 Mon Sep 17 00:00:00 2001 From: APriestman Date: Mon, 20 Apr 2015 14:36:51 -0400 Subject: [PATCH 7/7] More cleanup --- .../autopsy/imagegallery/ImageGalleryController.java | 8 +++----- .../autopsy/imagegallery/datamodel/DrawableDB.java | 7 ++++++- .../autopsy/imagegallery/datamodel/DrawableFile.java | 6 ++---- .../autopsy/imagegallery/grouping/GroupManager.java | 1 - 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index 3c4dc5b773..40f0779f7f 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -840,11 +840,9 @@ public final class ImageGalleryController { } catch (TskCoreException ex) { Logger.getLogger(PrePopulateDataSourceFiles.class.getName()).log(Level.WARNING, "failed to transfer all database contents", ex); - } catch (IllegalStateException ex) { - Logger.getLogger(PrePopulateDataSourceFiles.class.getName()).log(Level.SEVERE, "Case was closed out from underneath prepopulating database"); - } catch (NullPointerException ex) { - Logger.getLogger(PrePopulateDataSourceFiles.class.getName()).log(Level.SEVERE, "Case was closed out from underneath prepopulating database"); - } + } catch (IllegalStateException | NullPointerException ex) { + Logger.getLogger(PrePopulateDataSourceFiles.class.getName()).log(Level.WARNING, "Case was closed out from underneath prepopulating database"); + } progressHandle.finish(); } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java index 4229922a53..4d822eae7a 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java @@ -1183,7 +1183,12 @@ public class DrawableDB { try { con.setAutoCommit(true); } catch (SQLException ex) { - LOGGER.log(Level.SEVERE, "Error setting auto-commit to true.", ex); + if(Case.isCaseOpen()){ + LOGGER.log(Level.SEVERE, "Error setting auto-commit to true.", ex); + } + else{ + LOGGER.log(Level.SEVERE, "Error setting auto-commit to true - case is closed"); + } } finally { closed = true; dbWriteUnlock(); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java index 4b9ad70f05..a06fcd226c 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java @@ -176,7 +176,7 @@ public abstract class DrawableFile extends AbstractFile return Collections.emptySet(); } catch (IllegalStateException ex) { Logger.getAnonymousLogger().log(Level.WARNING, "there is no case open; failed to look up " + DrawableAttribute.TAGS.getDisplayName() + " for " + file.getName()); - return null; + return Collections.emptySet(); } } @@ -286,9 +286,7 @@ public abstract class DrawableFile extends AbstractFile } catch (TskCoreException ex) { Logger.getLogger(DrawableFile.class.getName()).log(Level.WARNING, "problem looking up category for file " + this.getName(), ex); } catch (IllegalStateException ex){ - // We get here if the case has been closed, in which case we don't need to print out a ton of warnings. - //Logger.getLogger(DrawableFile.class.getName()).log(Level.WARNING, "problem looking up category for file " + this.getName() + - // " - no case open"); + // We get here many times if the case is closed during ingest, so don't print out a ton of warnings. } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java index f94c88ea5c..5586e079e8 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java @@ -564,7 +564,6 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { LOGGER.log(Level.WARNING, "TSK error getting files in Category:" + category.getDisplayName(), ex); throw ex; } catch(IllegalStateException ex){ - // This is one of the places where we get an error if the case is closed during processing. throw new TskCoreException("Case closed while getting files"); }