From 9df62728289764d75b81d110769b24a9e177a3cd Mon Sep 17 00:00:00 2001 From: gmedici Date: Wed, 5 Oct 2022 10:47:43 -0400 Subject: [PATCH] Some various simple fixes * Fix `SimpleRetryPolicy` for NPE when `context.getLastThrowable()` is `null` Set `NO_RECOVERY` if it cannot retry and that exception is null * Fix `RecoverAnnotationRecoveryHandlerTests` for a proper return value in the composite `recoverByComposedRetryableAnnotationName` annotation test --- .../org/springframework/retry/policy/SimpleRetryPolicy.java | 2 +- .../annotation/RecoverAnnotationRecoveryHandlerTests.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/springframework/retry/policy/SimpleRetryPolicy.java b/src/main/java/org/springframework/retry/policy/SimpleRetryPolicy.java index 162c154..fa57162 100644 --- a/src/main/java/org/springframework/retry/policy/SimpleRetryPolicy.java +++ b/src/main/java/org/springframework/retry/policy/SimpleRetryPolicy.java @@ -210,7 +210,7 @@ public class SimpleRetryPolicy implements RetryPolicy { public boolean canRetry(RetryContext context) { Throwable t = context.getLastThrowable(); boolean can = (t == null || retryForException(t)) && context.getRetryCount() < getMaxAttempts(); - if (!can && !this.recoverableClassifier.classify(t)) { + if (!can && t != null && !this.recoverableClassifier.classify(t)) { context.setAttribute(RetryContext.NO_RECOVERY, true); } else { diff --git a/src/test/java/org/springframework/retry/annotation/RecoverAnnotationRecoveryHandlerTests.java b/src/test/java/org/springframework/retry/annotation/RecoverAnnotationRecoveryHandlerTests.java index fb87627..62d8dda 100644 --- a/src/test/java/org/springframework/retry/annotation/RecoverAnnotationRecoveryHandlerTests.java +++ b/src/test/java/org/springframework/retry/annotation/RecoverAnnotationRecoveryHandlerTests.java @@ -43,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * @author Randell Callahan * @author Nathanaƫl Roberts * @author Maksim Kita - * @Author Gianluca Medici + * @author Gianluca Medici */ public class RecoverAnnotationRecoveryHandlerTests { @@ -661,7 +661,7 @@ public class RecoverAnnotationRecoveryHandlerTests { } public int barRecover(Throwable throwable, String name) { - return 2; + return 4; } }