Skip to content

Commit 38e15b6

Browse files
committed
GH-1352: Fix New Sonar Issues
1 parent 7c63133 commit 38e15b6

File tree

3 files changed

+45
-26
lines changed

3 files changed

+45
-26
lines changed

spring-rabbit-stream/src/main/java/org/springframework/rabbit/stream/support/StreamMessageProperties.java

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717
package org.springframework.rabbit.stream.support;
1818

19+
import java.util.Objects;
20+
1921
import org.springframework.amqp.core.MessageProperties;
2022
import org.springframework.lang.Nullable;
2123

22-
import com.rabbitmq.stream.MessageBuilder.PropertiesBuilder;
2324
import com.rabbitmq.stream.MessageHandler.Context;
24-
import com.rabbitmq.stream.Properties;
2525

2626
/**
2727
* {@link MessageProperties} extension for stream messages.
@@ -66,99 +66,128 @@ public Context getContext() {
6666
}
6767

6868
/**
69-
* See {@link Properties#getTo()}.
69+
* See {@link com.rabbitmq.stream.Properties#getTo()}.
7070
* @return the to address.
7171
*/
7272
public String getTo() {
7373
return this.to;
7474
}
7575

7676
/**
77-
* See {@link PropertiesBuilder#to(String)}.
77+
* See {@link com.rabbitmq.stream.MessageBuilder.PropertiesBuilder#to(String)}.
7878
* @param address the address.
7979
*/
8080
public void setTo(String address) {
8181
this.to = address;
8282
}
8383

8484
/**
85-
* See {@link Properties#getSubject()}.
85+
* See {@link com.rabbitmq.stream.Properties#getSubject()}.
8686
* @return the subject.
8787
*/
8888
public String getSubject() {
8989
return this.subject;
9090
}
9191

9292
/**
93-
* See {@link PropertiesBuilder#subject(String)}.
93+
* See {@link com.rabbitmq.stream.MessageBuilder.PropertiesBuilder#subject(String)}.
9494
* @param subject the subject.
9595
*/
9696
public void setSubject(String subject) {
9797
this.subject = subject;
9898
}
9999

100100
/**
101-
* See {@link Properties#getCreationTime()}.
101+
* See {@link com.rabbitmq.stream.Properties#getCreationTime()}.
102102
* @return the creation time.
103103
*/
104104
public long getCreationTime() {
105105
return this.creationTime;
106106
}
107107

108108
/**
109-
* See {@link PropertiesBuilder#creationTime(long)}.
109+
* See
110+
* {@link com.rabbitmq.stream.MessageBuilder.PropertiesBuilder#creationTime(long)}.
110111
* @param creationTime the creation time.
111112
*/
112113
public void setCreationTime(long creationTime) {
113114
this.creationTime = creationTime;
114115
}
115116

116117
/**
117-
* See {@link Properties#getGroupId()}.
118+
* See {@link com.rabbitmq.stream.Properties#getGroupId()}.
118119
* @return the group id.
119120
*/
120121
public String getGroupId() {
121122
return this.groupId;
122123
}
123124

124125
/**
125-
* See {@link PropertiesBuilder#groupId(String)}.
126+
* See {@link com.rabbitmq.stream.MessageBuilder.PropertiesBuilder#groupId(String)}.
126127
* @param groupId the group id.
127128
*/
128129
public void setGroupId(String groupId) {
129130
this.groupId = groupId;
130131
}
131132

132133
/**
133-
* See {@link Properties#getGroupSequence()}.
134+
* See {@link com.rabbitmq.stream.Properties#getGroupSequence()}.
134135
* @return the group sequence.
135136
*/
136137
public long getGroupSequence() {
137138
return this.groupSequence;
138139
}
139140

140141
/**
141-
* See {@link PropertiesBuilder#groupSequence(long)}.
142+
* See
143+
* {@link com.rabbitmq.stream.MessageBuilder.PropertiesBuilder#groupSequence(long)}.
142144
* @param groupSequence the group sequence.
143145
*/
144146
public void setGroupSequence(long groupSequence) {
145147
this.groupSequence = groupSequence;
146148
}
147149

148150
/**
149-
* See {@link Properties#getReplyToGroupId()}.
151+
* See {@link com.rabbitmq.stream.Properties#getReplyToGroupId()}.
150152
* @return the reply to group id.
151153
*/
152154
public String getReplyToGroupId() {
153155
return this.replyToGroupId;
154156
}
155157

156158
/**
157-
* See {@link PropertiesBuilder#replyToGroupId(String)}.
159+
* See
160+
* {@link com.rabbitmq.stream.MessageBuilder.PropertiesBuilder#replyToGroupId(String)}.
158161
* @param replyToGroupId the reply to group id.
159162
*/
160163
public void setReplyToGroupId(String replyToGroupId) {
161164
this.replyToGroupId = replyToGroupId;
162165
}
163166

167+
@Override
168+
public int hashCode() {
169+
final int prime = 31;
170+
int result = super.hashCode();
171+
result = prime * result + Objects.hash(creationTime, groupId, groupSequence, replyToGroupId, subject, to);
172+
return result;
173+
}
174+
175+
@Override
176+
public boolean equals(Object obj) {
177+
if (this == obj) {
178+
return true;
179+
}
180+
if (!super.equals(obj)) {
181+
return false;
182+
}
183+
if (getClass() != obj.getClass()) {
184+
return false;
185+
}
186+
StreamMessageProperties other = (StreamMessageProperties) obj;
187+
return this.creationTime == other.creationTime && Objects.equals(this.groupId, other.groupId)
188+
&& this.groupSequence == other.groupSequence
189+
&& Objects.equals(this.replyToGroupId, other.replyToGroupId)
190+
&& Objects.equals(this.subject, other.subject) && Objects.equals(this.to, other.to);
191+
}
192+
164193
}

spring-rabbit-stream/src/main/java/org/springframework/rabbit/stream/support/converter/DefaultStreamMessageConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public com.rabbitmq.stream.Message fromMessage(Message message) throws MessageCo
106106
return builder.build();
107107
}
108108

109-
private void mapProp(String key, Object val, ApplicationPropertiesBuilder builder) {
109+
private void mapProp(String key, Object val, ApplicationPropertiesBuilder builder) { // NOSONAR - complexity
110110
if (val instanceof String) {
111111
builder.entry(key, (String) val);
112112
}

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/RabbitListenerEndpointRegistry.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
import org.apache.commons.logging.LogFactory;
3030

3131
import org.springframework.beans.BeansException;
32-
import org.springframework.beans.factory.BeanInitializationException;
3332
import org.springframework.beans.factory.DisposableBean;
34-
import org.springframework.beans.factory.InitializingBean;
3533
import org.springframework.context.ApplicationContext;
3634
import org.springframework.context.ApplicationContextAware;
3735
import org.springframework.context.ApplicationListener;
@@ -183,15 +181,7 @@ protected MessageListenerContainer createListenerContainer(RabbitListenerEndpoin
183181
RabbitListenerContainerFactory<?> factory) {
184182

185183
MessageListenerContainer listenerContainer = factory.createListenerContainer(endpoint);
186-
187-
if (listenerContainer instanceof InitializingBean) {
188-
try {
189-
((InitializingBean) listenerContainer).afterPropertiesSet();
190-
}
191-
catch (Exception ex) {
192-
throw new BeanInitializationException("Failed to initialize message listener container", ex);
193-
}
194-
}
184+
listenerContainer.afterPropertiesSet();
195185

196186
int containerPhase = listenerContainer.getPhase();
197187
if (containerPhase < Integer.MAX_VALUE) { // a custom phase value

0 commit comments

Comments
 (0)