Skip to content

Commit 4619273

Browse files
committed
Synchronize access to workspace tree node methods
Should fix the issue where duplicate tree paths are created in some instances
1 parent 816877f commit 4619273

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

recaf-ui/src/main/java/software/coley/recaf/ui/control/tree/WorkspaceTreeNode.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public WorkspaceTreeNode(PathNode<?> path) {
3232
* @return {@code true} when removal is a success.
3333
* {@code false} if nothing was removed.
3434
*/
35-
public boolean removeNodeByPath(@Nonnull PathNode<?> path) {
35+
public synchronized boolean removeNodeByPath(@Nonnull PathNode<?> path) {
3636
// Call from root node only.
3737
WorkspaceTreeNode root = this;
3838
while (root.getParent() instanceof WorkspaceTreeNode parentNode)
@@ -65,7 +65,7 @@ public boolean removeNodeByPath(@Nonnull PathNode<?> path) {
6565
* @return Node containing the path in the tree.
6666
*/
6767
@Nonnull
68-
public WorkspaceTreeNode getOrCreateNodeByPath(@Nonnull PathNode<?> path) {
68+
public synchronized WorkspaceTreeNode getOrCreateNodeByPath(@Nonnull PathNode<?> path) {
6969
// Call from root node only.
7070
WorkspaceTreeNode root = this;
7171
while (root.getParent() instanceof WorkspaceTreeNode parentNode)
@@ -85,7 +85,7 @@ public WorkspaceTreeNode getOrCreateNodeByPath(@Nonnull PathNode<?> path) {
8585
*/
8686
@Nullable
8787
@SuppressWarnings("deprecation")
88-
public WorkspaceTreeNode getNodeByPath(@Nonnull PathNode<?> path) {
88+
public synchronized WorkspaceTreeNode getNodeByPath(@Nonnull PathNode<?> path) {
8989
PathNode<?> value = getValue();
9090
if (path.equals(value))
9191
return this;
@@ -102,7 +102,7 @@ public WorkspaceTreeNode getNodeByPath(@Nonnull PathNode<?> path) {
102102
*/
103103
@Nullable
104104
@SuppressWarnings("deprecation")
105-
public WorkspaceTreeNode getFirstChild() {
105+
public synchronized WorkspaceTreeNode getFirstChild() {
106106
return getChildren().isEmpty()
107107
? null : getChildren().getFirst() instanceof WorkspaceTreeNode node
108108
? node : null;
@@ -136,7 +136,6 @@ public String toString() {
136136
return getClass().getSimpleName() + "[" + getValue().toString() + "]";
137137
}
138138

139-
140139
/**
141140
* Get/insert a {@link WorkspaceTreeNode} holding the given {@link PathNode} from/to the tree model.
142141
*

0 commit comments

Comments
 (0)