Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3650] Fix potential NPE in DiagramNavigator and Node #3657

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ More existing APIs will be migrated to this new common pattern.
- 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/3531[#3531] [diagram] Fix unnecessary edges label re render

- 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();
}
Comment on lines +109 to +111
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used this PR as an opportunity to add this method that would be helpful for some downstream tests.


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
Loading