2323 */
2424package org .jenkinsci .plugins .workflow .steps ;
2525
26+ import hudson .Util ;
27+ import hudson .model .Result ;
2628import jenkins .model .CauseOfInterruption ;
2729
2830import java .io .Serializable ;
@@ -49,31 +51,41 @@ public abstract class BodyExecution implements Future<Object>, Serializable {
4951 public abstract Collection <StepExecution > getCurrentExecutions ();
5052
5153 /**
52- * Attempts to cancel an executing body block.
53- *
54- * <p>
55- * If the body has finished executing, or is cancelled already, the attempt will
56- * fail. This method is asynchronous. There's no guarantee that the cancellation
57- * has happened or completed before this method returns.
58- *
59- * @return false if the task cannot be cancelled.
54+ * @deprecated use {@link #cancel(Throwable)} with {@link FlowInterruptedException}
6055 */
61- public abstract boolean cancel (CauseOfInterruption ... causes );
56+ @ Deprecated
57+ public boolean cancel (CauseOfInterruption ... causes ) {
58+ if (Util .isOverridden (BodyExecution .class , getClass (), "cancel" , Throwable .class )) {
59+ return cancel (new FlowInterruptedException (Result .ABORTED , true , causes ));
60+ } else {
61+ throw new AbstractMethodError ("Override cancel(Throwable) from " + getClass ());
62+ }
63+ }
6264
6365 /**
64- * @deprecated
65- * Use other overloaded forms of the cancel method to provide richer context.
66+ * @deprecated use {@link #cancel(Throwable)} to provide richer context
6667 */
68+ @ Deprecated
6769 public boolean cancel (boolean b ) {
68- return cancel (new Exception ( ));
70+ return cancel (new FlowInterruptedException ( Result . ABORTED , true ));
6971 }
7072
7173 /**
72- * Convenience method around {@link #cancel(CauseOfInterruption...)} in case
73- * the cause is a random exception.
74+ * Attempts to cancel an executing body block.
75+ *
76+ * <p>
77+ * If the body has finished executing, or is cancelled already, the attempt will
78+ * fail. This method is asynchronous. There's no guarantee that the cancellation
79+ * has happened or completed before this method returns.
80+ * @param t reason for cancellation; typically a {@link FlowInterruptedException}
81+ * @return false if the task cannot be cancelled.
7482 */
7583 public boolean cancel (Throwable t ) {
76- return cancel (new ExceptionCause (t ));
84+ if (Util .isOverridden (BodyExecution .class , getClass (), "cancel" , CauseOfInterruption [].class )) {
85+ return cancel (new ExceptionCause (t ));
86+ } else {
87+ throw new AbstractMethodError ("Override cancel(Throwable) from " + getClass ());
88+ }
7789 }
7890
7991 private static final long serialVersionUID = 1L ;
0 commit comments