diff --git a/plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecution.java b/plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecution.java index 9d1b3db80..4f9344355 100644 --- a/plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecution.java +++ b/plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecution.java @@ -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); } @@ -1212,11 +1215,19 @@ public Result getResult() { return result; } + @Override public List 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 actions) throws IOException { + if (storage == null) { + throw new IOException("storage not yet loaded"); + } storage.saveActions(node, actions); } @@ -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(); @@ -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 firstEntry = heads.firstEntry(); + if (firstEntry == null) { + return null; + } + return firstEntry.getValue(); } List getListenersToRun() {