Skip to content

Commit

Permalink
refactor: Common static analysis issues
Browse files Browse the repository at this point in the history
  • Loading branch information
natedanner and TeamModerne committed Apr 24, 2024
1 parent 9442435 commit 7e9e216
Show file tree
Hide file tree
Showing 35 changed files with 83 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public class BinaryExceptionClassifierBuilder {
* Building notation type (white list or black list) - null: has not selected yet -
* true: white list - false: black list
*/
private Boolean isWhiteList = null;
private Boolean isWhiteList;

private boolean traverseCauses = false;
private boolean traverseCauses;

private final List<Class<? extends Throwable>> exceptionClasses = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public final void setDelegate(Object delegate) {
this.invoker = MethodInvokerUtils
.getMethodInvokerByAnnotation(org.springframework.classify.annotation.Classifier.class, delegate);
if (this.invoker == null) {
this.invoker = MethodInvokerUtils.<C, T>getMethodInvokerForSingleArgument(delegate);
this.invoker = MethodInvokerUtils.getMethodInvokerForSingleArgument(delegate);
}
Assert.state(this.invoker != null, "No single argument public method with or without "
+ "@Classifier was found in delegate of type " + delegate.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
@SuppressWarnings("serial")
public class ClassifierSupport<C, T> implements Classifier<C, T> {

final private T defaultValue;
private final T defaultValue;

/**
* @param defaultValue the default value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ public static boolean match(String pattern, String str) {
}
// Find the pattern between padIdxStart & padIdxTmp in str between
// strIdxStart & strIdxEnd
int patLength = (patIdxTmp - patIdxStart - 1);
int strLength = (strIdxEnd - strIdxStart + 1);
int patLength = patIdxTmp - patIdxStart - 1;
int strLength = strIdxEnd - strIdxStart + 1;
int foundIdx = -1;
strLoop: for (int i = 0; i <= strLength - patLength; i++) {
for (int j = 0; j < patLength; j++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ public void setPatternMap(Map<String, T> values) {
*/
@Override
public T classify(String classifiable) {
T value = this.values.match(classifiable);
return value;
return this.values.match(classifiable);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public C classify(T classifiable) {
* Return the default value supplied in the constructor (default false).
* @return C the default value
*/
final public C getDefault() {
public final C getDefault() {
return this.defaultValue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static MethodInvoker getMethodInvokerForInterface(Class<?> cls, String me
public static MethodInvoker getMethodInvokerByAnnotation(final Class<? extends Annotation> annotationType,
final Object target, final Class<?>... expectedParamTypes) {
MethodInvoker mi = MethodInvokerUtils.getMethodInvokerByAnnotation(annotationType, target);
final Class<?> targetClass = (target instanceof Advised) ? ((Advised) target).getTargetSource().getTargetClass()
final Class<?> targetClass = target instanceof Advised ? ((Advised) target).getTargetSource().getTargetClass()
: target.getClass();
if (mi != null) {
ReflectionUtils.doWithMethods(targetClass, method -> {
Expand Down Expand Up @@ -151,7 +151,7 @@ public static MethodInvoker getMethodInvokerByAnnotation(final Class<? extends A
Assert.isTrue(
ObjectUtils.containsElement(annotationType.getAnnotation(Target.class).value(), ElementType.METHOD),
"Annotation [" + annotationType + "] is not a Method-level annotation.");
final Class<?> targetClass = (target instanceof Advised) ? ((Advised) target).getTargetSource().getTargetClass()
final Class<?> targetClass = target instanceof Advised ? ((Advised) target).getTargetSource().getTargetClass()
: target.getClass();
if (targetClass == null) {
// Proxy with no target cannot have annotations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ private void optionallyFilterMethodsBy(Class<?> returnClass) {
}
if (filteredMethods.size() > 0) {
this.methods.clear();
;
this.methods.putAll(filteredMethods);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
* @author Tomaz Fernandes
* @since 1.3.3
*/
public class BackOffPolicyBuilder {
public final class BackOffPolicyBuilder {

private static final long DEFAULT_INITIAL_DELAY = 1000L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class RetryContextSupport extends AttributeAccessorSupport implements Ret

private final RetryContext parent;

private volatile boolean terminate = false;
private volatile boolean terminate;

private volatile int count;

Expand Down Expand Up @@ -73,8 +73,9 @@ public Throwable getLastThrowable() {
*/
public void registerThrowable(Throwable throwable) {
this.lastException = throwable;
if (throwable != null)
if (throwable != null) {
count++;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ public RetryInterceptorBuilder<T> label(String label) {
private RetryInterceptorBuilder() {
}

public static class StatefulRetryInterceptorBuilder
extends RetryInterceptorBuilder<StatefulRetryOperationsInterceptor> {
public static final class StatefulRetryInterceptorBuilder
extends RetryInterceptorBuilder<StatefulRetryOperationsInterceptor> {

private final StatefulRetryOperationsInterceptor interceptor = new StatefulRetryOperationsInterceptor();

Expand Down Expand Up @@ -308,8 +308,8 @@ private StatefulRetryInterceptorBuilder() {

}

public static class CircuitBreakerInterceptorBuilder
extends RetryInterceptorBuilder<StatefulRetryOperationsInterceptor> {
public static final class CircuitBreakerInterceptorBuilder
extends RetryInterceptorBuilder<StatefulRetryOperationsInterceptor> {

private final StatefulRetryOperationsInterceptor interceptor = new StatefulRetryOperationsInterceptor();

Expand Down Expand Up @@ -370,7 +370,7 @@ private CircuitBreakerInterceptorBuilder() {

}

public static class StatelessRetryInterceptorBuilder extends RetryInterceptorBuilder<RetryOperationsInterceptor> {
public static final class StatelessRetryInterceptorBuilder extends RetryInterceptorBuilder<RetryOperationsInterceptor> {

private final RetryOperationsInterceptor interceptor = new RetryOperationsInterceptor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public Object doWithRetry(RetryContext context) throws Exception {

};

RecoveryCallback<Object> recoveryCallback = (this.recoverer != null)
RecoveryCallback<Object> recoveryCallback = this.recoverer != null
? new ItemRecovererCallback(invocation.getArguments(), this.recoverer) : null;
try {
return this.retryOperations.execute(retryCallback, recoveryCallback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
*/
public class StatefulRetryOperationsInterceptor implements MethodInterceptor {

private transient final Log logger = LogFactory.getLog(getClass());
private final transient Log logger = LogFactory.getLog(getClass());

private MethodArgumentsKeyGenerator keyGenerator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void close(RetryContext status) {

@Override
public void registerThrowable(RetryContext context, Throwable throwable) {
RetryContextSupport simpleContext = ((RetryContextSupport) context);
RetryContextSupport simpleContext = (RetryContextSupport) context;
simpleContext.registerThrowable(throwable);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public boolean isOpen() {
retryable = this.policy.canRetry(this.context);
}
else if (time < this.openWindow) {
if (!hasAttribute(CIRCUIT_OPEN) || (Boolean) getAttribute(CIRCUIT_OPEN) == false) {
if (!hasAttribute(CIRCUIT_OPEN) || !(Boolean) getAttribute(CIRCUIT_OPEN)) {
logger.trace("Opening circuit");
setAttribute(CIRCUIT_OPEN, true);
this.start = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class CompositeRetryPolicy implements RetryPolicy {

RetryPolicy[] policies = new RetryPolicy[0];

private boolean optimistic = false;
private boolean optimistic;

/**
* Setter for optimistic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ public void registerThrowable(RetryContext context, Throwable throwable) {

private static class ExceptionClassifierRetryContext extends RetryContextSupport implements RetryPolicy {

final private Classifier<Throwable, RetryPolicy> exceptionClassifier;
private final Classifier<Throwable, RetryPolicy> exceptionClassifier;

// Dynamic: depends on the latest exception:
private RetryPolicy policy;

// Dynamic: depends on the policy:
private RetryContext context;

final private Map<RetryPolicy, RetryContext> contexts = new HashMap<>();
private final Map<RetryPolicy, RetryContext> contexts = new HashMap<>();

public ExceptionClassifierRetryContext(RetryContext parent,
Classifier<Throwable, RetryPolicy> exceptionClassifier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class MaxAttemptsRetryPolicy implements RetryPolicy {
/**
* The default limit to the number of attempts for a new policy.
*/
public final static int DEFAULT_MAX_ATTEMPTS = 3;
public static final int DEFAULT_MAX_ATTEMPTS = 3;

private volatile int maxAttempts;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void registerThrowable(RetryContext context, Throwable throwable) {
*/
private static class NeverRetryContext extends RetryContextSupport {

private boolean finished = false;
private boolean finished;

public NeverRetryContext(RetryContext parent) {
super(parent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class SimpleRetryPolicy implements RetryPolicy {
/**
* The default limit to the number of attempts for a new policy.
*/
public final static int DEFAULT_MAX_ATTEMPTS = 3;
public static final int DEFAULT_MAX_ATTEMPTS = 3;

private int maxAttempts;

Expand Down Expand Up @@ -237,7 +237,7 @@ public void close(RetryContext status) {
*/
@Override
public void registerThrowable(RetryContext context, Throwable throwable) {
SimpleRetryContext simpleContext = ((SimpleRetryContext) context);
SimpleRetryContext simpleContext = (SimpleRetryContext) context;
simpleContext.registerThrowable(throwable);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
*/
public class DefaultRetryState implements RetryState {

final private Object key;
private final Object key;

final private boolean forceRefresh;
private final boolean forceRefresh;

final private Classifier<? super Throwable, Boolean> rollbackClassifier;
private final Classifier<? super Throwable, Boolean> rollbackClassifier;

/**
* Create a {@link DefaultRetryState} representing the state for a new retry attempt.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ protected <T, E extends Throwable> T doExecute(RetryCallback<T, E> retryCallback
}

Object label = retryCallback.getLabel();
String labelMessage = (label != null) ? "; for: '" + label + "'" : "";
String labelMessage = label != null ? "; for: '" + label + "'" : "";

/*
* We allow the whole loop to be skipped if the policy or context already
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void testTypesProvidedInConstructorWithNonDefaultInCause() {
}

@SuppressWarnings("serial")
private class FooException extends IllegalStateException {
private final class FooException extends IllegalStateException {

private FooException(String s) {
super(s);
Expand All @@ -128,7 +128,7 @@ private FooException(String s, Throwable t) {
}

@SuppressWarnings("serial")
private class BarException extends RuntimeException {
private final class BarException extends RuntimeException {

private BarException() {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected void doCleanupAfterCompletion(Object transaction) {

private static class ResourcelessTransaction {

private boolean active = false;
private boolean active;

public boolean isActive() {
return active;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ public void vanilla() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TestConfiguration.class);
Service service = context.getBean(Service.class);
assertThat(AopUtils.isAopProxy(service)).isTrue();
assertThatExceptionOfType(Exception.class).isThrownBy(() -> service.service());
assertThatExceptionOfType(Exception.class).isThrownBy(service::service);
assertThat((Boolean) service.getContext().getAttribute(CircuitBreakerRetryPolicy.CIRCUIT_OPEN)).isFalse();
assertThatExceptionOfType(Exception.class).isThrownBy(() -> service.service());
assertThatExceptionOfType(Exception.class).isThrownBy(service::service);
assertThat((Boolean) service.getContext().getAttribute(CircuitBreakerRetryPolicy.CIRCUIT_OPEN)).isFalse();
assertThatExceptionOfType(Exception.class).isThrownBy(() -> service.service());
assertThatExceptionOfType(Exception.class).isThrownBy(service::service);
assertThat((Boolean) service.getContext().getAttribute(CircuitBreakerRetryPolicy.CIRCUIT_OPEN)).isTrue();
assertThat(service.getCount()).isEqualTo(3);
assertThatExceptionOfType(Exception.class).isThrownBy(() -> service.service());
assertThatExceptionOfType(Exception.class).isThrownBy(service::service);
// Not called again once circuit is open
assertThat(service.getCount()).isEqualTo(3);
service.expressionService();
Expand Down Expand Up @@ -162,7 +162,7 @@ interface Service {

protected static class ServiceImpl implements Service {

int count = 0;
int count;

RetryContext context;

Expand Down
Loading

0 comments on commit 7e9e216

Please sign in to comment.