Skip to content

Commit

Permalink
[3650] Fix potential NPE in DiagramNavigator and Node
Browse files Browse the repository at this point in the history
Bug: #3650
Signed-off-by: Gwendal Daniel <[email protected]>
  • Loading branch information
gdaniel committed Jun 20, 2024
1 parent a0110f2 commit 43fba15
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ More existing APIs will be migrated to this new common pattern.
- https://github.com/eclipse-sirius/sirius-web/issues/3628[#3628] [sirius-web] Restore support for expand all and reveal in the explorer
- https://github.com/eclipse-sirius/sirius-web/issues/3616[#3616] [diagram] Fix potential exceptions due to duplicate keys in diagram event processing
- https://github.com/eclipse-sirius/sirius-web/issues/3624[#3624] [diagram] Fix an issue where the header separator does not fill the entire width of the node
- https://github.com/eclipse-sirius/sirius-web/issues/3650[#3650] [diagram] Fix potential NPE in DiagramNavigator and Node toString method

=== New Features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.eclipse.sirius.components.diagrams.tests.navigation;

import java.text.MessageFormat;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -105,6 +106,10 @@ public EdgeNavigator edgeWithEdgeDescriptionId(String edgeDescriptionId) {
return new EdgeNavigator(edges.get(0), this.cache);
}

public Collection<Node> findAllNodes() {
return this.cache.getIdToNode().values();
}

public int findDiagramNodeCount() {
return this.cache.getDiagramNodeCount();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,14 @@ private void cacheNode(Node node, List<Node> ancestors) {
this.idToNode.put(node.getId(), node);
List<Node> nodesWithDescription = this.nodeDescriptionIdToNodes.computeIfAbsent(node.getDescriptionId(), k -> new ArrayList<>());
nodesWithDescription.add(node);
List<Node> nodesWithLabel = this.labelToNodes.computeIfAbsent(node.getInsideLabel().getText(), k -> new ArrayList<>());
nodesWithLabel.add(node);
if (node.getInsideLabel() != null) {
List<Node> nodesWithLabel = this.labelToNodes.computeIfAbsent(node.getInsideLabel().getText(), k -> new ArrayList<>());
nodesWithLabel.add(node);
}
node.getOutsideLabels().forEach(outsideLabel -> {
List<Node> nodesWithLabel = this.labelToNodes.computeIfAbsent(outsideLabel.text(), k -> new ArrayList<>());
nodesWithLabel.add(node);
});
List<Node> nodesWithTargetObjectLabel = this.targetObjectLabelToNodes.computeIfAbsent(node.getTargetObjectLabel(), k -> new ArrayList<>());
nodesWithTargetObjectLabel.add(node);
List<Node> nodesWithTargetObjectId = this.targetObjectIdToNodes.computeIfAbsent(node.getTargetObjectId(), k -> new ArrayList<>());
Expand All @@ -150,9 +156,10 @@ private void cacheEdge(Edge edge) {
edgesWithTargetObjectLabel.add(edge);
List<Edge> edgesWithTargetObjectId = this.targetObjectIdToEdges.computeIfAbsent(edge.getTargetObjectId(), k -> new ArrayList<>());
edgesWithTargetObjectId.add(edge);

List<Edge> edgesWithLabel = this.labelToEdges.computeIfAbsent(edge.getCenterLabel().getText(), k -> new ArrayList<>());
edgesWithLabel.add(edge);
if (edge.getCenterLabel() != null) {
List<Edge> edgesWithLabel = this.labelToEdges.computeIfAbsent(edge.getCenterLabel().getText(), k -> new ArrayList<>());
edgesWithLabel.add(edge);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,13 @@ public boolean isPinned() {

@Override
public String toString() {
String insideLabelText = "";
if (this.insideLabel != null) {
insideLabelText = this.insideLabel.getText();
}
String pattern = "{0} '{'id: {1}, targetObjectId: {2}, targetObjectKind: {3}, targetObjectLabel: {4}, descriptionId: {5}, state: {6}, label: {7}, styleType: {8}, borderNodeCount: {9}, childNodeCount: {10}'}'";
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.id, this.targetObjectId, this.targetObjectKind, this.targetObjectLabel, this.descriptionId, this.state,
this.insideLabel.getText(), this.style.getClass().getSimpleName(), this.borderNodes.size(), this.childNodes.size());
insideLabelText, this.style.getClass().getSimpleName(), this.borderNodes.size(), this.childNodes.size());
}

/**
Expand Down

0 comments on commit 43fba15

Please sign in to comment.