Skip to content

Commit

Permalink
Merge pull request #596 from jglick/CpsFlowExecution.getNode
Browse files Browse the repository at this point in the history
Robustness of `CpsFlowExecution.getNode`
  • Loading branch information
dwnusbaum authored Nov 4, 2022
2 parents 0b7bf3d + 6868223 commit a8fc49e
Showing 1 changed file with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,9 @@ public void onFailure(Throwable t) {

@Override
public FlowNode getNode(String id) throws IOException {
if (storage == null) {
throw new IOException("storage not yet loaded");
}
return storage.getNode(id);
}

Expand All @@ -1212,11 +1215,19 @@ public Result getResult() {
return result;
}

@Override
public List<Action> loadActions(FlowNode node) throws IOException {
if (storage == null) {
throw new IOException("storage not yet loaded");
}
return storage.loadActions(node);
}

@Override
public void saveActions(FlowNode node, List<Action> actions) throws IOException {
if (storage == null) {
throw new IOException("storage not yet loaded");
}
storage.saveActions(node, actions);
}

Expand Down Expand Up @@ -1263,8 +1274,8 @@ synchronized void onProgramEnd(Outcome outcome) {

// shrink everything into a single new head
try {
if (heads != null) {
FlowHead first = getFirstHead();
FlowHead first = getFirstHead();
if (first != null) {
first.setNewHead(head);
done = true; // After setting the final head
heads.clear();
Expand Down Expand Up @@ -1491,9 +1502,15 @@ private static void cleanUpObjectStreamClassCaches(@NonNull Class<?> clazz) thro
}
}

synchronized FlowHead getFirstHead() {
assert !heads.isEmpty();
return heads.firstEntry().getValue();
synchronized @CheckForNull FlowHead getFirstHead() {
if (heads == null) {
return null;
}
Entry<Integer, FlowHead> firstEntry = heads.firstEntry();
if (firstEntry == null) {
return null;
}
return firstEntry.getValue();
}

List<GraphListener> getListenersToRun() {
Expand Down

0 comments on commit a8fc49e

Please sign in to comment.