More Sonar fixes

This commit is contained in:
Artem Bilan
2022-11-03 17:28:54 -04:00
parent 7084e9654a
commit d31f309752
15 changed files with 76 additions and 98 deletions

View File

@@ -187,12 +187,15 @@ public abstract class AbstractMethodAnnotationPostProcessor<T extends Annotation
BeanDefinition handlerBeanDefinition =
resolveHandlerBeanDefinition(beanName, beanDefinition, handlerBeanType, annotations);
MergedAnnotations mergedAnnotations = beanDefinition.getFactoryMethodMetadata().getAnnotations();
MergedAnnotations mergedAnnotations =
beanDefinition.getFactoryMethodMetadata().getAnnotations(); // NOSONAR
if (handlerBeanDefinition != null) {
if (handlerBeanDefinition != beanDefinition) {
if (!handlerBeanDefinition.equals(beanDefinition)) {
String beanClassName = handlerBeanDefinition.getBeanClassName();
Assert.notNull(beanClassName, "No bean class present for " + handlerBeanDefinition);
Class<?> handlerBeanClass =
org.springframework.util.ClassUtils.resolveClassName(handlerBeanDefinition.getBeanClassName(),
org.springframework.util.ClassUtils.resolveClassName(beanClassName,
this.beanFactory.getBeanClassLoader());
if (isClassIn(handlerBeanClass, Orderable.class, AbstractSimpleMessageHandlerFactoryBean.class)) {
@@ -381,6 +384,7 @@ public abstract class AbstractMethodAnnotationPostProcessor<T extends Annotation
return ResolvableType.forMethodReturnType(standardMethodMetadata.getIntrospectedMethod());
}
else {
Assert.notNull(factoryMethodMetadata, "No factoryMethodMetadata present for " + beanDefinition);
String typeName = factoryMethodMetadata.getReturnTypeName();
Class<?> beanClass =
org.springframework.util.ClassUtils.resolveClassName(typeName,

View File

@@ -16,9 +16,6 @@
package org.springframework.integration.context;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -90,8 +87,6 @@ public abstract class IntegrationContextUtils {
public static final String GLOBAL_CHANNEL_INTERCEPTOR_PROCESSOR_BEAN_NAME = "globalChannelInterceptorProcessor";
public static final String JSON_NODE_WRAPPER_TO_JSON_NODE_CONVERTER = "jsonNodeWrapperToJsonNodeConverter";
public static final String INTEGRATION_LIFECYCLE_ROLE_CONTROLLER = "integrationLifecycleRoleController";
public static final String INTEGRATION_GRAPH_SERVER_BEAN_NAME = "integrationGraphServer";
@@ -106,8 +101,6 @@ public abstract class IntegrationContextUtils {
public static final String LIST_MESSAGE_HANDLER_FACTORY_BEAN_NAME = "integrationListMessageHandlerMethodFactory";
private static final Log LOGGER = LogFactory.getLog(IntegrationContextUtils.class);
/**
* @param beanFactory BeanFactory for lookup, must not be null.
* @return The {@link MetadataStore} bean whose name is "metadataStore".

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -61,7 +61,9 @@ public class AggregateMessageDeliveryException extends MessageDeliveryException
StringBuilder message = new StringBuilder(appendPeriodIfNecessary(baseMessage))
.append(" Multiple causes:\n");
for (Exception exception : this.aggregatedExceptions) {
message.append(" " + exception.getMessage() + "\n");
message.append(" ")
.append(exception.getMessage())
.append("\n");
}
message.append("See below for the stacktrace of the first cause.");
return message.toString();

View File

@@ -53,7 +53,7 @@ public final class Pollers {
/**
* @deprecated since 6.0 in favor of {@link #fixedRate(Duration)}
*/
@Deprecated(since = "6.0", forRemoval = true)
@Deprecated(forRemoval = true)
public static PollerSpec fixedRate(long period, TimeUnit timeUnit) {
return fixedRate(Duration.of(period, timeUnit.toChronoUnit()));
}
@@ -69,7 +69,7 @@ public final class Pollers {
/**
* @deprecated since 6.0 in favor of {@link #fixedRate(Duration, Duration)}
*/
@Deprecated(since = "6.0", forRemoval = true)
@Deprecated(forRemoval = true)
public static PollerSpec fixedRate(long period, TimeUnit timeUnit, long initialDelay) {
ChronoUnit chronoUnit = timeUnit.toChronoUnit();
return fixedRate(Duration.of(period, chronoUnit), Duration.of(initialDelay, chronoUnit));
@@ -90,7 +90,7 @@ public final class Pollers {
/**
* @deprecated since 6.0 in favor of {@link #fixedDelay(Duration)}
*/
@Deprecated(since = "6.0", forRemoval = true)
@Deprecated(forRemoval = true)
public static PollerSpec fixedDelay(long period, TimeUnit timeUnit) {
return fixedDelay(Duration.of(period, timeUnit.toChronoUnit()));
}
@@ -102,7 +102,7 @@ public final class Pollers {
/**
* @deprecated since 6.0 in favor of {@link #fixedDelay(Duration, Duration)}
*/
@Deprecated(since = "6.0", forRemoval = true)
@Deprecated(forRemoval = true)
public static PollerSpec fixedDelay(long period, TimeUnit timeUnit, long initialDelay) {
ChronoUnit chronoUnit = timeUnit.toChronoUnit();
return fixedDelay(Duration.of(period, chronoUnit), Duration.of(initialDelay, chronoUnit));

View File

@@ -36,7 +36,7 @@ import org.springframework.util.ReflectionUtils;
/**
* Method interceptor to invoke default methods on the gateway proxy.
*
* <p>
* The copy of {@code DefaultMethodInvokingMethodInterceptor} from Spring Data Commons.
*
* @author Oliver Gierke
@@ -122,7 +122,7 @@ class DefaultMethodInvokingMethodInterceptor implements MethodInterceptor {
private volatile boolean constructorResolved;
private Constructor<Lookup> constructor;
private transient Constructor<Lookup> constructor;
private final Supplier<Constructor<Lookup>> constructorSupplier =
() -> {

View File

@@ -122,10 +122,11 @@ public class LambdaMessageProcessor implements MessageProcessor<Object>, BeanFac
}
return result;
}
catch (ClassCastException ex) {
logClassCastException(ex);
throw ex;
}
catch (RuntimeException ex) {
if (ex instanceof ClassCastException classCastException) {
logClassCastException(classCastException);
}
throw ex;
}
catch (InvocationTargetException e) {

View File

@@ -1013,13 +1013,6 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator im
return null;
}
private static boolean isMethodDefinedOnObjectClass(Method method) {
return method != null && // NOSONAR
(ReflectionUtils.isObjectMethod(method) ||
AopUtils.isFinalizeMethod(method) || (method.getName().equals("clone")
&& method.getParameterTypes().length == 0));
}
public boolean isAsync() {
if (this.handlerMethodsList.size() == 1) {
Method methodToCheck = this.handlerMethodsList.get(0).values().iterator().next().method;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -70,7 +70,7 @@ public class GroovyScriptExecutingMessageProcessor extends AbstractScriptExecuti
private final Lock scriptLock = new ReentrantLock();
private ScriptSource scriptSource;
private final ScriptSource scriptSource;
private GroovyClassLoader groovyClassLoader = new GroovyClassLoader(ClassUtils.getDefaultClassLoader());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2019 the original author or authors.
* Copyright 2015-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -82,9 +82,9 @@ public class HazelcastLocalInstanceRegistrar implements SmartInitializingSinglet
public void afterSingletonsInstantiated() {
if (this.hazelcastInstance == null) {
if (!Hazelcast.getAllHazelcastInstances().isEmpty()) {
HazelcastInstance hazelcastInstance = Hazelcast.getAllHazelcastInstances().iterator().next();
hazelcastInstance.getCluster().addMembershipListener(new HazelcastMembershipListener());
syncConfigurationMultiMap(hazelcastInstance);
HazelcastInstance anyHazelcastInstance = Hazelcast.getAllHazelcastInstances().iterator().next();
anyHazelcastInstance.getCluster().addMembershipListener(new HazelcastMembershipListener());
syncConfigurationMultiMap(anyHazelcastInstance);
}
else {
logger.warn("No HazelcastInstances for MembershipListener registration");

View File

@@ -73,12 +73,12 @@ public abstract class AbstractHazelcastMessageProducer extends MessageProducerSu
}
public void setCacheEventTypes(String cacheEventTypes) {
Set<String> cacheEvents =
Set<String> events =
HazelcastIntegrationDefinitionValidator.validateEnumType(CacheEventType.class, cacheEventTypes);
Assert.notEmpty(cacheEvents, "'cacheEvents' must have elements");
Assert.notEmpty(events, "'events' must have elements");
HazelcastIntegrationDefinitionValidator.validateCacheEventsByDistributedObject(this.distributedObject,
cacheEvents);
this.cacheEvents = cacheEvents;
events);
this.cacheEvents = events;
}
protected CacheListeningPolicyType getCacheListeningPolicy() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,7 +43,7 @@ public class HazelcastMetadataStore implements ListenableMetadataStore, Initiali
private final IMap<String, String> map;
private final List<MetadataStoreListener> listeners = new CopyOnWriteArrayList<MetadataStoreListener>();
private final List<MetadataStoreListener> listeners = new CopyOnWriteArrayList<>();
public HazelcastMetadataStore(HazelcastInstance hazelcastInstance) {
Assert.notNull(hazelcastInstance, "Hazelcast instance can't be null");
@@ -57,14 +57,14 @@ public class HazelcastMetadataStore implements ListenableMetadataStore, Initiali
@Override
public String putIfAbsent(String key, String value) {
Assert.notNull(key, "'key' must not be null.");
assertKey(key);
Assert.notNull(value, "'value' must not be null.");
return this.map.putIfAbsent(key, value);
}
@Override
public boolean replace(String key, String oldValue, String newValue) {
Assert.notNull(key, "'key' must not be null.");
assertKey(key);
Assert.notNull(oldValue, "'oldValue' must not be null.");
Assert.notNull(newValue, "'newValue' must not be null.");
return this.map.replace(key, oldValue, newValue);
@@ -72,23 +72,27 @@ public class HazelcastMetadataStore implements ListenableMetadataStore, Initiali
@Override
public void put(String key, String value) {
Assert.notNull(key, "'key' must not be null.");
assertKey(key);
Assert.notNull(value, "'value' must not be null.");
this.map.put(key, value);
}
@Override
public String get(String key) {
Assert.notNull(key, "'key' must not be null.");
assertKey(key);
return this.map.get(key);
}
@Override
public String remove(String key) {
Assert.notNull(key, "'key' must not be null.");
assertKey(key);
return this.map.remove(key);
}
private static void assertKey(String key) {
Assert.notNull(key, "'key' must not be null.");
}
@Override
public void addListener(MetadataStoreListener callback) {
Assert.notNull(callback, "callback object can not be null");
@@ -101,18 +105,14 @@ public class HazelcastMetadataStore implements ListenableMetadataStore, Initiali
}
@Override
public void afterPropertiesSet() throws Exception {
public void afterPropertiesSet() {
this.map.addEntryListener(new MapListener(this.listeners), true);
}
private static class MapListener implements EntryAddedListener<String, String>,
EntryRemovedListener<String, String>, EntryUpdatedListener<String, String> {
private final List<MetadataStoreListener> listeners;
MapListener(List<MetadataStoreListener> listeners) {
this.listeners = listeners;
}
private record MapListener(List<MetadataStoreListener> listeners)
implements EntryAddedListener<String, String>,
EntryRemovedListener<String, String>,
EntryUpdatedListener<String, String> {
@Override
public void entryAdded(EntryEvent<String, String> event) {

View File

@@ -66,7 +66,7 @@ public final class PostgresChannelMessageTableSubscriber implements SmartLifecyc
private static final LogAccessor LOGGER = new LogAccessor(PostgresChannelMessageTableSubscriber.class);
private final Map<String, Set<Subscription>> subscriptions = new ConcurrentHashMap<>();
private final Map<String, Set<Subscription>> subscriptionsMap = new ConcurrentHashMap<>();
private final PgConnectionSupplier connectionSupplier;
@@ -120,7 +120,7 @@ public final class PostgresChannelMessageTableSubscriber implements SmartLifecyc
public boolean subscribe(Subscription subscription) {
String subscriptionKey = subscription.getRegion() + " " + getKey(subscription.getGroupId());
Set<Subscription> subscriptions =
this.subscriptions.computeIfAbsent(subscriptionKey, __ -> ConcurrentHashMap.newKeySet());
this.subscriptionsMap.computeIfAbsent(subscriptionKey, __ -> ConcurrentHashMap.newKeySet());
return subscriptions.add(subscription);
}
@@ -131,7 +131,7 @@ public final class PostgresChannelMessageTableSubscriber implements SmartLifecyc
*/
public boolean unsubscribe(Subscription subscription) {
String subscriptionKey = subscription.getRegion() + " " + getKey(subscription.getGroupId());
Set<Subscription> subscriptions = this.subscriptions.get(subscriptionKey);
Set<Subscription> subscriptions = this.subscriptionsMap.get(subscriptionKey);
return subscriptions != null && subscriptions.remove(subscription);
}
@@ -140,16 +140,16 @@ public final class PostgresChannelMessageTableSubscriber implements SmartLifecyc
if (this.latch.getCount() > 0) {
return;
}
ExecutorService executor = this.executor;
if (executor == null) {
ExecutorService executorToUse = this.executor;
if (executorToUse == null) {
CustomizableThreadFactory threadFactory =
new CustomizableThreadFactory("postgres-channel-message-table-subscriber-");
threadFactory.setDaemon(true);
executor = Executors.newSingleThreadExecutor(threadFactory);
this.executor = executor;
executorToUse = Executors.newSingleThreadExecutor(threadFactory);
this.executor = executorToUse;
}
this.latch = new CountDownLatch(1);
this.future = executor.submit(() -> {
this.future = executorToUse.submit(() -> {
try {
while (isActive()) {
try {
@@ -157,16 +157,16 @@ public final class PostgresChannelMessageTableSubscriber implements SmartLifecyc
try (Statement stmt = conn.createStatement()) {
stmt.execute("LISTEN " + this.tablePrefix.toLowerCase() + "channel_message_notify");
}
catch (Throwable t) {
catch (Exception ex) {
try {
conn.close();
}
catch (Throwable suppressed) {
t.addSuppressed(suppressed);
catch (Exception suppressed) {
ex.addSuppressed(suppressed);
}
throw t;
throw ex;
}
this.subscriptions.values()
this.subscriptionsMap.values()
.forEach(subscriptions -> subscriptions.forEach(Subscription::notifyUpdate));
try {
this.connection = conn;
@@ -180,7 +180,7 @@ public final class PostgresChannelMessageTableSubscriber implements SmartLifecyc
if (notifications != null) {
for (PGNotification notification : notifications) {
String parameter = notification.getParameter();
Set<Subscription> subscriptions = this.subscriptions.get(parameter);
Set<Subscription> subscriptions = this.subscriptionsMap.get(parameter);
if (subscriptions == null) {
continue;
}
@@ -202,10 +202,6 @@ public final class PostgresChannelMessageTableSubscriber implements SmartLifecyc
LOGGER.error(e, "Failed to poll notifications from Postgres database");
}
}
catch (Throwable t) {
LOGGER.error(t, "Failed to poll notifications from Postgres database");
return;
}
}
}
finally {
@@ -224,11 +220,10 @@ public final class PostgresChannelMessageTableSubscriber implements SmartLifecyc
@Override
public synchronized void stop() {
Future<?> future = this.future;
if (future.isDone()) {
if (this.future.isDone()) {
return;
}
future.cancel(true);
this.future.cancel(true);
PgConnection conn = this.connection;
if (conn != null) {
try {

View File

@@ -16,7 +16,6 @@
package org.springframework.integration.jdbc.store;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
@@ -50,9 +49,6 @@ import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.SingleColumnRowMapper;
import org.springframework.jdbc.support.JdbcAccessor;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.jdbc.support.MetaDataAccessException;
import org.springframework.jdbc.support.lob.DefaultLobHandler;
import org.springframework.jdbc.support.lob.LobHandler;
import org.springframework.jmx.export.annotation.ManagedAttribute;
@@ -171,8 +167,6 @@ public class JdbcMessageStore extends AbstractMessageGroupStore implements Messa
private final JdbcOperations jdbcTemplate;
private final String vendorName;
private final Map<Query, String> queryCache = new ConcurrentHashMap<>();
private String region = "DEFAULT";
@@ -205,14 +199,6 @@ public class JdbcMessageStore extends AbstractMessageGroupStore implements Messa
Assert.notNull(jdbcOperations, "'dataSource' must not be null");
this.jdbcTemplate = jdbcOperations;
this.serializer = new SerializingConverter();
try {
this.vendorName =
JdbcUtils.extractDatabaseMetaData(((JdbcAccessor) jdbcOperations).getDataSource(), // NOSONAR
DatabaseMetaData::getDatabaseProductName);
}
catch (MetaDataAccessException ex) {
throw new IllegalStateException("Cannot extract database vendor name", ex);
}
}
@Override

View File

@@ -171,12 +171,15 @@ public class SftpSession implements Session<SftpClient.DirEntry> {
this.sftpClient.lstat(path);
return true;
}
catch (IOException ex) {
if (ex instanceof SftpException sftpException &&
SftpConstants.SSH_FX_NO_SUCH_FILE == sftpException.getStatus()) {
catch (SftpException ex) {
if (SftpConstants.SSH_FX_NO_SUCH_FILE == ex.getStatus()) {
return false;
}
else {
throw new UncheckedIOException("Cannot check 'lstat' for path " + path, ex);
}
}
catch (IOException ex) {
throw new UncheckedIOException("Cannot check 'lstat' for path " + path, ex);
}
}

View File

@@ -257,12 +257,13 @@ public abstract class TestUtils {
try {
sent = errorChannel.send(new ErrorMessage(throwable), 10000); // NOSONAR
}
catch (Throwable errorDeliveryError) { // NOSONAR
catch (Exception deliveryException) {
// message will be logged only
logger.warn("Error message was not delivered.", errorDeliveryError);
if (errorDeliveryError instanceof Error) { // NOSONAR
throw (Error) errorDeliveryError;
}
logger.warn("Error message was not delivered.", deliveryException);
}
catch (Error deliveryError) {
logger.warn("Error message was not delivered.", deliveryError);
throw deliveryError;
}
}
if (!sent && logger.isErrorEnabled()) {