Skip to content

Commit

Permalink
Synchronize access to workspace tree node methods
Browse files Browse the repository at this point in the history
Should fix the issue where duplicate tree paths are created in some instances
  • Loading branch information
Col-E committed Jul 17, 2024
1 parent 62a5bd3 commit 06f06d7
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public WorkspaceTreeNode(PathNode<?> path) {
* @return {@code true} when removal is a success.
* {@code false} if nothing was removed.
*/
public boolean removeNodeByPath(@Nonnull PathNode<?> path) {
public synchronized boolean removeNodeByPath(@Nonnull PathNode<?> path) {
// Call from root node only.
WorkspaceTreeNode root = this;
while (root.getParent() instanceof WorkspaceTreeNode parentNode)
Expand Down Expand Up @@ -65,7 +65,7 @@ public boolean removeNodeByPath(@Nonnull PathNode<?> path) {
* @return Node containing the path in the tree.
*/
@Nonnull
public WorkspaceTreeNode getOrCreateNodeByPath(@Nonnull PathNode<?> path) {
public synchronized WorkspaceTreeNode getOrCreateNodeByPath(@Nonnull PathNode<?> path) {
// Call from root node only.
WorkspaceTreeNode root = this;
while (root.getParent() instanceof WorkspaceTreeNode parentNode)
Expand All @@ -85,7 +85,7 @@ public WorkspaceTreeNode getOrCreateNodeByPath(@Nonnull PathNode<?> path) {
*/
@Nullable
@SuppressWarnings("deprecation")
public WorkspaceTreeNode getNodeByPath(@Nonnull PathNode<?> path) {
public synchronized WorkspaceTreeNode getNodeByPath(@Nonnull PathNode<?> path) {
PathNode<?> value = getValue();
if (path.equals(value))
return this;
Expand All @@ -102,7 +102,7 @@ public WorkspaceTreeNode getNodeByPath(@Nonnull PathNode<?> path) {
*/
@Nullable
@SuppressWarnings("deprecation")
public WorkspaceTreeNode getFirstChild() {
public synchronized WorkspaceTreeNode getFirstChild() {
return getChildren().isEmpty()
? null : getChildren().getFirst() instanceof WorkspaceTreeNode node
? node : null;
Expand Down Expand Up @@ -136,7 +136,6 @@ public String toString() {
return getClass().getSimpleName() + "[" + getValue().toString() + "]";
}


/**
* Get/insert a {@link WorkspaceTreeNode} holding the given {@link PathNode} from/to the tree model.
*
Expand Down

0 comments on commit 06f06d7

Please sign in to comment.