diff --git a/src/main/java/org/springframework/retry/annotation/AnnotationAwareRetryOperationsInterceptor.java b/src/main/java/org/springframework/retry/annotation/AnnotationAwareRetryOperationsInterceptor.java index 10b5dcba..c4cbde54 100644 --- a/src/main/java/org/springframework/retry/annotation/AnnotationAwareRetryOperationsInterceptor.java +++ b/src/main/java/org/springframework/retry/annotation/AnnotationAwareRetryOperationsInterceptor.java @@ -352,7 +352,7 @@ private RetryPolicy getRetryPolicy(Annotation retryable, boolean stateless) { @SuppressWarnings("unchecked") Class[] includes = (Class[]) attrs.get("value"); String exceptionExpression = (String) attrs.get("exceptionExpression"); - boolean hasExpression = StringUtils.hasText(exceptionExpression); + boolean hasExceptionExpression = StringUtils.hasText(exceptionExpression); if (includes.length == 0) { @SuppressWarnings("unchecked") Class[] value = (Class[]) attrs.get("retryFor"); @@ -370,14 +370,14 @@ private RetryPolicy getRetryPolicy(Annotation retryable, boolean stateless) { parsedExpression = null; } } - final Expression expression = parsedExpression; + final Expression maxAttExpression = parsedExpression; SimpleRetryPolicy simple = null; if (includes.length == 0 && excludes.length == 0) { - simple = hasExpression + simple = hasExceptionExpression ? new ExpressionRetryPolicy(resolve(exceptionExpression)).withBeanFactory(this.beanFactory) : new SimpleRetryPolicy(); - if (expression != null) { - simple.maxAttemptsSupplier(() -> evaluate(expression, Integer.class, stateless)); + if (maxAttExpression != null) { + simple.maxAttemptsSupplier(() -> evaluate(maxAttExpression, Integer.class, stateless)); } else { simple.setMaxAttempts(maxAttempts); @@ -392,16 +392,16 @@ private RetryPolicy getRetryPolicy(Annotation retryable, boolean stateless) { } boolean retryNotExcluded = includes.length == 0; if (simple == null) { - if (hasExpression) { + if (hasExceptionExpression) { simple = new ExpressionRetryPolicy(maxAttempts, policyMap, true, resolve(exceptionExpression), retryNotExcluded) .withBeanFactory(this.beanFactory); } else { simple = new SimpleRetryPolicy(maxAttempts, policyMap, true, retryNotExcluded); - if (expression != null) { - simple.maxAttemptsSupplier(() -> evaluate(expression, Integer.class, stateless)); - } + } + if (maxAttExpression != null) { + simple.maxAttemptsSupplier(() -> evaluate(maxAttExpression, Integer.class, stateless)); } } @SuppressWarnings("unchecked") diff --git a/src/test/java/org/springframework/retry/annotation/EnableRetryTests.java b/src/test/java/org/springframework/retry/annotation/EnableRetryTests.java index 63b0c2e9..f1e6518a 100644 --- a/src/test/java/org/springframework/retry/annotation/EnableRetryTests.java +++ b/src/test/java/org/springframework/retry/annotation/EnableRetryTests.java @@ -560,22 +560,22 @@ public static class RuntimeConfigs { int count = 0; public int getMaxAttempts() { - count++; + this.count++; return 3; } public long getInitial() { - count++; + this.count++; return 1000; } public long getMax() { - count++; + this.count++; return 2000; } public double getMult() { - count++; + this.count++; return 1.2; } @@ -639,10 +639,10 @@ protected static class RecoverableService { @Retryable(retryFor = RuntimeException.class, noRetryFor = IllegalStateException.class, notRecoverable = { IllegalArgumentException.class, IllegalStateException.class }) public void service() { - if (this.count++ >= 3 && count < 7) { + if (this.count++ >= 3 && this.count < 7) { throw new IllegalArgumentException("Planned"); } - else if (count > 6) { + else if (this.count > 6) { throw new IllegalStateException("Planned"); } else { @@ -801,7 +801,7 @@ public void service2() { throw new RuntimeException("this cannot be retried"); } - @Retryable(exceptionExpression = "@exceptionChecker.${retryMethod}(#root)", + @Retryable(exceptionExpression = "@exceptionChecker.${retryMethod}(#root)", retryFor = RuntimeException.class, maxAttemptsExpression = "@integerFiveBean", backoff = @Backoff(delayExpression = "${one}", maxDelayExpression = "@integerFiveBean", multiplierExpression = "${onePointOne}")) public void service3() {