diff --git a/bindings/java/src/org/sleuthkit/datamodel/AbstractContent.java b/bindings/java/src/org/sleuthkit/datamodel/AbstractContent.java index caf1773869774c85118568428d1ae3ca13379850..50afea2be2b2dc50a86ce6f58d27f7789ab3662a 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/AbstractContent.java +++ b/bindings/java/src/org/sleuthkit/datamodel/AbstractContent.java @@ -39,8 +39,8 @@ public abstract class AbstractContent implements Content { private final SleuthkitCase db; private final long objId; private final String name; - private Content parent; - private String uniquePath; + private volatile Content parent; + private volatile String uniquePath; protected long parentId; private volatile boolean hasChildren; private volatile boolean checkedHasChildren; @@ -69,17 +69,22 @@ public String getName() { * interleaving forward slashes). */ @Override - public synchronized String getUniquePath() throws TskCoreException { + public String getUniquePath() throws TskCoreException { + // It is possible that multiple threads could be doing this calculation + // simultaneously, but it's worth the potential extra processing to prevent deadlocks. if (uniquePath == null) { - uniquePath = ""; + String tempUniquePath = ""; if (!name.isEmpty()) { - uniquePath = "/" + getName(); + tempUniquePath = "/" + getName(); } Content myParent = getParent(); if (myParent != null) { - uniquePath = myParent.getUniquePath() + uniquePath; + tempUniquePath = myParent.getUniquePath() + tempUniquePath; } + + // Don't update uniquePath until it is complete. + uniquePath = tempUniquePath; } return uniquePath; } @@ -111,7 +116,9 @@ public int getChildrenCount() throws TskCoreException { } @Override - public synchronized Content getParent() throws TskCoreException { + public Content getParent() throws TskCoreException { + // It is possible that multiple threads could be doing this calculation + // simultaneously, but it's worth the potential extra processing to prevent deadlocks. if (parent == null) { ObjectInfo parentInfo; parentInfo = db.getParentInfo(this); diff --git a/bindings/java/src/org/sleuthkit/datamodel/BlackboardArtifact.java b/bindings/java/src/org/sleuthkit/datamodel/BlackboardArtifact.java index 0848c7470f61c39466522016e306bb914ffb20d6..591f0fae8fa3af11356098f12b57cf6314f1a4f1 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/BlackboardArtifact.java +++ b/bindings/java/src/org/sleuthkit/datamodel/BlackboardArtifact.java @@ -59,8 +59,8 @@ public class BlackboardArtifact implements Content { private final SleuthkitCase sleuthkitCase; private final List<BlackboardAttribute> attrsCache = new ArrayList<BlackboardAttribute>(); private boolean loadedCacheFromDb = false; - private Content parent; - private String uniquePath; + private volatile Content parent; + private volatile String uniquePath; private byte[] contentBytes = null; @@ -391,21 +391,27 @@ public void addAttributes(Collection<BlackboardAttribute> attributes) throws Tsk * @throws org.sleuthkit.datamodel.TskCoreException */ @Override - public synchronized String getUniquePath() throws TskCoreException { - - // Return the path of the parrent file + public String getUniquePath() throws TskCoreException { + // Return the path of the parent file + // It is possible that multiple threads could be doing this calculation + // simultaneously, but it's worth the potential extra processing to prevent deadlocks. if (uniquePath == null) { - uniquePath = ""; + String tempUniquePath = ""; Content myParent = getParent(); if (myParent != null) { - uniquePath = myParent.getUniquePath(); + tempUniquePath = myParent.getUniquePath(); } + + // Don't update uniquePath until it is complete. + uniquePath = tempUniquePath; } return uniquePath; } @Override - public synchronized Content getParent() throws TskCoreException { + public Content getParent() throws TskCoreException { + // It is possible that multiple threads could be doing this calculation + // simultaneously, but it's worth the potential extra processing to prevent deadlocks. if (parent == null) { ObjectInfo parentInfo; parentInfo = getSleuthkitCase().getParentInfo(this); diff --git a/bindings/java/src/org/sleuthkit/datamodel/FsContent.java b/bindings/java/src/org/sleuthkit/datamodel/FsContent.java index aa4bb739d06a0bad71b343ab9766c75f5f38511a..7e022bc81776885bf73c65fb3e38f368e44613f2 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/FsContent.java +++ b/bindings/java/src/org/sleuthkit/datamodel/FsContent.java @@ -38,7 +38,7 @@ public abstract class FsContent extends AbstractFile { private static final Logger logger = Logger.getLogger(FsContent.class.getName()); - private String uniquePath; + private volatile String uniquePath; private List<String> metaDataText = null; private volatile FileSystem parentFileSystem; @@ -259,7 +259,9 @@ public Content getDataSource() throws TskCoreException { * @throws TskCoreException if there is an error querying the case database. */ @Override - public synchronized String getUniquePath() throws TskCoreException { + public String getUniquePath() throws TskCoreException { + // It is possible that multiple threads could be doing this calculation + // simultaneously, but it's worth the potential extra processing to prevent deadlocks. if (uniquePath == null) { StringBuilder sb = new StringBuilder(); sb.append(getFileSystem().getUniquePath()); diff --git a/bindings/java/src/org/sleuthkit/datamodel/Volume.java b/bindings/java/src/org/sleuthkit/datamodel/Volume.java index 75778e23e56dc42d880370e9bf7516abce164e2c..8350105e5abd072ade826f7bc11e78e0db691bda 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/Volume.java +++ b/bindings/java/src/org/sleuthkit/datamodel/Volume.java @@ -34,7 +34,7 @@ public class Volume extends AbstractContent { private long flags; private String desc; private volatile long volumeHandle = 0; - private String uniquePath; + private volatile String uniquePath; private static ResourceBundle bundle = ResourceBundle.getBundle("org.sleuthkit.datamodel.Bundle"); /** @@ -107,18 +107,23 @@ public long getSize() { } @Override - public synchronized String getUniquePath() throws TskCoreException { + public String getUniquePath() throws TskCoreException { + // It is possible that multiple threads could be doing this calculation + // simultaneously, but it's worth the potential extra processing to prevent deadlocks. if(uniquePath == null) { - uniquePath = ""; + String tempUniquePath = ""; String name = getName(); if (!name.isEmpty()) { - uniquePath = "/vol_" + name; //NON-NLS + tempUniquePath = "/vol_" + name; //NON-NLS } Content myParent = getParent(); if (myParent != null) { - uniquePath = myParent.getUniquePath() + uniquePath; + tempUniquePath = myParent.getUniquePath() + tempUniquePath; } + + // Don't update uniquePath until it is complete. + uniquePath = tempUniquePath; } return uniquePath; }