Address Sonar Issues

This commit is contained in:
Gary Russell
2022-11-02 11:37:48 -04:00
parent e7d7244b30
commit cdcaa6e9a6
9 changed files with 17 additions and 24 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 the original author or authors.
* Copyright 2016-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.
@@ -34,17 +34,13 @@ public class RemoteInvocationAwareMessageConverterAdapter implements MessageConv
private final MessageConverter delegate;
private final boolean shouldSetClassLoader;
public RemoteInvocationAwareMessageConverterAdapter() {
this.delegate = new SimpleMessageConverter();
this.shouldSetClassLoader = true;
}
public RemoteInvocationAwareMessageConverterAdapter(MessageConverter delegate) {
Assert.notNull(delegate, "'delegate' converter cannot be null");
this.delegate = delegate;
this.shouldSetClassLoader = false;
}
@Override

View File

@@ -103,7 +103,7 @@ public class StreamListenerContainer implements MessageListenerContainer, BeanNa
* Mutually exclusive with {@link #superStream(String, String)}.
*/
@Override
public void setQueueNames(String... queueNames) {
public synchronized void setQueueNames(String... queueNames) {
Assert.isTrue(!this.superStream, "setQueueNames() and superStream() are mutually exclusive");
Assert.isTrue(queueNames != null && queueNames.length == 1, "Only one stream is supported");
this.builder.stream(queueNames[0]);

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.
@@ -101,7 +101,7 @@ public final class ConsumerChannelRegistry {
public static Channel getConsumerChannel(ConnectionFactory connectionFactory) {
ChannelHolder channelHolder = consumerChannel.get();
Channel channel = null;
if (channelHolder != null && channelHolder.getConnectionFactory() == connectionFactory) {
if (channelHolder != null && channelHolder.getConnectionFactory().equals(connectionFactory)) {
channel = channelHolder.getChannel();
}
return channel;

View File

@@ -126,7 +126,6 @@ public abstract class RabbitAccessor implements InitializingBean {
}
}
@Nullable
protected ObservationRegistry getObservationRegistry() {
return this.observationRegistry;
}

View File

@@ -264,11 +264,10 @@ public class RabbitAdmin implements AmqpAdmin, ApplicationContextAware, Applicat
Iterator<Entry<String, Declarable>> iterator = this.manualDeclarables.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, Declarable> next = iterator.next();
if (next.getValue() instanceof Binding binding) {
if ((!binding.isDestinationQueue() && binding.getDestination().equals(exchangeName))
|| binding.getExchange().equals(exchangeName)) {
iterator.remove();
}
if (next.getValue() instanceof Binding binding &&
((!binding.isDestinationQueue() && binding.getDestination().equals(exchangeName))
|| binding.getExchange().equals(exchangeName))) {
iterator.remove();
}
}
}
@@ -362,10 +361,9 @@ public class RabbitAdmin implements AmqpAdmin, ApplicationContextAware, Applicat
Iterator<Entry<String, Declarable>> iterator = this.manualDeclarables.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, Declarable> next = iterator.next();
if (next.getValue() instanceof Binding binding) {
if (binding.isDestinationQueue() && binding.getDestination().equals(queueName)) {
iterator.remove();
}
if (next.getValue() instanceof Binding binding &&
(binding.isDestinationQueue() && binding.getDestination().equals(queueName))) {
iterator.remove();
}
}
}

View File

@@ -1642,7 +1642,7 @@ public abstract class AbstractMessageListenerContainer extends RabbitAccessor
if (listener instanceof ChannelAwareMessageListener chaml) {
doInvokeListener(chaml, channel, data);
}
else if (listener instanceof MessageListener msgListener) {
else if (listener instanceof MessageListener msgListener) { // NOSONAR
boolean bindChannel = isExposeListenerChannel() && isChannelLocallyTransacted();
if (bindChannel) {
RabbitResourceHolder resourceHolder = new RabbitResourceHolder(channel, false);

View File

@@ -436,10 +436,9 @@ public class MessagingMessageListenerAdapter extends AbstractAdaptableMessageLis
|| parameterType.equals(org.springframework.amqp.core.Message.class)) {
return false;
}
if (parameterType instanceof ParameterizedType parameterizedType) {
if (parameterizedType.getRawType().equals(Message.class)) {
return !(parameterizedType.getActualTypeArguments()[0] instanceof WildcardType);
}
if (parameterType instanceof ParameterizedType parameterizedType &&
(parameterizedType.getRawType().equals(Message.class))) {
return !(parameterizedType.getActualTypeArguments()[0] instanceof WildcardType);
}
return !parameterType.equals(Message.class); // could be Message without a generic type
}

View File

@@ -113,7 +113,7 @@ public class RepublishMessageRecoverer implements MessageRecoverer {
public RepublishMessageRecoverer(AmqpTemplate errorTemplate, @Nullable String errorExchange,
@Nullable String errorRoutingKey) {
this(errorTemplate, new LiteralExpression(errorExchange), new LiteralExpression(errorRoutingKey));
this(errorTemplate, new LiteralExpression(errorExchange), new LiteralExpression(errorRoutingKey)); // NOSONAR
}
/**

View File

@@ -30,6 +30,7 @@ import io.micrometer.observation.transport.ReceiverContext;
*/
public class RabbitMessageReceiverContext extends ReceiverContext<Message> {
@Nullable
private final String listenerId;
private final Message message;