Fix some compiler smells for Java 21

This commit is contained in:
Artem Bilan
2024-09-24 14:33:16 -04:00
parent fc377126de
commit 8082f3c3f9
25 changed files with 160 additions and 298 deletions

Binary file not shown.

View File

@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=d725d707bfabd4dfdc958c624003b3c80accc03f7037b5122c4b1d0ef15cecab
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
distributionSha256Sum=1541fa36599e12857140465f3c91a97409b4512501c26f9631fb113e392c5bd1
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME

View File

@@ -114,6 +114,7 @@ public class AmqpInboundGateway extends MessagingGatewaySupport {
private AmqpInboundGateway(MessageListenerContainer listenerContainer, AmqpTemplate amqpTemplate,
boolean amqpTemplateExplicitlySet) {
Assert.notNull(listenerContainer, "listenerContainer must not be null");
Assert.notNull(amqpTemplate, "'amqpTemplate' must not be null");
Assert.isNull(listenerContainer.getMessageListener(),
@@ -194,7 +195,7 @@ public class AmqpInboundGateway extends MessagingGatewaySupport {
* @since 4.3.10
* @see #setRetryTemplate(RetryTemplate)
*/
public void setRecoveryCallback(RecoveryCallback<? extends Object> recoveryCallback) {
public void setRecoveryCallback(RecoveryCallback<?> recoveryCallback) {
this.recoveryCallback = recoveryCallback;
}
@@ -341,6 +342,9 @@ public class AmqpInboundGateway extends MessagingGatewaySupport {
protected class Listener implements ChannelAwareMessageListener {
protected Listener() {
}
@SuppressWarnings("unchecked")
@Override
public void onMessage(final Message message, final Channel channel) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 the original author or authors.
* Copyright 2019-2024 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.
@@ -38,7 +38,7 @@ public class ManualAckListenerExecutionFailedException extends ListenerExecution
@Serial
private static final long serialVersionUID = 1L;
private final Channel channel;
private final transient Channel channel;
private final long deliveryTag;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2019 the original author or authors.
* Copyright 2017-2024 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.
@@ -25,6 +25,8 @@ import org.springframework.messaging.MessagingException;
* publisher confirm.
*
* @author Gary Russell
* @author Artem Bilan
*
* @since 4.3.12
*
*/
@@ -32,10 +34,11 @@ public class NackedAmqpMessageException extends MessagingException {
private static final long serialVersionUID = 1L;
private final Object correlationData;
private final String nackReason;
@SuppressWarnings("serial")
private final Object correlationData;
public NackedAmqpMessageException(Message<?> message, @Nullable Object correlationData, String nackReason) {
super(message);
this.correlationData = correlationData;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2022 the original author or authors.
* Copyright 2014-2024 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.
@@ -32,6 +32,7 @@ public class MessageGroupExpiredEvent extends IntegrationEvent {
private static final long serialVersionUID = -7126221042599333919L;
@SuppressWarnings("serial")
private final Object groupId;
private final int messageCount;
@@ -44,6 +45,7 @@ public class MessageGroupExpiredEvent extends IntegrationEvent {
public MessageGroupExpiredEvent(Object source, Object groupId, int messageCount, Date lastModified, Date expired,
boolean discarded) {
super(source);
this.groupId = groupId;
this.messageCount = messageCount;

View File

@@ -45,7 +45,7 @@ public class EventDrivenConsumer extends AbstractEndpoint implements Integration
Assert.notNull(handler, "handler must not be null");
this.inputChannel = inputChannel;
this.handler = handler;
this.setPhase(Integer.MIN_VALUE);
setPhase(Integer.MIN_VALUE);
}
@Override
@@ -55,11 +55,11 @@ public class EventDrivenConsumer extends AbstractEndpoint implements Integration
@Override
public MessageChannel getOutputChannel() {
if (this.handler instanceof MessageProducer) {
return ((MessageProducer) this.handler).getOutputChannel();
if (this.handler instanceof MessageProducer messageProducer) {
return messageProducer.getOutputChannel();
}
else if (this.handler instanceof MessageRouter) {
return ((MessageRouter) this.handler).getDefaultOutputChannel();
else if (this.handler instanceof MessageRouter messageRouter) {
return messageRouter.getDefaultOutputChannel();
}
else {
return null;
@@ -75,8 +75,8 @@ public class EventDrivenConsumer extends AbstractEndpoint implements Integration
protected void doStart() {
this.logComponentSubscriptionEvent(true);
this.inputChannel.subscribe(this.handler);
if (this.handler instanceof Lifecycle) {
((Lifecycle) this.handler).start();
if (this.handler instanceof Lifecycle lifecycle) {
lifecycle.start();
}
}
@@ -84,15 +84,16 @@ public class EventDrivenConsumer extends AbstractEndpoint implements Integration
protected void doStop() {
this.logComponentSubscriptionEvent(false);
this.inputChannel.unsubscribe(this.handler);
if (this.handler instanceof Lifecycle) {
((Lifecycle) this.handler).stop();
if (this.handler instanceof Lifecycle lifecycle) {
lifecycle.stop();
}
}
private void logComponentSubscriptionEvent(boolean add) {
if (this.handler instanceof NamedComponent && this.inputChannel instanceof NamedComponent) {
String channelName = ((NamedComponent) this.inputChannel).getComponentName();
String componentType = ((NamedComponent) this.handler).getComponentType();
if (this.handler instanceof NamedComponent namedHandler
&& this.inputChannel instanceof NamedComponent namedChannel) {
String componentType = namedHandler.getComponentType();
componentType = StringUtils.hasText(componentType) ? componentType : "";
String componentName = getComponentName();
componentName =
@@ -102,7 +103,7 @@ public class EventDrivenConsumer extends AbstractEndpoint implements Integration
.append(componentType)
.append(componentName)
.append("} as a subscriber to the '")
.append(channelName)
.append(namedChannel.getComponentName())
.append("' channel");
if (add) {
buffer.insert(0, "Adding ");

View File

@@ -81,7 +81,7 @@ public abstract class MessageProducerSupport extends AbstractEndpoint
private volatile Subscription subscription;
protected MessageProducerSupport() {
this.setPhase(Integer.MAX_VALUE / 2);
setPhase(Integer.MAX_VALUE / 2);
}
@Override
@@ -222,7 +222,6 @@ public abstract class MessageProducerSupport extends AbstractEndpoint
if (beanFactory != null) {
this.messagingTemplate.setBeanFactory(beanFactory);
}
}
/**
@@ -278,8 +277,8 @@ public abstract class MessageProducerSupport extends AbstractEndpoint
.doOnCancel(this::stop)
.doOnSubscribe((subs) -> this.subscription = subs);
if (channelForSubscription instanceof ReactiveStreamsSubscribableChannel) {
((ReactiveStreamsSubscribableChannel) channelForSubscription).subscribeTo(messageFlux);
if (channelForSubscription instanceof ReactiveStreamsSubscribableChannel reactiveStreamsSubscribableChannel) {
reactiveStreamsSubscribableChannel.subscribeTo(messageFlux);
}
else {
messageFlux

View File

@@ -686,6 +686,7 @@ public class DelayHandler extends AbstractReplyProducingMessageHandler implement
private final long requestDate;
@SuppressWarnings("serial")
private final Message<?> original;
DelayedMessageWrapper(Message<?> original, long requestDate) {

View File

@@ -23,6 +23,7 @@ import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.cache.CacheManager;
import org.springframework.cache.interceptor.CacheAspectSupport;
@@ -49,7 +50,7 @@ import org.springframework.util.ReflectionUtils;
* The {@link AbstractRequestHandlerAdvice} implementation for caching
* {@code AbstractReplyProducingMessageHandler.RequestHandler#handleRequestMessage(Message)} results.
* Supports all the cache operations - cacheable, put, evict.
* By default only cacheable is applied for the provided {@code cacheNames}.
* By default, only cacheable is applied for the provided {@code cacheNames}.
* The default cache {@code key} is {@code payload} of the request message.
*
* @author Artem Bilan
@@ -103,9 +104,6 @@ public class CacheRequestHandlerAdvice extends AbstractRequestHandlerAdvice
*/
public CacheRequestHandlerAdvice(String... cacheNamesArg) {
this.cacheNames = cacheNamesArg != null ? Arrays.copyOf(cacheNamesArg, cacheNamesArg.length) : null;
CacheableOperation.Builder builder = new CacheableOperation.Builder();
builder.setName(toString());
this.cacheOperations.add(builder.build());
}
/**
@@ -192,6 +190,11 @@ public class CacheRequestHandlerAdvice extends AbstractRequestHandlerAdvice
@Override
protected void onInit() {
if (this.cacheOperations.isEmpty()) {
CacheableOperation.Builder builder = new CacheableOperation.Builder();
builder.setName(toString());
this.cacheOperations.add(builder.build());
}
List<CacheOperation> cacheOperationsToUse;
if (!ObjectUtils.isEmpty(this.cacheNames)) {
cacheOperationsToUse =
@@ -232,14 +235,15 @@ public class CacheRequestHandlerAdvice extends AbstractRequestHandlerAdvice
builder.setKeyGenerator(operation.getKeyGenerator());
return builder.build();
})
.collect(Collectors.toList());
.toList();
}
else {
cacheOperationsToUse = this.cacheOperations;
}
this.delegate.setBeanFactory(getBeanFactory());
EvaluationContext evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory());
BeanFactory beanFactory = getBeanFactory();
this.delegate.setBeanFactory(beanFactory);
EvaluationContext evaluationContext = ExpressionUtils.createStandardEvaluationContext(beanFactory);
this.delegate.setKeyGenerator((target, method, params) ->
this.keyExpression.getValue(evaluationContext, params[0])); // NOSONAR
this.delegate.setCacheOperationSources((method, targetClass) -> cacheOperationsToUse);
@@ -260,7 +264,6 @@ public class CacheRequestHandlerAdvice extends AbstractRequestHandlerAdvice
else {
return result;
}
};
return this.delegate.invoke(operationInvoker, target, message);

View File

@@ -309,7 +309,7 @@ public class ExpressionEvaluatingRequestHandlerAdvice extends AbstractRequestHan
private static final long serialVersionUID = 1L;
private final Object evaluationResult;
private final transient Object evaluationResult;
public MessageHandlingExpressionEvaluatingAdviceException(Message<?> message, String description,
Throwable cause, Object evaluationResult) {

View File

@@ -73,6 +73,7 @@ public final class MessageHistory implements List<Properties>, Serializable, Clo
private static final MessageBuilderFactory MESSAGE_BUILDER_FACTORY = new DefaultMessageBuilderFactory();
@SuppressWarnings("serial")
private final List<Properties> components;
@Nullable

View File

@@ -41,6 +41,7 @@ public class AdviceMessage<T> extends GenericMessage<T> {
private static final long serialVersionUID = 1L;
@SuppressWarnings("serial")
private final Message<?> inputMessage;
public AdviceMessage(T payload, Message<?> inputMessage) {

View File

@@ -67,7 +67,7 @@ public abstract class AbstractMessageSplitter extends AbstractReplyProducingMess
* Set the applySequence flag to the specified value. Defaults to true.
* @param applySequence true to apply sequence information.
*/
public void setApplySequence(boolean applySequence) {
public final void setApplySequence(boolean applySequence) {
this.applySequence = applySequence;
}
@@ -143,8 +143,7 @@ public abstract class AbstractMessageSplitter extends AbstractReplyProducingMess
private Flux<?> prepareFluxResult(Message<?> message, Object result) {
int sequenceSize = 1;
Flux<?> flux = Flux.just(result);
if (result instanceof Iterable<?>) {
Iterable<Object> iterable = (Iterable<Object>) result;
if (result instanceof Iterable<?> iterable) {
sequenceSize = obtainSizeIfPossible(iterable);
flux = Flux.fromIterable(iterable);
}
@@ -153,18 +152,15 @@ public abstract class AbstractMessageSplitter extends AbstractReplyProducingMess
sequenceSize = items.length;
flux = Flux.fromArray(items);
}
else if (result instanceof Iterator<?>) {
Iterator<Object> iter = (Iterator<Object>) result;
sequenceSize = obtainSizeIfPossible(iter);
flux = Flux.fromIterable(() -> iter);
else if (result instanceof Iterator<?> iterator) {
sequenceSize = obtainSizeIfPossible(iterator);
flux = Flux.fromIterable(() -> iterator);
}
else if (result instanceof Stream<?>) {
Stream<Object> stream = ((Stream<Object>) result);
else if (result instanceof Stream<?> stream) {
sequenceSize = 0;
flux = Flux.fromStream(stream);
}
else if (result instanceof Publisher<?>) {
Publisher<Object> publisher = (Publisher<Object>) result;
else if (result instanceof Publisher<?> publisher) {
sequenceSize = 0;
flux = Flux.from(publisher);
}
@@ -188,8 +184,7 @@ public abstract class AbstractMessageSplitter extends AbstractReplyProducingMess
int sequenceSize = 1;
Iterator<?> iterator = Collections.singleton(result).iterator();
if (result instanceof Iterable<?>) {
Iterable<Object> iterable = (Iterable<Object>) result;
if (result instanceof Iterable<?> iterable) {
sequenceSize = obtainSizeIfPossible(iterable);
iterator = iterable.iterator();
}
@@ -198,19 +193,17 @@ public abstract class AbstractMessageSplitter extends AbstractReplyProducingMess
sequenceSize = items.length;
iterator = Arrays.asList(items).iterator();
}
else if (result instanceof Iterator<?>) {
Iterator<Object> iter = (Iterator<Object>) result;
else if (result instanceof Iterator<?> iter) {
sequenceSize = obtainSizeIfPossible(iter);
iterator = iter;
}
else if (result instanceof Stream<?>) {
Stream<Object> stream = ((Stream<Object>) result);
else if (result instanceof Stream<?> stream) {
sequenceSize = 0;
iterator = stream.iterator();
}
else if (result instanceof Publisher<?>) {
else if (result instanceof Publisher<?> publisher) {
sequenceSize = 0;
iterator = Flux.from((Publisher<?>) result).toIterable().iterator();
iterator = Flux.from(publisher).toIterable().iterator();
}
if (!iterator.hasNext()) {
@@ -251,8 +244,8 @@ public abstract class AbstractMessageSplitter extends AbstractReplyProducingMess
* @since 5.0
*/
protected int obtainSizeIfPossible(Iterable<?> iterable) {
if (iterable instanceof Collection) {
return ((Collection<?>) iterable).size();
if (iterable instanceof Collection<?> collection) {
return collection.size();
}
else if (JacksonPresent.isJackson2Present() && JacksonNodeHelper.isNode(iterable)) {
return JacksonNodeHelper.nodeSize(iterable);

View File

@@ -41,6 +41,7 @@ public class MessageGroupMetadata implements Serializable {
private static final long serialVersionUID = 1L;
@SuppressWarnings("serial")
private final List<UUID> messageIds = new LinkedList<>();
private long timestamp;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2019 the original author or authors.
* Copyright 2016-2024 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.
@@ -32,6 +32,7 @@ public class MessageHolder implements Serializable {
private static final long serialVersionUID = 1L;
@SuppressWarnings("serial")
private Message<?> message;
private MessageMetadata messageMetadata;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2021 the original author or authors.
* Copyright 2014-2024 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.
@@ -56,6 +56,7 @@ public class MutableMessage<T> implements Message<T>, Serializable {
private static final long serialVersionUID = -636635024258737500L;
@SuppressWarnings("serial")
private final T payload;
private final MutableMessageHeaders headers;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2021 the original author or authors.
* Copyright 2015-2024 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.
@@ -27,6 +27,8 @@ import org.springframework.util.Assert;
* performing multiple updates from a single message, e.g. an FTP 'mput' operation.
*
* @author Gary Russell
* @author Artem Bilan
*
* @since 4.2
*
*/
@@ -34,9 +36,9 @@ public class PartialSuccessException extends MessagingException {
private static final long serialVersionUID = 8810900575763284993L;
private final Collection<?> partialResults;
private final transient Collection<?> partialResults;
private final Collection<?> derivedInput;
private final transient Collection<?> derivedInput;
/**
*

View File

@@ -19,28 +19,33 @@ package org.springframework.integration.config;
import java.util.Collection;
import java.util.List;
/**
* @author Marius Bogoevici
* @author Dave Syer
* @author Artem Bilan
*/
public class MaxValueReleaseStrategy {
private long maxValue;
private final long maxValue;
public MaxValueReleaseStrategy(long maxValue) {
this.maxValue = maxValue;
}
public boolean checkCompletenessAsList(List<Long> numbers) {
int sum = 0;
long sum = 0;
for (long number : numbers) {
sum += number;
}
return sum >= maxValue;
return sum >= this.maxValue;
}
public boolean checkCompletenessAsCollection(Collection<Long> numbers) {
int sum = 0;
long sum = 0;
for (long number : numbers) {
sum += number;
}
return sum >= maxValue;
return sum >= this.maxValue;
}
}

View File

@@ -20,21 +20,21 @@ import java.io.ByteArrayInputStream;
import java.util.Locale;
import java.util.Properties;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
* @author Oleg Zhurakousky
@@ -46,240 +46,73 @@ public class ChainElementsFailureTests {
private Locale localeBeforeTest;
@Before
@BeforeEach
public void setUp() {
localeBeforeTest = Locale.getDefault();
Locale.setDefault(new Locale("en", "US"));
Locale.setDefault(Locale.forLanguageTag("en-US"));
}
@After
@AfterEach
public void tearDown() {
Locale.setDefault(localeBeforeTest);
}
@Test
public void chainServiceActivator() throws Exception {
try {
this.bootStrap("service-activator");
fail("Expected a XmlBeanDefinitionStoreException to be thrown.");
}
catch (XmlBeanDefinitionStoreException e) {
assertThat(e.getCause().getMessage()).isEqualTo("cvc-complex-type.3.2.2: Attribute 'input-channel' is " +
"not" +
" allowed to appear in element 'int:service-activator'.");
}
@ParameterizedTest
@ValueSource(strings = {
"service-activator",
"aggregator",
"chain",
"delayer",
"filter",
"gateway",
"header-enricher",
"header-filter",
"header-filter",
"header-value-router",
"transformer",
"router",
"splitter",
"resequencer",
})
void inputChannelNotAllowed(String element) {
assertThatExceptionOfType(XmlBeanDefinitionStoreException.class)
.isThrownBy(() -> bootStrap(element))
.withStackTraceContaining(
"cvc-complex-type.3.2.2: Attribute 'input-channel' is not" +
" allowed to appear in element 'int:" + element + "'.");
}
@Test
public void chainAggregator() throws Exception {
try {
this.bootStrap("aggregator");
fail("Expected a XmlBeanDefinitionStoreException to be thrown.");
}
catch (XmlBeanDefinitionStoreException e) {
assertThat(e.getCause().getMessage()).isEqualTo("cvc-complex-type.3.2.2: Attribute 'input-channel' is " +
"not" +
" allowed to appear in element 'int:aggregator'.");
}
}
@Test
public void chainChain() throws Exception {
try {
this.bootStrap("chain");
fail("Expected a XmlBeanDefinitionStoreException to be thrown.");
}
catch (XmlBeanDefinitionStoreException e) {
assertThat(e.getCause().getMessage()).isEqualTo("cvc-complex-type.3.2.2: Attribute 'input-channel' is " +
"not" +
" allowed to appear in element 'int:chain'.");
}
}
@Test
public void chainDelayer() throws Exception {
try {
this.bootStrap("delayer");
fail("Expected a XmlBeanDefinitionStoreException to be thrown.");
}
catch (XmlBeanDefinitionStoreException e) {
assertThat(e.getCause().getMessage()).isEqualTo("cvc-complex-type.3.2.2: Attribute 'input-channel' is " +
"not" +
" allowed to appear in element 'int:delayer'.");
}
}
@Test
public void chainFilter() throws Exception {
try {
this.bootStrap("filter");
fail("Expected a XmlBeanDefinitionStoreException to be thrown.");
}
catch (XmlBeanDefinitionStoreException e) {
assertThat(e.getCause().getMessage()).isEqualTo("cvc-complex-type.3.2.2: Attribute 'input-channel' is " +
"not" +
" allowed to appear in element 'int:filter'.");
}
}
@Test
public void chainGateway() throws Exception {
try {
this.bootStrap("gateway");
fail("Expected a XmlBeanDefinitionStoreException to be thrown.");
}
catch (XmlBeanDefinitionStoreException e) {
assertThat(e.getCause().getMessage()).isEqualTo("cvc-complex-type.3.2.2: Attribute 'input-channel' is " +
"not" +
" allowed to appear in element 'int:gateway'.");
}
}
@Test
public void chainHeaderEnricher() throws Exception {
try {
this.bootStrap("header-enricher");
fail("Expected a XmlBeanDefinitionStoreException to be thrown.");
}
catch (XmlBeanDefinitionStoreException e) {
assertThat(e.getCause().getMessage()).isEqualTo("cvc-complex-type.3.2.2: Attribute 'input-channel' is not" +
" allowed to appear in element 'int:header-enricher'.");
}
}
@Test
public void chainHeaderFilter() throws Exception {
try {
this.bootStrap("header-filter");
fail("Expected a XmlBeanDefinitionStoreException to be thrown.");
}
catch (XmlBeanDefinitionStoreException e) {
assertThat(e.getCause().getMessage()).isEqualTo("cvc-complex-type.3.2.2: Attribute 'input-channel' is not" +
" allowed to appear in element 'int:header-filter'.");
}
}
@Test
public void chainHeaderValueRouter() throws Exception {
try {
this.bootStrap("header-value-router");
fail("Expected a XmlBeanDefinitionStoreException to be thrown.");
}
catch (XmlBeanDefinitionStoreException e) {
assertThat(e.getCause().getMessage()).isEqualTo("cvc-complex-type.3.2.2: Attribute 'input-channel' is " +
"not" +
" allowed to appear in element 'int:header-value-router'.");
}
}
@Test
public void chainTransformer() throws Exception {
try {
this.bootStrap("transformer");
fail("Expected a XmlBeanDefinitionStoreException to be thrown.");
}
catch (XmlBeanDefinitionStoreException e) {
assertThat(e.getCause().getMessage()).isEqualTo("cvc-complex-type.3.2.2: Attribute 'input-channel' is not" +
" allowed to appear in element 'int:transformer'.");
}
}
@Test
public void chainRouter() throws Exception {
try {
this.bootStrap("router");
fail("Expected a XmlBeanDefinitionStoreException to be thrown.");
}
catch (XmlBeanDefinitionStoreException e) {
assertThat(e.getCause().getMessage()).isEqualTo("cvc-complex-type.3.2.2: Attribute 'input-channel' is not" +
" allowed to appear in element 'int:router'.");
}
}
@Test
public void chainSplitter() throws Exception {
try {
this.bootStrap("splitter");
fail("Expected a XmlBeanDefinitionStoreException to be thrown.");
}
catch (XmlBeanDefinitionStoreException e) {
assertThat(e.getCause().getMessage()).isEqualTo("cvc-complex-type.3.2.2: Attribute 'input-channel' is not" +
" allowed to appear in element 'int:splitter'.");
}
}
@Test
public void chainResequencer() throws Exception {
try {
this.bootStrap("resequencer");
fail("Expected a XmlBeanDefinitionStoreException to be thrown.");
}
catch (XmlBeanDefinitionStoreException e) {
assertThat(e.getCause().getMessage()).isEqualTo("cvc-complex-type.3.2.2: Attribute 'input-channel' is not" +
" allowed to appear in element 'int:resequencer'.");
}
}
@Test
public void chainResequencerPoller() throws Exception {
try {
this.bootStrap("resequencer-poller");
fail("Expected a XmlBeanDefinitionStoreException to be thrown.");
}
catch (BeanDefinitionParsingException e) {
final String expectedMessage = "Configuration problem: " +
"'int:resequencer' must not define a 'poller' sub-element " +
"when used within a chain.";
final String actualMessage = e.getMessage();
assertThat(actualMessage.startsWith(expectedMessage))
.as("Error message did not start with '" + expectedMessage +
"' but instead returned: '" + actualMessage + "'").isTrue();
}
public void chainResequencerPoller() {
assertThatExceptionOfType(BeanDefinitionParsingException.class)
.isThrownBy(() -> bootStrap("resequencer-poller"))
.withMessageStartingWith("Configuration problem: " +
"'int:resequencer' must not define a 'poller' sub-element " +
"when used within a chain.");
}
@Test
public void testInt2755DetectDuplicateHandlerId() throws Exception {
try {
this.bootStrap("duplicate-handler-id");
fail("Expected a BeanDefinitionParsingException to be thrown.");
}
catch (BeanDefinitionParsingException e) {
assertThat(e.getMessage().contains("A bean definition is already registered for " +
"beanName: 'foo$child.bar.handler' within the current <chain>.")).isTrue();
}
assertThatExceptionOfType(BeanDefinitionParsingException.class)
.isThrownBy(() -> bootStrap("duplicate-handler-id"))
.withMessageContaining("A bean definition is already registered for " +
"beanName: 'foo$child.bar.handler' within the current <chain>.");
}
private ApplicationContext bootStrap(String configProperty) throws Exception {
PropertiesFactoryBean pfb = new PropertiesFactoryBean();
pfb.setLocation(new ClassPathResource("org/springframework/integration/config/xml/chain-elements-config.properties"));
pfb.afterPropertiesSet();
Properties prop = pfb.getObject();
StringBuilder buffer = new StringBuilder();
buffer.append(prop.getProperty("xmlheaders")).append(prop.getProperty(configProperty)).append(prop.getProperty("xmlfooter"));
ByteArrayInputStream stream = new ByteArrayInputStream(buffer.toString().getBytes());
private static void bootStrap(String configProperty) throws Exception {
Properties prop =
PropertiesLoaderUtils.loadProperties(
new ClassPathResource(
"org/springframework/integration/config/xml/chain-elements-config.properties"));
ByteArrayInputStream stream =
new ByteArrayInputStream((prop.getProperty("xmlheaders") +
prop.getProperty(configProperty) +
prop.getProperty("xmlfooter")).getBytes());
GenericApplicationContext ac = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ac);
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
reader.loadBeanDefinitions(new InputStreamResource(stream));
ac.refresh();
return ac;
}
public static class SampleService {

View File

@@ -30,8 +30,10 @@ import org.springframework.scheduling.support.PeriodicTrigger;
*/
public class PollingEndpointStub extends AbstractPollingEndpoint {
public PollingEndpointStub() {
this.setTrigger(new PeriodicTrigger(Duration.ofMillis(500)));
@Override
protected void onInit() {
super.onInit();
setTrigger(new PeriodicTrigger(Duration.ofMillis(500)));
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2019 the original author or authors.
* Copyright 2019-2024 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.
@@ -30,7 +30,7 @@ public abstract class FtpRequestEvent extends ApacheMinaFtpEvent {
private static final long serialVersionUID = 1L;
protected final FtpRequest request; //NOSONAR protected final
protected final transient FtpRequest request; //NOSONAR protected final
public FtpRequestEvent(FtpSession source, FtpRequest request) {
super(source);

View File

@@ -22,8 +22,7 @@ import javax.management.Attribute;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
@@ -37,16 +36,18 @@ import org.springframework.integration.scheduling.PollerMetadata;
import org.springframework.jmx.support.MBeanServerFactoryBean;
import org.springframework.messaging.PollableChannel;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Gary Russell
* @author Artem Bilan
*
* @since 5.0
*
*/
@RunWith(SpringRunner.class)
@SpringJUnitConfig
@DirtiesContext
public class MessageSourceTests {
@@ -108,7 +109,9 @@ public class MessageSourceTests {
public static class MaxFetchSource extends AbstractFetchLimitingMessageSource<String> {
{
@Override
protected void onInit() {
super.onInit();
setMaxFetchSize(123);
}

View File

@@ -59,9 +59,14 @@ public class PollableKafkaChannel extends AbstractKafkaChannel
public PollableKafkaChannel(KafkaOperations<?, ?> template, KafkaMessageSource<?, ?> source) {
super(template, topic(source));
this.source = source;
if (source.getConsumerProperties().getGroupId() == null) {
}
@Override
protected void onInit() {
super.onInit();
if (this.source.getConsumerProperties().getGroupId() == null) {
String groupId = getGroupId();
source.getConsumerProperties().setGroupId(groupId != null ? groupId : getBeanName());
this.source.getConsumerProperties().setGroupId(groupId != null ? groupId : getBeanName());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2019 the original author or authors.
* Copyright 2017-2024 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.
@@ -25,6 +25,7 @@ import org.springframework.messaging.MessagingException;
* An exception that is the payload of an {@code ErrorMessage} when a send fails.
*
* @author Gary Russell
* @author Artem Bilan
*
* @since 5.4
*
@@ -33,7 +34,7 @@ public class KafkaSendFailureException extends MessagingException {
private static final long serialVersionUID = 1L;
private final ProducerRecord<?, ?> record;
private final transient ProducerRecord<?, ?> record;
public KafkaSendFailureException(Message<?> message, ProducerRecord<?, ?> record, Throwable cause) {
super(message, cause);