Skip to content

Commit a01d09f

Browse files
garyrussellartembilan
authored andcommitted
Sonar Fixes
Final critical smells.
1 parent 761af27 commit a01d09f

File tree

9 files changed

+25
-32
lines changed

9 files changed

+25
-32
lines changed

spring-integration-core/src/main/java/org/springframework/integration/selector/MetadataStoreSelector.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2017 the original author or authors.
2+
* Copyright 2014-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,6 +46,8 @@
4646
* or {@link org.springframework.integration.handler.advice.IdempotentReceiverInterceptor}.
4747
*
4848
* @author Artem Bilan
49+
* @author Gary Russell
50+
*
4951
* @since 4.1
5052
*/
5153
public class MetadataStoreSelector implements MessageSelector {
@@ -81,9 +83,10 @@ public MetadataStoreSelector(MessageProcessor<String> keyStrategy, MessageProces
8183
@Override
8284
public boolean accept(Message<?> message) {
8385
String key = this.keyStrategy.processMessage(message);
86+
Long timestamp = message.getHeaders().getTimestamp();
8487
String value = (this.valueStrategy != null)
8588
? this.valueStrategy.processMessage(message)
86-
: Long.toString(message.getHeaders().getTimestamp());
89+
: (timestamp == null ? "0" : Long.toString(timestamp));
8790

8891
return this.metadataStore.putIfAbsent(key, value) == null;
8992
}

spring-integration-core/src/main/java/org/springframework/integration/store/SimpleMessageStore.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ public MessageMetadata getMessageMetadata(UUID id) {
198198
Message<?> message = getMessage(id);
199199
if (message != null) {
200200
MessageMetadata messageMetadata = new MessageMetadata(id);
201-
messageMetadata.setTimestamp(message.getHeaders().getTimestamp());
201+
Long timestamp = message.getHeaders().getTimestamp();
202+
messageMetadata.setTimestamp(timestamp == null ? 0L : timestamp);
202203
return messageMetadata;
203204
}
204205
else {

spring-integration-core/src/main/java/org/springframework/integration/support/AbstractIntegrationMessageBuilder.java

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ public AbstractIntegrationMessageBuilder<T> filterAndCopyHeadersIfAbsent(Map<Str
163163
return copyHeadersIfAbsent(headers);
164164
}
165165

166+
@Nullable
166167
protected abstract List<List<Object>> getSequenceDetails();
167168

168169
protected abstract Object getCorrelationId();

spring-integration-core/src/main/java/org/springframework/integration/support/MessageBuilder.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -201,11 +201,13 @@ public MessageBuilder<T> copyHeadersIfAbsent(@Nullable Map<String, ?> headersToC
201201

202202
@SuppressWarnings("unchecked")
203203
@Override
204+
@Nullable
204205
protected List<List<Object>> getSequenceDetails() {
205206
return (List<List<Object>>) this.headerAccessor.getHeader(IntegrationMessageHeaderAccessor.SEQUENCE_DETAILS);
206207
}
207208

208209
@Override
210+
@Nullable
209211
protected Object getCorrelationId() {
210212
return this.headerAccessor.getCorrelationId();
211213
}

spring-integration-core/src/main/java/org/springframework/integration/support/MutableMessage.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.io.Serializable;
2020
import java.util.Map;
21+
import java.util.UUID;
2122

2223
import org.springframework.integration.store.SimpleMessageStore;
2324
import org.springframework.lang.Nullable;
@@ -112,7 +113,9 @@ public boolean equals(Object obj) {
112113
}
113114
if (obj != null && obj instanceof MutableMessage<?>) {
114115
MutableMessage<?> other = (MutableMessage<?>) obj;
115-
return (this.headers.getId().equals(other.headers.getId()) &&
116+
UUID thisId = this.headers.getId();
117+
UUID otherId = other.headers.getId();
118+
return (ObjectUtils.nullSafeEquals(thisId, otherId) &&
116119
this.headers.equals(other.headers) && this.payload.equals(other.payload));
117120
}
118121
return false;

spring-integration-core/src/main/java/org/springframework/integration/support/converter/WhiteListDeserializingConverter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -134,7 +134,7 @@ public Object convert(byte[] source) {
134134
return this.deserializer.deserialize(byteStream);
135135
}
136136
}
137-
catch (Throwable ex) {
137+
catch (Exception ex) {
138138
throw new SerializationFailedException("Failed to deserialize payload. " +
139139
"Is the byte array a result of corresponding serialization for " +
140140
this.deserializer.getClass().getSimpleName() + "?", ex);

spring-integration-redis/src/main/java/org/springframework/integration/redis/inbound/RedisQueueInboundGateway.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,10 @@ private void receiveAndReply() {
208208
if (value != null) {
209209
if (!this.active) {
210210
this.template.boundListOps(uuid).rightPush(value);
211-
this.boundListOperations.rightPush(stringSerializer.serialize(uuid));
211+
byte[] serialized = stringSerializer.serialize(uuid);
212+
if (serialized != null) {
213+
this.boundListOperations.rightPush(serialized);
214+
}
212215
return;
213216
}
214217
if (this.extractPayload) {

spring-integration-stream/src/main/java/org/springframework/integration/stream/ByteStreamWritingMessageHandler.java

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,9 +20,6 @@
2020
import java.io.IOException;
2121
import java.io.OutputStream;
2222

23-
import org.apache.commons.logging.Log;
24-
import org.apache.commons.logging.LogFactory;
25-
2623
import org.springframework.integration.handler.AbstractMessageHandler;
2724
import org.springframework.messaging.Message;
2825
import org.springframework.messaging.MessageHandler;
@@ -32,11 +29,10 @@
3229
* A {@link MessageHandler} that writes a byte array to an {@link OutputStream}.
3330
*
3431
* @author Mark Fisher
32+
* @author Gary Russell
3533
*/
3634
public class ByteStreamWritingMessageHandler extends AbstractMessageHandler {
3735

38-
private final Log logger = LogFactory.getLog(this.getClass());
39-
4036
private final BufferedOutputStream stream;
4137

4238

@@ -61,12 +57,6 @@ public String getComponentType() {
6157
@Override
6258
protected void handleMessageInternal(Message<?> message) {
6359
Object payload = message.getPayload();
64-
if (payload == null) {
65-
if (this.logger.isWarnEnabled()) {
66-
this.logger.warn(this.getClass().getSimpleName() + " received null object");
67-
}
68-
return;
69-
}
7060
try {
7161
if (payload instanceof String) {
7262
this.stream.write(((String) payload).getBytes());

spring-integration-stream/src/main/java/org/springframework/integration/stream/CharacterStreamWritingMessageHandler.java

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,9 +24,6 @@
2424
import java.io.UnsupportedEncodingException;
2525
import java.io.Writer;
2626

27-
import org.apache.commons.logging.Log;
28-
import org.apache.commons.logging.LogFactory;
29-
3027
import org.springframework.integration.handler.AbstractMessageHandler;
3128
import org.springframework.messaging.Message;
3229
import org.springframework.messaging.MessageHandler;
@@ -41,11 +38,10 @@
4138
* {@link #setShouldAppendNewLine(boolean) shouldAppendNewLine} flag to 'true'. It is 'false' by default.
4239
*
4340
* @author Mark Fisher
41+
* @author Gary Russell
4442
*/
4543
public class CharacterStreamWritingMessageHandler extends AbstractMessageHandler {
4644

47-
private final Log logger = LogFactory.getLog(this.getClass());
48-
4945
private final BufferedWriter writer;
5046

5147
private volatile boolean shouldAppendNewLine = false;
@@ -136,12 +132,6 @@ public String getComponentType() {
136132
@Override
137133
protected void handleMessageInternal(Message<?> message) {
138134
Object payload = message.getPayload();
139-
if (payload == null) {
140-
if (this.logger.isWarnEnabled()) {
141-
this.logger.warn("target received null payload");
142-
}
143-
return;
144-
}
145135
try {
146136
if (payload instanceof String) {
147137
this.writer.write((String) payload);

0 commit comments

Comments
 (0)