Skip to content

Commit 61f9195

Browse files
garyrussellartembilan
authored andcommitted
Do not deserialize in Message.toString()
# Conflicts: # spring-amqp/src/main/java/org/springframework/amqp/core/Message.java # spring-amqp/src/test/java/org/springframework/amqp/core/MessageTests.java
1 parent e29cd03 commit 61f9195

File tree

2 files changed

+5
-23
lines changed

2 files changed

+5
-23
lines changed

spring-amqp/src/main/java/org/springframework/amqp/core/Message.java

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,11 @@
1616

1717
package org.springframework.amqp.core;
1818

19-
import java.io.ByteArrayInputStream;
2019
import java.io.Serializable;
2120
import java.nio.charset.Charset;
2221
import java.util.Arrays;
23-
import java.util.LinkedHashSet;
24-
import java.util.Set;
2522

26-
import org.springframework.amqp.utils.SerializationUtils;
2723
import org.springframework.util.Assert;
28-
import org.springframework.util.ClassUtils;
2924

3025
/**
3126
* The 0-8 and 0-9-1 AMQP specifications do not define an Message class or interface. Instead, when performing an
@@ -48,9 +43,6 @@ public class Message implements Serializable {
4843

4944
private static final String DEFAULT_ENCODING = Charset.defaultCharset().name();
5045

51-
private static final Set<String> whiteListPatterns = // NOSONAR lower case static
52-
new LinkedHashSet<>(Arrays.asList("java.util.*", "java.lang.*"));
53-
5446
private static String bodyEncoding = DEFAULT_ENCODING;
5547

5648
private final MessageProperties messageProperties;
@@ -79,20 +71,12 @@ public Message(byte[] body, MessageProperties messageProperties) { //NOSONAR
7971
}
8072

8173
/**
82-
* Add patterns to the white list of permissable package/class name patterns for
83-
* deserialization in {@link #toString()}.
84-
* The patterns will be applied in order until a match is found.
85-
* A class can be fully qualified or a wildcard '*' is allowed at the
86-
* beginning or end of the class name.
87-
* Examples: {@code com.foo.*}, {@code *.MyClass}.
88-
* By default, only {@code java.util} and {@code java.lang} classes will be
89-
* deserialized.
74+
* No longer used.
75+
* @deprecated toString() no longer deserializes the body.
9076
* @param patterns the patterns.
9177
* @since 1.5.7
9278
*/
9379
public static void addWhiteListPatterns(String... patterns) {
94-
Assert.notNull(patterns, "'patterns' cannot be null");
95-
whiteListPatterns.addAll(Arrays.asList(patterns));
9680
}
9781

9882
/**
@@ -132,8 +116,7 @@ private String getBodyContentAsString() {
132116
boolean nullProps = this.messageProperties == null;
133117
String contentType = nullProps ? null : this.messageProperties.getContentType();
134118
if (MessageProperties.CONTENT_TYPE_SERIALIZED_OBJECT.equals(contentType)) {
135-
return SerializationUtils.deserialize(new ByteArrayInputStream(this.body), whiteListPatterns,
136-
ClassUtils.getDefaultClassLoader()).toString();
119+
return "[serialized object]";
137120
}
138121
String encoding = encoding(nullProps);
139122
if (MessageProperties.CONTENT_TYPE_TEXT_PLAIN.equals(contentType)

spring-amqp/src/test/java/org/springframework/amqp/core/MessageTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,8 @@ public void fooNotDeserialized() {
106106
Message listMessage = new SimpleMessageConverter().toMessage(Collections.singletonList(new Foo()),
107107
new MessageProperties());
108108
assertThat(listMessage.toString()).doesNotContainPattern("aFoo");
109-
Message.addWhiteListPatterns(Foo.class.getName());
110-
assertThat(message.toString()).contains("aFoo");
111-
assertThat(listMessage.toString()).contains("aFoo");
109+
assertThat(message.toString()).contains("[serialized object]");
110+
assertThat(listMessage.toString()).contains("[serialized object]");
112111
}
113112

114113
@SuppressWarnings("serial")

0 commit comments

Comments
 (0)