diff --git a/src/main/java/org/jenkinsci/plugins/workflow/graph/StandardGraphLookupView.java b/src/main/java/org/jenkinsci/plugins/workflow/graph/StandardGraphLookupView.java index 5d6e2ffc..f16ebced 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/graph/StandardGraphLookupView.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/graph/StandardGraphLookupView.java @@ -24,20 +24,20 @@ public final class StandardGraphLookupView implements GraphLookupView, GraphList static final String INCOMPLETE = ""; - /** Map the blockStartNode to its endNode, to accellerate a range of operations */ + /** Map the blockStartNode to its endNode, to accelerate a range of operations */ HashMap blockStartToEnd = new HashMap<>(); /** Map a node to its nearest enclosing block */ HashMap nearestEnclosingBlock = new HashMap<>(); - public void clearCache() { + public synchronized void clearCache() { blockStartToEnd.clear(); nearestEnclosingBlock.clear(); } /** Update with a new node added to the flowgraph */ @Override - public void onNewHead(@Nonnull FlowNode newHead) { + public synchronized void onNewHead(@Nonnull FlowNode newHead) { if (newHead instanceof BlockEndNode) { blockStartToEnd.put(((BlockEndNode)newHead).getStartNode().getId(), newHead.getId()); String overallEnclosing = nearestEnclosingBlock.get(((BlockEndNode) newHead).getStartNode().getId()); @@ -87,7 +87,7 @@ public boolean isActive(@Nonnull FlowNode node) { } // Do a brute-force scan for the block end matching the start, caching info along the way for future use - BlockEndNode bruteForceScanForEnd(@Nonnull BlockStartNode start) { + synchronized BlockEndNode bruteForceScanForEnd(@Nonnull BlockStartNode start) { DepthFirstScanner scan = new DepthFirstScanner(); scan.setup(start.getExecution().getCurrentHeads()); for (FlowNode f : scan) { @@ -112,11 +112,8 @@ BlockEndNode bruteForceScanForEnd(@Nonnull BlockStartNode start) { return null; } - - - /** Do a brute-force scan for the enclosing blocks **/ - BlockStartNode bruteForceScanForEnclosingBlock(@Nonnull final FlowNode node) { + synchronized BlockStartNode bruteForceScanForEnclosingBlock(@Nonnull final FlowNode node) { FlowNode current = node; while (!(current instanceof FlowStartNode)) { // Hunt back for enclosing blocks, a potentially expensive operation @@ -157,7 +154,7 @@ BlockStartNode bruteForceScanForEnclosingBlock(@Nonnull final FlowNode node) { @CheckForNull @Override - public BlockEndNode getEndNode(@Nonnull final BlockStartNode startNode) { + public synchronized BlockEndNode getEndNode(@Nonnull final BlockStartNode startNode) { String id = blockStartToEnd.get(startNode.getId()); if (id != null) { @@ -177,7 +174,7 @@ public BlockEndNode getEndNode(@Nonnull final BlockStartNode startNode) { @CheckForNull @Override - public BlockStartNode findEnclosingBlockStart(@Nonnull FlowNode node) { + public synchronized BlockStartNode findEnclosingBlockStart(@Nonnull FlowNode node) { if (node instanceof FlowStartNode || node instanceof FlowEndNode) { return null; }