Skip to content

Commit b127fb1

Browse files
committed
Synchronize Target Node
The org.eclipse.pde.internal.genericeditor.target.extension.model.Node is accessed in a concurrent way but its internal implementation uses unsynchronized mutator methods. This add synchronized to all methods and copy internal datastructures to make the class at least concurrent-safe and prevent unsyncronized data structures to escape the scope of a node.
1 parent 0b123e0 commit b127fb1

File tree

1 file changed

+14
-18
lines changed
  • ui/org.eclipse.pde.genericeditor.extension/src/org/eclipse/pde/internal/genericeditor/target/extension/model

1 file changed

+14
-18
lines changed

ui/org.eclipse.pde.genericeditor.extension/src/org/eclipse/pde/internal/genericeditor/target/extension/model/Node.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,52 +30,48 @@ public class Node {
3030
private List<Node> childNodes;
3131
private Node parentNode;
3232

33-
public int getOffsetStart() {
33+
public synchronized int getOffsetStart() {
3434
return offsetStart;
3535
}
3636

37-
public void setOffsetStart(int offsetStart) {
37+
public synchronized void setOffsetStart(int offsetStart) {
3838
this.offsetStart = offsetStart;
3939
}
4040

41-
public int getOffsetEnd() {
41+
public synchronized int getOffsetEnd() {
4242
return offsetEnd;
4343
}
4444

45-
public void setOffsetEnd(int offsetEnd) {
45+
public synchronized void setOffsetEnd(int offsetEnd) {
4646
this.offsetEnd = offsetEnd;
4747
}
4848

49-
public String getNodeTag() {
49+
public synchronized String getNodeTag() {
5050
return nodeTag;
5151
}
5252

53-
public void setNodeTag(String nodeTag) {
53+
public synchronized void setNodeTag(String nodeTag) {
5454
this.nodeTag = nodeTag;
5555
}
5656

57-
public List<Node> getChildNodes() {
58-
List<Node> nodes = childNodes;
59-
return nodes == null ? new ArrayList<>() : nodes;
57+
public synchronized List<Node> getChildNodes() {
58+
return childNodes == null ? List.of() : List.copyOf(childNodes);
6059
}
6160

62-
public List<Node> getChildNodesByTag(String nodeTag) {
63-
return childNodes.stream().filter(n -> Objects.equals(n.getNodeTag(), nodeTag)).collect(Collectors.toList());
61+
public synchronized List<Node> getChildNodesByTag(String nodeTag) {
62+
return getChildNodes().stream().filter(n -> Objects.equals(n.getNodeTag(), nodeTag))
63+
.collect(Collectors.toList());
6464
}
6565

66-
public void addChildNode(Node child) {
66+
public synchronized void addChildNode(Node child) {
6767
if (childNodes == null) {
6868
childNodes = new ArrayList<>();
6969
}
7070
childNodes.add(child);
71-
child.setParentNode(this);
71+
child.parentNode = this;
7272
}
7373

74-
public Node getParentNode() {
74+
public synchronized Node getParentNode() {
7575
return parentNode;
7676
}
77-
78-
private void setParentNode(Node parentNode) {
79-
this.parentNode = parentNode;
80-
}
8177
}

0 commit comments

Comments
 (0)