Merge pull request #2259 from eugene7646/concurrent_mod_1839

1839 Fixed ConcurrentModificationException in several Autopsy datamodel objects
This commit is contained in:
Richard Cordovano 2016-06-28 17:47:00 -04:00 committed by GitHub
commit 5cb6afb67a
4 changed files with 130 additions and 91 deletions

View File

@ -72,6 +72,7 @@ public class EmailExtracted implements AutopsyVisitableItem {
private final class EmailResults extends Observable {
// NOTE: the map can be accessed by multiple worker threads and needs to be synchronized
private final Map<String, Map<String, List<Long>>> accounts = new LinkedHashMap<>();
EmailResults() {
@ -79,20 +80,28 @@ public class EmailExtracted implements AutopsyVisitableItem {
}
public Set<String> getAccounts() {
synchronized (accounts) {
return accounts.keySet();
}
}
public Set<String> getFolders(String account) {
synchronized (accounts) {
return accounts.get(account).keySet();
}
}
public List<Long> getArtifactIds(String account, String folder) {
synchronized (accounts) {
return accounts.get(account).get(folder);
}
}
@SuppressWarnings("deprecation")
public void update() {
synchronized (accounts) {
accounts.clear();
}
if (skCase == null) {
return;
}
@ -107,6 +116,7 @@ public class EmailExtracted implements AutopsyVisitableItem {
try (CaseDbQuery dbQuery = skCase.executeQuery(query)) {
ResultSet resultSet = dbQuery.getResultSet();
synchronized (accounts) {
while (resultSet.next()) {
final String path = resultSet.getString("value_text"); //NON-NLS
final long artifactId = resultSet.getLong("artifact_id"); //NON-NLS
@ -126,6 +136,7 @@ public class EmailExtracted implements AutopsyVisitableItem {
}
messages.add(artifactId);
}
}
} catch (TskCoreException | SQLException ex) {
logger.log(Level.WARNING, "Cannot initialize email extraction: ", ex); //NON-NLS
}

View File

@ -78,7 +78,7 @@ public class HashsetHits implements AutopsyVisitableItem {
private class HashsetResults extends Observable {
// maps hashset name to list of artifacts for that set
// NOTE: the map can be accessed by multiple worker threads and needs to be synchronized
private final Map<String, Set<Long>> hashSetHitsMap = new LinkedHashMap<>();
HashsetResults() {
@ -86,18 +86,25 @@ public class HashsetHits implements AutopsyVisitableItem {
}
List<String> getSetNames() {
List<String> names = new ArrayList<>(hashSetHitsMap.keySet());
List<String> names;
synchronized (hashSetHitsMap) {
names = new ArrayList<>(hashSetHitsMap.keySet());
}
Collections.sort(names);
return names;
}
Set<Long> getArtifactIds(String hashSetName) {
synchronized (hashSetHitsMap) {
return hashSetHitsMap.get(hashSetName);
}
}
@SuppressWarnings("deprecation")
final void update() {
synchronized (hashSetHitsMap) {
hashSetHitsMap.clear();
}
if (skCase == null) {
return;
@ -113,6 +120,7 @@ public class HashsetHits implements AutopsyVisitableItem {
try (CaseDbQuery dbQuery = skCase.executeQuery(query)) {
ResultSet resultSet = dbQuery.getResultSet();
synchronized (hashSetHitsMap) {
while (resultSet.next()) {
String setName = resultSet.getString("value_text"); //NON-NLS
long artifactId = resultSet.getLong("artifact_id"); //NON-NLS
@ -121,6 +129,7 @@ public class HashsetHits implements AutopsyVisitableItem {
}
hashSetHitsMap.get(setName).add(artifactId);
}
}
} catch (TskCoreException | SQLException ex) {
logger.log(Level.WARNING, "SQL Exception occurred: ", ex); //NON-NLS
}

View File

@ -64,20 +64,28 @@ public class InterestingHits implements AutopsyVisitableItem {
private class InterestingResults extends Observable {
// NOTE: the map can be accessed by multiple worker threads and needs to be synchronized
private final Map<String, Set<Long>> interestingItemsMap = new LinkedHashMap<>();
public List<String> getSetNames() {
List<String> setNames = new ArrayList<>(interestingItemsMap.keySet());
List<String> setNames;
synchronized (interestingItemsMap) {
setNames = new ArrayList<>(interestingItemsMap.keySet());
}
Collections.sort(setNames);
return setNames;
}
public Set<Long> getArtifactIds(String setName) {
synchronized (interestingItemsMap) {
return interestingItemsMap.get(setName);
}
}
public void update() {
synchronized (interestingItemsMap) {
interestingItemsMap.clear();
}
loadArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT);
loadArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT);
setChanged();
@ -103,6 +111,7 @@ public class InterestingHits implements AutopsyVisitableItem {
+ " AND blackboard_artifacts.artifact_type_id=" + artId; //NON-NLS
try (CaseDbQuery dbQuery = skCase.executeQuery(query)) {
synchronized (interestingItemsMap) {
ResultSet resultSet = dbQuery.getResultSet();
while (resultSet.next()) {
String value = resultSet.getString("value_text"); //NON-NLS
@ -112,6 +121,7 @@ public class InterestingHits implements AutopsyVisitableItem {
}
interestingItemsMap.get(value).add(artifactId);
}
}
} catch (TskCoreException | SQLException ex) {
logger.log(Level.WARNING, "SQL Exception occurred: ", ex); //NON-NLS
}

View File

@ -73,33 +73,41 @@ public class KeywordHits implements AutopsyVisitableItem {
private final class KeywordResults extends Observable {
// Map from listName/Type to Map of keyword to set of artifact Ids
private final Map<String, Map<String, Set<Long>>> topLevelMap;
// NOTE: the map can be accessed by multiple worker threads and needs to be synchronized
private final Map<String, Map<String, Set<Long>>> topLevelMap = new LinkedHashMap<>();
KeywordResults() {
topLevelMap = new LinkedHashMap<>();
update();
}
List<String> getListNames() {
synchronized (topLevelMap) {
List<String> names = new ArrayList<>(topLevelMap.keySet());
// this causes the "Single ..." terms to be in the middle of the results,
// which is wierd. Make a custom comparator or do something else to maek them on top
//Collections.sort(names);
return names;
}
}
List<String> getKeywords(String listName) {
List<String> keywords = new ArrayList<>(topLevelMap.get(listName).keySet());
List<String> keywords;
synchronized (topLevelMap) {
keywords = new ArrayList<>(topLevelMap.get(listName).keySet());
}
Collections.sort(keywords);
return keywords;
}
Set<Long> getArtifactIds(String listName, String keyword) {
synchronized (topLevelMap) {
return topLevelMap.get(listName).get(keyword);
}
}
// populate maps based on artifactIds
void populateMaps(Map<Long, Map<Long, String>> artifactIds) {
synchronized (topLevelMap) {
topLevelMap.clear();
// map of list name to keword to artifact IDs
@ -151,6 +159,7 @@ public class KeywordHits implements AutopsyVisitableItem {
}
topLevelMap.putAll(listsMap);
}
}
setChanged();
notifyObservers();