From 1e1d13f3fbf2a2583999795408a9a3a52bf98430 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Wed, 15 Sep 2021 16:46:37 -0400 Subject: [PATCH 1/7] 7917 address null safety due to removed method --- .../datamodel/CorrelationAttributeUtil.java | 2 +- .../datamodel/AbstractAbstractFileNode.java | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CorrelationAttributeUtil.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CorrelationAttributeUtil.java index 5e64e3994b..c8dfa81f7c 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CorrelationAttributeUtil.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CorrelationAttributeUtil.java @@ -617,7 +617,7 @@ public class CorrelationAttributeUtil { */ public static CorrelationAttributeInstance getCorrAttrForFile(AbstractFile file) { - if (!isSupportedAbstractFileType(file)) { + if (!CentralRepository.isEnabled() || !isSupportedAbstractFileType(file)) { return null; } diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/AbstractAbstractFileNode.java b/Core/src/org/sleuthkit/autopsy/datamodel/AbstractAbstractFileNode.java index ad4f94e1ff..6081d0703c 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/AbstractAbstractFileNode.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/AbstractAbstractFileNode.java @@ -183,7 +183,10 @@ public abstract class AbstractAbstractFileNode extends A Score value = scorePropAndDescr.getLeft(); String descr = scorePropAndDescr.getRight(); List listWithJustFileAttr = new ArrayList<>(); - listWithJustFileAttr.add(CorrelationAttributeUtil.getCorrAttrForFile(content)); + CorrelationAttributeInstance corrInstance = CorrelationAttributeUtil.getCorrAttrForFile(content); + if (corrInstance != null) { + listWithJustFileAttr.add(corrInstance); + } updateSheet(new NodeProperty<>(SCORE.toString(), SCORE.toString(), descr, value), new NodeProperty<>(COMMENT.toString(), COMMENT.toString(), NO_DESCR, getCommentProperty(tags, listWithJustFileAttr)) ); @@ -196,7 +199,10 @@ public abstract class AbstractAbstractFileNode extends A Score value = scorePropAndDescr.getLeft(); String descr = scorePropAndDescr.getRight(); List listWithJustFileAttr = new ArrayList<>(); - listWithJustFileAttr.add(CorrelationAttributeUtil.getCorrAttrForFile(content)); + CorrelationAttributeInstance corrInstance = CorrelationAttributeUtil.getCorrAttrForFile(content); + if (corrInstance != null) { + listWithJustFileAttr.add(corrInstance); + } updateSheet(new NodeProperty<>(SCORE.toString(), SCORE.toString(), descr, value), new NodeProperty<>(COMMENT.toString(), COMMENT.toString(), NO_DESCR, getCommentProperty(tags, listWithJustFileAttr)) ); @@ -206,7 +212,10 @@ public abstract class AbstractAbstractFileNode extends A if (event.getContentID() == content.getId()) { List tags = getAllTagsFromDatabase(); List listWithJustFileAttr = new ArrayList<>(); - listWithJustFileAttr.add(CorrelationAttributeUtil.getCorrAttrForFile(content)); + CorrelationAttributeInstance corrInstance = CorrelationAttributeUtil.getCorrAttrForFile(content); + if (corrInstance != null) { + listWithJustFileAttr.add(corrInstance); + } updateSheet(new NodeProperty<>(COMMENT.toString(), COMMENT.toString(), NO_DESCR, getCommentProperty(tags, listWithJustFileAttr))); } } else if (eventType.equals(NodeSpecificEvents.TRANSLATION_AVAILABLE.toString())) { From 88ddb07388288f79662b0fb2919c04d8f1edc8e7 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Wed, 15 Sep 2021 17:03:22 -0400 Subject: [PATCH 2/7] 7917 remove redundant public declarations from public interface --- .../datamodel/CentralRepository.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepository.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepository.java index a0cd06c26e..43f96ef670 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepository.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepository.java @@ -109,7 +109,7 @@ public interface CentralRepository { * * @throws CentralRepoException */ - public void newDbInfo(String name, String value) throws CentralRepoException; + void newDbInfo(String name, String value) throws CentralRepoException; /** * Set the data source object id for a specific entry in the data_sources @@ -130,7 +130,7 @@ public interface CentralRepository { * * @throws CentralRepoException */ - public String getDbInfo(String name) throws CentralRepoException; + String getDbInfo(String name) throws CentralRepoException; /** * Update the value for a name in the name/value db_info table. @@ -140,7 +140,7 @@ public interface CentralRepository { * * @throws CentralRepoException */ - public void updateDbInfo(String name, String value) throws CentralRepoException; + void updateDbInfo(String name, String value) throws CentralRepoException; /** * Creates new Case in the database @@ -386,7 +386,7 @@ public interface CentralRepository { * @return Number of cases with additional instances of this attribute type * and value. */ - public Long getCountCasesWithOtherInstances(CorrelationAttributeInstance instance) throws CentralRepoException, CorrelationAttributeNormalizationException; + Long getCountCasesWithOtherInstances(CorrelationAttributeInstance instance) throws CentralRepoException, CorrelationAttributeNormalizationException; /** * Retrieves number of data sources in the database. @@ -528,7 +528,7 @@ public interface CentralRepository { * * @throws CentralRepoException */ - public void deleteReferenceSet(int referenceSetID) throws CentralRepoException; + void deleteReferenceSet(int referenceSetID) throws CentralRepoException; /** * Check whether a reference set with the given parameters exists in the @@ -543,7 +543,7 @@ public interface CentralRepository { * * @throws CentralRepoException */ - public boolean referenceSetIsValid(int referenceSetID, String referenceSetName, String version) throws CentralRepoException; + boolean referenceSetIsValid(int referenceSetID, String referenceSetName, String version) throws CentralRepoException; /** * Check whether a reference set with the given name/version is in the @@ -557,7 +557,7 @@ public interface CentralRepository { * * @throws CentralRepoException */ - public boolean referenceSetExists(String referenceSetName, String version) throws CentralRepoException; + boolean referenceSetExists(String referenceSetName, String version) throws CentralRepoException; /** * Check if the given file hash is in this reference set. Only searches the @@ -570,7 +570,7 @@ public interface CentralRepository { * * @throws CentralRepoException */ - public boolean isFileHashInReferenceSet(String hash, int referenceSetID) throws CentralRepoException, CorrelationAttributeNormalizationException; + boolean isFileHashInReferenceSet(String hash, int referenceSetID) throws CentralRepoException, CorrelationAttributeNormalizationException; /** * Retrieves the given file HashHitInfo if the given file hash is in this @@ -596,7 +596,7 @@ public interface CentralRepository { * * @return true if the hash is found in the reference set */ - public boolean isValueInReferenceSet(String value, int referenceSetID, int correlationTypeID) throws CentralRepoException, CorrelationAttributeNormalizationException; + boolean isValueInReferenceSet(String value, int referenceSetID, int correlationTypeID) throws CentralRepoException, CorrelationAttributeNormalizationException; /** * Is the artifact known as bad according to the reference entries? @@ -805,7 +805,7 @@ public interface CentralRepository { * * @throws CentralRepoException */ - public void upgradeSchema() throws CentralRepoException, SQLException, IncompatibleCentralRepoException; + void upgradeSchema() throws CentralRepoException, SQLException, IncompatibleCentralRepoException; /** * Gets an exclusive lock (if applicable). Will return the lock if @@ -818,7 +818,7 @@ public interface CentralRepository { * @throws CentralRepoException if the coordination service is running but * we fail to get the lock */ - public CoordinationService.Lock getExclusiveMultiUserDbLock() throws CentralRepoException; + CoordinationService.Lock getExclusiveMultiUserDbLock() throws CentralRepoException; /** * Process the Artifact instance in the EamDb @@ -849,7 +849,7 @@ public interface CentralRepository { * * @throws CentralRepoException */ - public void processSelectClause(String selectClause, InstanceTableCallback instanceTableCallback) throws CentralRepoException; + void processSelectClause(String selectClause, InstanceTableCallback instanceTableCallback) throws CentralRepoException; /** * Executes an INSERT/UPDATE/DELETE sql as a prepared statement, on the From 98f65468058d55dfbf96c0bbbca11f5069505420 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Wed, 15 Sep 2021 17:51:14 -0400 Subject: [PATCH 3/7] 7917 re-order closing of result to be before closing of statement --- .../datamodel/RdbmsCentralRepo.java | 78 +++++++++---------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java index 149a5fc398..fcc3b26f7f 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java @@ -212,8 +212,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error getting value for name.", ex); } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } @@ -505,8 +505,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error getting case details.", ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } @@ -565,8 +565,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error getting case details.", ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } @@ -602,8 +602,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error getting all cases.", ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } @@ -787,8 +787,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error getting data source.", ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } @@ -851,8 +851,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error getting data source.", ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } @@ -885,8 +885,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error getting all data sources.", ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } @@ -1390,8 +1390,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error getting artifact instances by artifactType and artifactValue.", ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } return artifactInstances; @@ -1432,8 +1432,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error getting count of artifact instances by artifactType and artifactValue.", ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } @@ -1488,8 +1488,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error counting unique caseDisplayName/dataSource tuples having artifactType and artifactValue.", ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } @@ -1540,8 +1540,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error counting unique caseDisplayName/dataSource tuples having artifactType and artifactValue.", ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } } @@ -1567,8 +1567,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error counting data sources.", ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } @@ -1614,8 +1614,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error counting artifact instances by caseName/dataSource.", ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } @@ -1941,8 +1941,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error getting notable artifact instances.", ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } @@ -2012,8 +2012,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error getting notable artifact instances.", ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } @@ -2099,9 +2099,9 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error getting/setting artifact instance knownStatus=" + knownStatus.getName(), ex); // NON-NLS } finally { + CentralRepoDbUtil.closeResultSet(resultSet); CentralRepoDbUtil.closeStatement(preparedUpdate); CentralRepoDbUtil.closeStatement(preparedQuery); - CentralRepoDbUtil.closeResultSet(resultSet); CentralRepoDbUtil.closeConnection(conn); } } @@ -2141,8 +2141,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error getting count of notable artifact instances.", ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } @@ -2196,8 +2196,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error getting notable artifact instances.", ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } @@ -2248,8 +2248,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error getting notable artifact instances.", ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } @@ -2392,8 +2392,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error determining if value (" + normalizeValued + ") is in reference set " + referenceSetID, ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } } @@ -2431,8 +2431,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error determining if value (" + normalizeValued + ") is in reference set " + referenceSetID, ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } @@ -2475,8 +2475,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error determining if artifact is notable by reference.", ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } @@ -2516,8 +2516,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error getting all artifact instances from instances table", ex); } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } } @@ -2562,8 +2562,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error getting all artifact instances from instances table", ex); } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } } @@ -2601,8 +2601,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error running query", ex); } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } } @@ -2687,8 +2687,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error inserting new organization.", ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(generatedKeys); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } } @@ -2720,8 +2720,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error getting all organizations.", ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } } @@ -2753,8 +2753,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error getting organization by id.", ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } } @@ -2905,9 +2905,9 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error executing query when attempting to delete organization by id.", ex); // NON-NLS } finally { + CentralRepoDbUtil.closeResultSet(resultSet); CentralRepoDbUtil.closeStatement(checkIfUsedStatement); CentralRepoDbUtil.closeStatement(deleteOrgStatement); - CentralRepoDbUtil.closeResultSet(resultSet); CentralRepoDbUtil.closeConnection(conn); } } @@ -2969,9 +2969,9 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error inserting new global set.", ex); // NON-NLS } finally { + CentralRepoDbUtil.closeResultSet(resultSet); CentralRepoDbUtil.closeStatement(preparedStatement1); CentralRepoDbUtil.closeStatement(preparedStatement2); - CentralRepoDbUtil.closeResultSet(resultSet); CentralRepoDbUtil.closeConnection(conn); } } @@ -3006,8 +3006,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error getting reference set by id.", ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement1); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement1); CentralRepoDbUtil.closeConnection(conn); } } @@ -3045,8 +3045,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error getting reference sets.", ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement1); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement1); CentralRepoDbUtil.closeConnection(conn); } return results; @@ -3123,8 +3123,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { throw new CentralRepoException("Error testing whether reference set exists (name: " + referenceSetName + " version: " + version, ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement1); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement1); CentralRepoDbUtil.closeConnection(conn); } } @@ -3214,8 +3214,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error getting reference instances by type and value.", ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement1); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement1); CentralRepoDbUtil.closeConnection(conn); } @@ -3295,9 +3295,9 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error inserting new correlation type.", ex); // NON-NLS } finally { + CentralRepoDbUtil.closeResultSet(resultSet); CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeStatement(preparedStatementQuery); - CentralRepoDbUtil.closeResultSet(resultSet); CentralRepoDbUtil.closeConnection(conn); } return typeId; @@ -3349,9 +3349,9 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error inserting new correlation type.", ex); // NON-NLS } finally { + CentralRepoDbUtil.closeResultSet(resultSet); CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeStatement(preparedStatementQuery); - CentralRepoDbUtil.closeResultSet(resultSet); CentralRepoDbUtil.closeConnection(conn); } return typeId; @@ -3397,8 +3397,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error getting enabled correlation types.", ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } } @@ -3432,8 +3432,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error getting supported correlation types.", ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } } @@ -3526,8 +3526,8 @@ abstract class RdbmsCentralRepo implements CentralRepository { } catch (SQLException ex) { throw new CentralRepoException("Error getting correlation type by id.", ex); // NON-NLS } finally { - CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeResultSet(resultSet); + CentralRepoDbUtil.closeStatement(preparedStatement); CentralRepoDbUtil.closeConnection(conn); } } From e7eb5788ae6ee6c10a12233e3bd4d2f1a5aebfcd Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Wed, 15 Sep 2021 18:13:33 -0400 Subject: [PATCH 4/7] 7917 refine comment on new count case method --- .../datamodel/CentralRepository.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepository.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepository.java index 43f96ef670..3dc57dc333 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepository.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepository.java @@ -376,15 +376,20 @@ public interface CentralRepository { Long getCountUniqueCaseDataSourceTuplesHavingTypeValue(CorrelationAttributeInstance.Type aType, String value) throws CentralRepoException, CorrelationAttributeNormalizationException; /** - * Retrieves number of unique cases which have correlation attributes other + * Retrieves number of unique cases which have correlation attributes * * which are not associated with the specified file with the same type and - * value. + * value. Gets the count of cases that have an instance of a given + * correlation attribute. + * + * This count will ignore the specified instance of the correlation + * attribute and any other instances of this correlation attribute existing + * on the same object. * * @param instance The instance having its cases with other occurrences * counted. * - * @return Number of cases with additional instances of this attribute type - * and value. + * @return Number of cases with additional instances of this + * CorrelationAttributeInstance. */ Long getCountCasesWithOtherInstances(CorrelationAttributeInstance instance) throws CentralRepoException, CorrelationAttributeNormalizationException; From ede4d8adf18ed29169cf5aa4dc6a43a51d2d4dad Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Wed, 15 Sep 2021 18:14:26 -0400 Subject: [PATCH 5/7] 7917 refine comment on new count case method --- .../centralrepository/datamodel/CentralRepository.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepository.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepository.java index 3dc57dc333..975ae93b46 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepository.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepository.java @@ -376,10 +376,8 @@ public interface CentralRepository { Long getCountUniqueCaseDataSourceTuplesHavingTypeValue(CorrelationAttributeInstance.Type aType, String value) throws CentralRepoException, CorrelationAttributeNormalizationException; /** - * Retrieves number of unique cases which have correlation attributes * - * which are not associated with the specified file with the same type and - * value. Gets the count of cases that have an instance of a given - * correlation attribute. + * Gets the count of cases that have an instance of a given correlation + * attribute. * * This count will ignore the specified instance of the correlation * attribute and any other instances of this correlation attribute existing From 5119b2e739404f1891aef0b64deeaf8c8718e1f7 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Wed, 15 Sep 2021 18:39:33 -0400 Subject: [PATCH 6/7] 7917 fix spelling of consistency --- .../centralrepository/AddEditCentralRepoCommentAction.java | 2 +- .../eventlisteners/CaseEventListener.java | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/AddEditCentralRepoCommentAction.java b/Core/src/org/sleuthkit/autopsy/centralrepository/AddEditCentralRepoCommentAction.java index b1069ba5b9..1bef9719bb 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/AddEditCentralRepoCommentAction.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/AddEditCentralRepoCommentAction.java @@ -67,7 +67,7 @@ public final class AddEditCentralRepoCommentAction extends AbstractAction { addToDatabase = true; final List md5CorrelationAttr = CorrelationAttributeUtil.makeCorrAttrsForSearch(file); if (!md5CorrelationAttr.isEmpty()) { - //for an abstract file the 'list' of attributes will be a single attribute or empty and is returning a list for consistancy with other makeCorrAttrsForSearch methods per 7852 + //for an abstract file the 'list' of attributes will be a single attribute or empty and is returning a list for consistency with other makeCorrAttrsForSearch methods per 7852 correlationAttributeInstance = md5CorrelationAttr.get(0); } else { correlationAttributeInstance = null; diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/CaseEventListener.java b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/CaseEventListener.java index 4fe5467bef..39d93bd76a 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/CaseEventListener.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/CaseEventListener.java @@ -322,7 +322,7 @@ public final class CaseEventListener implements PropertyChangeListener { private void setContentKnownStatus(AbstractFile af, TskData.FileKnown knownStatus) { final List md5CorrelationAttr = CorrelationAttributeUtil.makeCorrAttrsForSearch(af); if (!md5CorrelationAttr.isEmpty()) { - //for an abstract file the 'list' of attributes will be a single attribute or empty and is returning a list for consistancy with other makeCorrAttrsForSearch methods per 7852 + //for an abstract file the 'list' of attributes will be a single attribute or empty and is returning a list for consistency with other makeCorrAttrsForSearch methods per 7852 // send update to Central Repository db try { dbManager.setAttributeInstanceKnownStatus(md5CorrelationAttr.get(0), knownStatus); @@ -436,7 +436,6 @@ public final class CaseEventListener implements PropertyChangeListener { } } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Failed to obtain tags manager for case.", ex); - return; } } @@ -569,9 +568,9 @@ public final class CaseEventListener implements PropertyChangeListener { if (!hasTagWithConflictingKnownStatus) { Content taggedContent = contentTag.getContent(); if (taggedContent instanceof AbstractFile) { - final List eamArtifact = CorrelationAttributeUtil.makeCorrAttrsForSearch((AbstractFile) taggedContent); + final List eamArtifact = CorrelationAttributeUtil.makeCorrAttrsForSearch(taggedContent); if (!eamArtifact.isEmpty()) { - //for an abstract file the 'list' of attributes will be a single attribute or empty and is returning a list for consistancy with other makeCorrAttrsForSearch methods per 7852 + //for an abstract file the 'list' of attributes will be a single attribute or empty and is returning a list for consistency with other makeCorrAttrsForSearch methods per 7852 CentralRepository.getInstance().setAttributeInstanceKnownStatus(eamArtifact.get(0), tagName.getKnownStatus()); } } From db8c65b972651082a4e49aba7aa8d7ec6f5b32a3 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Wed, 15 Sep 2021 19:01:58 -0400 Subject: [PATCH 7/7] 7917 adjust comments to be more helpfull --- .../datamodel/RdbmsCentralRepo.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java index fcc3b26f7f..1442a0ec62 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java @@ -1,7 +1,7 @@ /* * Central Repository * - * Copyright 2015-2020 Basis Technology Corp. + * Copyright 2015-2021 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -1501,7 +1501,7 @@ abstract class RdbmsCentralRepo implements CentralRepository { Long instanceCount = 0L; if (instance != null) { Long sourceObjID = instance.getFileObjectId(); - //We know that instances have a correlation case but that correlation case may have a null ID if it is not in the CR, although it should be. + //The CorrelationAttributeInstance will have a CorrelationCase, however that correlation case's ID will be null if the case is not in the CR. int correlationCaseId = instance.getCorrelationCase().getID(); String normalizedValue = CorrelationAttributeNormalizer.normalize(instance.getCorrelationType(), instance.getCorrelationValue()); Connection conn = connect(); @@ -1510,12 +1510,11 @@ abstract class RdbmsCentralRepo implements CentralRepository { ResultSet resultSet = null; try { if (correlationCaseId > 0 && sourceObjID != null) { - //the current case is in the CR we can ignore this case source file to ensure we don't count the current item - //this will also work regardless of the instance itself being a database instance + //The CorrelationCase is in the Central repository. String sql - = "SELECT count(*) FROM (SELECT DISTINCT case_id FROM " + = "SELECT count(*) FROM (SELECT DISTINCT case_id FROM " //Get distinct cases with a matching value in the corresponding table from the central repository. + tableName - + " WHERE value=? AND NOT (file_obj_id=? AND case_id=?)) AS " + + " WHERE value=? AND NOT (file_obj_id=? AND case_id=?)) AS " //Check the file_obj_id AND case_id to ensure we ignore the currently selected instance. + tableName + "_other_case_count"; preparedStatement = conn.prepareStatement(sql); @@ -1523,10 +1522,9 @@ abstract class RdbmsCentralRepo implements CentralRepository { preparedStatement.setLong(2, sourceObjID); preparedStatement.setInt(3, correlationCaseId); } else { - //the current case is not in the CR so the current instance can't be so we can just count all other cases with the instance - //we won't know if it exists elsewhere in this case because this case is not in the CR + //The CorrelationCase is NOT in the central repository. String sql - = "SELECT count(*) FROM (SELECT DISTINCT case_id FROM " + = "SELECT count(*) FROM (SELECT DISTINCT case_id FROM " //Get all distinct cases with a matching value in the corresponding table from the central repository. + tableName + " WHERE value=? AS " + tableName