diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/ContentTagAddedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/ContentTagAddedEvent.java index 966138434a..c724dfa104 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/ContentTagAddedEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/ContentTagAddedEvent.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2015 Basis Technology Corp. + * Copyright 2015-2018 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,6 +21,7 @@ package org.sleuthkit.autopsy.casemodule.events; import java.io.Serializable; import javax.annotation.concurrent.Immutable; import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TskCoreException; @@ -41,10 +42,10 @@ public class ContentTagAddedEvent extends TagAddedEvent implements S * * @return ContentTag that was added * - * @throws IllegalStateException + * @throws NoCurrentCaseException * @throws TskCoreException */ - ContentTag getTagByID() throws IllegalStateException, TskCoreException { - return Case.getCurrentCase().getServices().getTagsManager().getContentTagByTagID(getTagID()); + ContentTag getTagByID() throws NoCurrentCaseException, TskCoreException { + return Case.getOpenCase().getServices().getTagsManager().getContentTagByTagID(getTagID()); } } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/TagAddedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/TagAddedEvent.java index 1f679c47a3..6d7ebb4f9c 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/TagAddedEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/TagAddedEvent.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2015 Basis Technology Corp. + * Copyright 2015-2018 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,6 +20,7 @@ package org.sleuthkit.autopsy.casemodule.events; import java.io.Serializable; import java.util.logging.Level; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.events.AutopsyEvent; import org.sleuthkit.datamodel.Tag; @@ -84,7 +85,7 @@ abstract class TagAddedEvent extends AutopsyEvent implements Seri try { tag = getTagByID(); return tag; - } catch (IllegalStateException | TskCoreException ex) { + } catch (NoCurrentCaseException | TskCoreException ex) { Logger.getLogger(TagAddedEvent.class.getName()).log(Level.SEVERE, "Error doing lazy load for remote event", ex); //NON-NLS return null; } @@ -98,8 +99,8 @@ abstract class TagAddedEvent extends AutopsyEvent implements Seri * * @return the Tag based on the saved tag id * - * @throws IllegalStateException + * @throws NoCurrentCaseException * @throws TskCoreException */ - abstract T getTagByID() throws IllegalStateException, TskCoreException; + abstract T getTagByID() throws NoCurrentCaseException, TskCoreException; } diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/accounts/Accounts.java b/Core/src/org/sleuthkit/autopsy/datamodel/accounts/Accounts.java index b3e8a9a1b1..422a0cff0a 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/accounts/Accounts.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/accounts/Accounts.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2011-2017 Basis Technology Corp. + * Copyright 2011-2018 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -59,6 +59,7 @@ import org.openide.util.NbBundle; import org.openide.util.Utilities; import org.openide.util.lookup.Lookups; import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.corecomponents.DataResultTopComponent; import org.sleuthkit.autopsy.datamodel.AutopsyItemVisitor; import org.sleuthkit.autopsy.datamodel.AutopsyVisitableItem; @@ -240,7 +241,7 @@ final public class Accounts implements AutopsyVisitableItem { * that is already closed. */ try { - Case.getCurrentCase(); + Case.getOpenCase(); /** * Even with the check above, it is still possible that * the case will be closed in a different thread before @@ -252,7 +253,7 @@ final public class Accounts implements AutopsyVisitableItem { && eventData.getBlackboardArtifactType().getTypeID() == ARTIFACT_TYPE.TSK_ACCOUNT.getTypeID()) { reviewStatusBus.post(eventData); } - } catch (IllegalStateException notUsed) { + } catch (NoCurrentCaseException notUsed) { // Case is closed, do nothing. } } else if (eventType.equals(IngestManager.IngestJobEvent.COMPLETED.toString()) @@ -264,9 +265,9 @@ final public class Accounts implements AutopsyVisitableItem { * that is already closed. */ try { - Case.getCurrentCase(); + Case.getOpenCase(); refresh(true); - } catch (IllegalStateException notUsed) { + } catch (NoCurrentCaseException notUsed) { // Case is closed, do nothing. } } else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) { @@ -368,7 +369,7 @@ final public class Accounts implements AutopsyVisitableItem { * that is already closed. */ try { - Case.getCurrentCase(); + Case.getOpenCase(); /** * Even with the check above, it is still possible that * the case will be closed in a different thread before @@ -380,7 +381,7 @@ final public class Accounts implements AutopsyVisitableItem { && eventData.getBlackboardArtifactType().getTypeID() == ARTIFACT_TYPE.TSK_ACCOUNT.getTypeID()) { reviewStatusBus.post(eventData); } - } catch (IllegalStateException notUsed) { + } catch (NoCurrentCaseException notUsed) { // Case is closed, do nothing. } } else if (eventType.equals(IngestManager.IngestJobEvent.COMPLETED.toString()) @@ -392,10 +393,10 @@ final public class Accounts implements AutopsyVisitableItem { * that is already closed. */ try { - Case.getCurrentCase(); + Case.getOpenCase(); refresh(true); - } catch (IllegalStateException notUsed) { + } catch (NoCurrentCaseException notUsed) { // Case is closed, do nothing. } } else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) { @@ -517,7 +518,7 @@ final public class Accounts implements AutopsyVisitableItem { * that is already closed. */ try { - Case.getCurrentCase(); + Case.getOpenCase(); /** * Even with the check above, it is still possible that * the case will be closed in a different thread before @@ -529,7 +530,7 @@ final public class Accounts implements AutopsyVisitableItem { && eventData.getBlackboardArtifactType().getTypeID() == ARTIFACT_TYPE.TSK_ACCOUNT.getTypeID()) { reviewStatusBus.post(eventData); } - } catch (IllegalStateException notUsed) { + } catch (NoCurrentCaseException notUsed) { // Case is closed, do nothing. } } else if (eventType.equals(IngestManager.IngestJobEvent.COMPLETED.toString()) @@ -541,10 +542,10 @@ final public class Accounts implements AutopsyVisitableItem { * that is already closed. */ try { - Case.getCurrentCase(); + Case.getOpenCase(); refresh(true); - } catch (IllegalStateException notUsed) { + } catch (NoCurrentCaseException notUsed) { // Case is closed, do nothing. } } else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) { @@ -651,7 +652,7 @@ final public class Accounts implements AutopsyVisitableItem { * that is already closed. */ try { - Case.getCurrentCase(); + Case.getOpenCase(); /** * Even with the check above, it is still possible that * the case will be closed in a different thread before @@ -663,7 +664,7 @@ final public class Accounts implements AutopsyVisitableItem { && eventData.getBlackboardArtifactType().getTypeID() == ARTIFACT_TYPE.TSK_ACCOUNT.getTypeID()) { reviewStatusBus.post(eventData); } - } catch (IllegalStateException notUsed) { + } catch (NoCurrentCaseException notUsed) { // Case is closed, do nothing. } } else if (eventType.equals(IngestManager.IngestJobEvent.COMPLETED.toString()) @@ -675,10 +676,10 @@ final public class Accounts implements AutopsyVisitableItem { * that is already closed. */ try { - Case.getCurrentCase(); + Case.getOpenCase(); refresh(true); - } catch (IllegalStateException notUsed) { + } catch (NoCurrentCaseException notUsed) { // Case is closed, do nothing. } } else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) { @@ -862,7 +863,7 @@ final public class Accounts implements AutopsyVisitableItem { * that is already closed. */ try { - Case.getCurrentCase(); + Case.getOpenCase(); /** * Even with the check above, it is still possible that * the case will be closed in a different thread before @@ -874,7 +875,7 @@ final public class Accounts implements AutopsyVisitableItem { && eventData.getBlackboardArtifactType().getTypeID() == ARTIFACT_TYPE.TSK_ACCOUNT.getTypeID()) { reviewStatusBus.post(eventData); } - } catch (IllegalStateException notUsed) { + } catch (NoCurrentCaseException notUsed) { // Case is closed, do nothing. } } else if (eventType.equals(IngestManager.IngestJobEvent.COMPLETED.toString()) @@ -886,10 +887,10 @@ final public class Accounts implements AutopsyVisitableItem { * that is already closed. */ try { - Case.getCurrentCase(); + Case.getOpenCase(); refresh(true); - } catch (IllegalStateException notUsed) { + } catch (NoCurrentCaseException notUsed) { // Case is closed, do nothing. } } else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) { diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbSearchAction.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbSearchAction.java index 61c2fe699e..7d4ec611b6 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbSearchAction.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbSearchAction.java @@ -24,6 +24,7 @@ import org.openide.util.HelpCtx; import org.openide.util.NbBundle; import org.openide.util.actions.CallableSystemAction; import org.openide.windows.WindowManager; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.datamodel.ContentUtils; import org.sleuthkit.autopsy.directorytree.HashSearchProvider; import org.sleuthkit.datamodel.AbstractFile; @@ -118,8 +119,12 @@ public class HashDbSearchAction extends CallableSystemAction implements HashSear * performAction. */ @Override + @NbBundle.Messages ({ + "HashDbSearchAction.noOpenCase.errMsg=No open case available." + }) public void performAction() { // Make sure at least 1 file has an md5 hash + try { if (file != null && HashDbSearcher.countFilesMd5Hashed() > 0) { doSearch(); } else { @@ -129,6 +134,12 @@ public class HashDbSearchAction extends CallableSystemAction implements HashSear NbBundle.getMessage(this.getClass(), "HashDbSearchAction.dlgMsg.title"), JOptionPane.ERROR_MESSAGE); } + } catch (NoCurrentCaseException ex) { + JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), + Bundle.HashDbSearchAction_noOpenCase_errMsg(), + NbBundle.getMessage(this.getClass(), "HashDbSearchAction.dlgMsg.title"), + JOptionPane.ERROR_MESSAGE); + } } private void doSearch() { diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbSearchPanel.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbSearchPanel.java index 9f7642c69f..4dac4864c7 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbSearchPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbSearchPanel.java @@ -32,6 +32,7 @@ import javax.swing.table.DefaultTableModel; import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; import javax.swing.text.PlainDocument; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.ingest.IngestManager; /** @@ -290,16 +291,27 @@ class HashDbSearchPanel extends javax.swing.JPanel implements ActionListener { * Search through all tsk_files to find ones with the same hashes as the * hashes given. */ + @NbBundle.Messages ({ + "HashDbSearchPanel.noOpenCase.errMsg=No open case available." + }) boolean search() { // Check if any hashed have been entered if (hashTable.getRowCount() != 0) { // Make sure at least 1 file has an md5 hash - if (HashDbSearcher.countFilesMd5Hashed() > 0) { - return doSearch(); - } else { + try { + if (HashDbSearcher.countFilesMd5Hashed() > 0) { + return doSearch(); + } else { + JOptionPane.showMessageDialog(this, + NbBundle.getMessage(this.getClass(), + "HashDbSearchPanel.noFilesHaveMD5HashMsg"), + NbBundle.getMessage(this.getClass(), "HashDbSearchPanel.dlgMsg.title"), + JOptionPane.ERROR_MESSAGE); + return false; + } + } catch (NoCurrentCaseException ex) { JOptionPane.showMessageDialog(this, - NbBundle.getMessage(this.getClass(), - "HashDbSearchPanel.noFilesHaveMD5HashMsg"), + Bundle.HashDbSearchPanel_noOpenCase_errMsg(), NbBundle.getMessage(this.getClass(), "HashDbSearchPanel.dlgMsg.title"), JOptionPane.ERROR_MESSAGE); return false; diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbSearcher.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbSearcher.java index 628f99f78e..213400925f 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbSearcher.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbSearcher.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2011 Basis Technology Corp. + * Copyright 2011-2018 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,9 +22,12 @@ import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.logging.Level; import javax.swing.SwingWorker; import org.netbeans.api.progress.ProgressHandle; import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; +import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.FsContent; import org.sleuthkit.datamodel.SleuthkitCase; @@ -34,7 +37,7 @@ import org.sleuthkit.datamodel.SleuthkitCase; * the same content. */ class HashDbSearcher { - + private static final Logger logger = Logger.getLogger(HashDbSearcher.class.getName()); /** * Given a string hash value, find all files with that hash. * @@ -42,8 +45,8 @@ class HashDbSearcher { * * @return a List of all FsContent with the given hash */ - static List findFilesByMd5(String md5Hash) { - final Case currentCase = Case.getCurrentCase(); + static List findFilesByMd5(String md5Hash) throws NoCurrentCaseException { + final Case currentCase = Case.getOpenCase(); final SleuthkitCase skCase = currentCase.getSleuthkitCase(); return skCase.findFilesByMd5(md5Hash); } @@ -56,7 +59,7 @@ class HashDbSearcher { * * @return a Map of md5 hashes mapped to the list of files hit */ - static Map> findFilesBymd5(List md5Hash) { + static Map> findFilesBymd5(List md5Hash) throws NoCurrentCaseException { Map> map = new LinkedHashMap>(); for (String md5 : md5Hash) { List files = findFilesByMd5(md5); @@ -69,7 +72,7 @@ class HashDbSearcher { // Same as above, but with a given ProgressHandle to accumulate and StringWorker to check if cancelled - static Map> findFilesBymd5(List md5Hash, ProgressHandle progress, SwingWorker worker) { + static Map> findFilesBymd5(List md5Hash, ProgressHandle progress, SwingWorker worker) throws NoCurrentCaseException { Map> map = new LinkedHashMap>(); if (!worker.isCancelled()) { progress.switchToDeterminate(md5Hash.size()); @@ -101,9 +104,14 @@ class HashDbSearcher { */ static List findFiles(FsContent file) { String md5; - if ((md5 = file.getMd5Hash()) != null) { - return findFilesByMd5(md5); - } else { + try { + if ((md5 = file.getMd5Hash()) != null) { + return findFilesByMd5(md5); + } else { + return Collections.emptyList(); + } + } catch (NoCurrentCaseException ex) { + logger.log(Level.SEVERE, "Exception while getting open case.", ex); return Collections.emptyList(); } } @@ -114,8 +122,8 @@ class HashDbSearcher { * * @return true if the search feature is ready. */ - static boolean allFilesMd5Hashed() { - final Case currentCase = Case.getCurrentCase(); + static boolean allFilesMd5Hashed() throws NoCurrentCaseException { + final Case currentCase = Case.getOpenCase(); final SleuthkitCase skCase = currentCase.getSleuthkitCase(); return skCase.allFilesMd5Hashed(); } @@ -125,8 +133,8 @@ class HashDbSearcher { * * @return the number of files with an MD5 */ - static int countFilesMd5Hashed() { - final Case currentCase = Case.getCurrentCase(); + static int countFilesMd5Hashed() throws NoCurrentCaseException { + final Case currentCase = Case.getOpenCase(); final SleuthkitCase skCase = currentCase.getSleuthkitCase(); return skCase.countFilesMd5Hashed(); } diff --git a/Core/src/org/sleuthkit/autopsy/report/FileReportText.java b/Core/src/org/sleuthkit/autopsy/report/FileReportText.java index c9a239cf0a..71cccf96ed 100644 --- a/Core/src/org/sleuthkit/autopsy/report/FileReportText.java +++ b/Core/src/org/sleuthkit/autopsy/report/FileReportText.java @@ -31,6 +31,7 @@ import org.sleuthkit.autopsy.coreutils.Logger; import org.openide.util.NbBundle; import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.TskCoreException; @@ -71,13 +72,15 @@ class FileReportText implements FileReportModule { if (out != null) { try { out.close(); - Case.getCurrentCase().addReport(reportPath, NbBundle.getMessage(this.getClass(), + Case.getOpenCase().addReport(reportPath, NbBundle.getMessage(this.getClass(), "FileReportText.getName.text"), ""); } catch (IOException ex) { logger.log(Level.WARNING, "Could not close output writer when ending report.", ex); //NON-NLS } catch (TskCoreException ex) { String errorMessage = String.format("Error adding %s to case as a report", reportPath); //NON-NLS logger.log(Level.SEVERE, errorMessage, ex); + } catch (NoCurrentCaseException ex) { + logger.log(Level.SEVERE, "Exception while getting open case.", ex); } } }