From 38e15b669fb850c8ff38de551ea54302dae8f9e0 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Thu, 24 Jun 2021 09:45:26 -0400 Subject: [PATCH] GH-1352: Fix New Sonar Issues --- .../support/StreamMessageProperties.java | 57 ++++++++++++++----- .../DefaultStreamMessageConverter.java | 2 +- .../RabbitListenerEndpointRegistry.java | 12 +--- 3 files changed, 45 insertions(+), 26 deletions(-) diff --git a/spring-rabbit-stream/src/main/java/org/springframework/rabbit/stream/support/StreamMessageProperties.java b/spring-rabbit-stream/src/main/java/org/springframework/rabbit/stream/support/StreamMessageProperties.java index ee85dc15..2b04ae91 100644 --- a/spring-rabbit-stream/src/main/java/org/springframework/rabbit/stream/support/StreamMessageProperties.java +++ b/spring-rabbit-stream/src/main/java/org/springframework/rabbit/stream/support/StreamMessageProperties.java @@ -16,12 +16,12 @@ package org.springframework.rabbit.stream.support; +import java.util.Objects; + import org.springframework.amqp.core.MessageProperties; import org.springframework.lang.Nullable; -import com.rabbitmq.stream.MessageBuilder.PropertiesBuilder; import com.rabbitmq.stream.MessageHandler.Context; -import com.rabbitmq.stream.Properties; /** * {@link MessageProperties} extension for stream messages. @@ -66,7 +66,7 @@ public class StreamMessageProperties extends MessageProperties { } /** - * See {@link Properties#getTo()}. + * See {@link com.rabbitmq.stream.Properties#getTo()}. * @return the to address. */ public String getTo() { @@ -74,7 +74,7 @@ public class StreamMessageProperties extends MessageProperties { } /** - * See {@link PropertiesBuilder#to(String)}. + * See {@link com.rabbitmq.stream.MessageBuilder.PropertiesBuilder#to(String)}. * @param address the address. */ public void setTo(String address) { @@ -82,7 +82,7 @@ public class StreamMessageProperties extends MessageProperties { } /** - * See {@link Properties#getSubject()}. + * See {@link com.rabbitmq.stream.Properties#getSubject()}. * @return the subject. */ public String getSubject() { @@ -90,7 +90,7 @@ public class StreamMessageProperties extends MessageProperties { } /** - * See {@link PropertiesBuilder#subject(String)}. + * See {@link com.rabbitmq.stream.MessageBuilder.PropertiesBuilder#subject(String)}. * @param subject the subject. */ public void setSubject(String subject) { @@ -98,7 +98,7 @@ public class StreamMessageProperties extends MessageProperties { } /** - * See {@link Properties#getCreationTime()}. + * See {@link com.rabbitmq.stream.Properties#getCreationTime()}. * @return the creation time. */ public long getCreationTime() { @@ -106,7 +106,8 @@ public class StreamMessageProperties extends MessageProperties { } /** - * See {@link PropertiesBuilder#creationTime(long)}. + * See + * {@link com.rabbitmq.stream.MessageBuilder.PropertiesBuilder#creationTime(long)}. * @param creationTime the creation time. */ public void setCreationTime(long creationTime) { @@ -114,7 +115,7 @@ public class StreamMessageProperties extends MessageProperties { } /** - * See {@link Properties#getGroupId()}. + * See {@link com.rabbitmq.stream.Properties#getGroupId()}. * @return the group id. */ public String getGroupId() { @@ -122,7 +123,7 @@ public class StreamMessageProperties extends MessageProperties { } /** - * See {@link PropertiesBuilder#groupId(String)}. + * See {@link com.rabbitmq.stream.MessageBuilder.PropertiesBuilder#groupId(String)}. * @param groupId the group id. */ public void setGroupId(String groupId) { @@ -130,7 +131,7 @@ public class StreamMessageProperties extends MessageProperties { } /** - * See {@link Properties#getGroupSequence()}. + * See {@link com.rabbitmq.stream.Properties#getGroupSequence()}. * @return the group sequence. */ public long getGroupSequence() { @@ -138,7 +139,8 @@ public class StreamMessageProperties extends MessageProperties { } /** - * See {@link PropertiesBuilder#groupSequence(long)}. + * See + * {@link com.rabbitmq.stream.MessageBuilder.PropertiesBuilder#groupSequence(long)}. * @param groupSequence the group sequence. */ public void setGroupSequence(long groupSequence) { @@ -146,7 +148,7 @@ public class StreamMessageProperties extends MessageProperties { } /** - * See {@link Properties#getReplyToGroupId()}. + * See {@link com.rabbitmq.stream.Properties#getReplyToGroupId()}. * @return the reply to group id. */ public String getReplyToGroupId() { @@ -154,11 +156,38 @@ public class StreamMessageProperties extends MessageProperties { } /** - * See {@link PropertiesBuilder#replyToGroupId(String)}. + * See + * {@link com.rabbitmq.stream.MessageBuilder.PropertiesBuilder#replyToGroupId(String)}. * @param replyToGroupId the reply to group id. */ public void setReplyToGroupId(String replyToGroupId) { this.replyToGroupId = replyToGroupId; } + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + Objects.hash(creationTime, groupId, groupSequence, replyToGroupId, subject, to); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + StreamMessageProperties other = (StreamMessageProperties) obj; + return this.creationTime == other.creationTime && Objects.equals(this.groupId, other.groupId) + && this.groupSequence == other.groupSequence + && Objects.equals(this.replyToGroupId, other.replyToGroupId) + && Objects.equals(this.subject, other.subject) && Objects.equals(this.to, other.to); + } + } diff --git a/spring-rabbit-stream/src/main/java/org/springframework/rabbit/stream/support/converter/DefaultStreamMessageConverter.java b/spring-rabbit-stream/src/main/java/org/springframework/rabbit/stream/support/converter/DefaultStreamMessageConverter.java index e02f5b8c..76c6c0d7 100644 --- a/spring-rabbit-stream/src/main/java/org/springframework/rabbit/stream/support/converter/DefaultStreamMessageConverter.java +++ b/spring-rabbit-stream/src/main/java/org/springframework/rabbit/stream/support/converter/DefaultStreamMessageConverter.java @@ -106,7 +106,7 @@ public class DefaultStreamMessageConverter implements StreamMessageConverter { return builder.build(); } - private void mapProp(String key, Object val, ApplicationPropertiesBuilder builder) { + private void mapProp(String key, Object val, ApplicationPropertiesBuilder builder) { // NOSONAR - complexity if (val instanceof String) { builder.entry(key, (String) val); } diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/RabbitListenerEndpointRegistry.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/RabbitListenerEndpointRegistry.java index ca485864..5b20169f 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/RabbitListenerEndpointRegistry.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/RabbitListenerEndpointRegistry.java @@ -29,9 +29,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.BeansException; -import org.springframework.beans.factory.BeanInitializationException; import org.springframework.beans.factory.DisposableBean; -import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationListener; @@ -183,15 +181,7 @@ public class RabbitListenerEndpointRegistry implements DisposableBean, SmartLife RabbitListenerContainerFactory factory) { MessageListenerContainer listenerContainer = factory.createListenerContainer(endpoint); - - if (listenerContainer instanceof InitializingBean) { - try { - ((InitializingBean) listenerContainer).afterPropertiesSet(); - } - catch (Exception ex) { - throw new BeanInitializationException("Failed to initialize message listener container", ex); - } - } + listenerContainer.afterPropertiesSet(); int containerPhase = listenerContainer.getPhase(); if (containerPhase < Integer.MAX_VALUE) { // a custom phase value