3030 * @author Dave Syer
3131 * @author Mahmoud Ben Hassine
3232 * @author JiWon Seo
33+ * @author Yanming Zhou
3334 *
3435 */
3536public class ExitStatus implements Serializable , Comparable <ExitStatus > {
@@ -73,7 +74,7 @@ public class ExitStatus implements Serializable, Comparable<ExitStatus> {
7374
7475 private final String exitDescription ;
7576
76- @ Nullable private Throwable exitException ;
77+ private final @ Nullable Throwable exitException ;
7778
7879 /**
7980 * Constructor that accepts the exit code and sets the exit description to an empty
@@ -91,9 +92,7 @@ public ExitStatus(String exitCode) {
9192 * @param exitDescription The exit description to be used for the {@link ExitStatus}.
9293 */
9394 public ExitStatus (String exitCode , String exitDescription ) {
94- super ();
95- this .exitCode = exitCode ;
96- this .exitDescription = exitDescription == null ? "" : exitDescription ;
95+ this (exitCode , exitDescription , null );
9796 }
9897
9998 /**
@@ -104,8 +103,9 @@ public ExitStatus(String exitCode, String exitDescription) {
104103 * @param exitException The exit exception to the {@link ExitStatus}.
105104 * @since 6.0.3
106105 */
107- public ExitStatus (String exitCode , String exitDescription , Throwable exitException ) {
108- this (exitCode , exitDescription );
106+ public ExitStatus (String exitCode , @ Nullable String exitDescription , @ Nullable Throwable exitException ) {
107+ this .exitCode = exitCode ;
108+ this .exitDescription = exitDescription == null ? "" : exitDescription ;
109109 this .exitException = exitException ;
110110 }
111111
@@ -157,14 +157,14 @@ public String getExitDescription() {
157157 * @return a new {@link ExitStatus} combining the current value and the argument
158158 * provided.
159159 */
160- public ExitStatus and (ExitStatus status ) {
160+ public ExitStatus and (@ Nullable ExitStatus status ) {
161161 if (status == null ) {
162162 return this ;
163163 }
164164 ExitStatus result = addExitDescription (status .exitDescription );
165165 Throwable exitException = status .exitException ;
166166 if (exitException != null ) {
167- result . setExitException (exitException );
167+ result = result . withExitException (exitException );
168168 }
169169 if (compareTo (status ) < 0 ) {
170170 result = result .replaceExitCode (status .exitCode );
@@ -287,13 +287,12 @@ public ExitStatus addExitDescription(String description) {
287287 }
288288
289289 /**
290- * Public setter for the exit exception.
290+ * Create new instance with the exit exception.
291291 * @param exitException the last exception that caused the step to exit
292- * @since 6.0.3
292+ * @since 6.0.4
293293 */
294- public ExitStatus setExitException (Throwable exitException ) {
295- this .exitException = exitException ;
296- return this ;
294+ public ExitStatus withExitException (Throwable exitException ) {
295+ return new ExitStatus (this .exitCode , this .exitDescription , exitException );
297296 }
298297
299298 /**
@@ -314,9 +313,8 @@ public ExitStatus addExitDescription(Throwable throwable) {
314313 * evaluated.
315314 * @return {@code true} if the value matches a known exit code.
316315 */
317- public static boolean isNonDefaultExitStatus (ExitStatus status ) {
318- return status == null || status .getExitCode () == null
319- || status .getExitCode ().equals (ExitStatus .COMPLETED .getExitCode ())
316+ public static boolean isNonDefaultExitStatus (@ Nullable ExitStatus status ) {
317+ return status == null || status .getExitCode ().equals (ExitStatus .COMPLETED .getExitCode ())
320318 || status .getExitCode ().equals (ExitStatus .EXECUTING .getExitCode ())
321319 || status .getExitCode ().equals (ExitStatus .FAILED .getExitCode ())
322320 || status .getExitCode ().equals (ExitStatus .NOOP .getExitCode ())
0 commit comments