Skip to content

Commit ed82463

Browse files
garyrussellartembilan
authored andcommitted
Do not deserialize in Message.toString()
1 parent 9371f8c commit ed82463

File tree

2 files changed

+6
-23
lines changed

2 files changed

+6
-23
lines changed

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

+4-20
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> ALLOWED_LIST_PATTERNS =
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,13 @@ public Message(byte[] body, MessageProperties messageProperties) { //NOSONAR
7971
}
8072

8173
/**
82-
* Add patterns to the allowed list of permissible 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
*/
79+
@Deprecated
9380
public static void addAllowedListPatterns(String... patterns) {
94-
Assert.notNull(patterns, "'patterns' cannot be null");
95-
ALLOWED_LIST_PATTERNS.addAll(Arrays.asList(patterns));
9681
}
9782

9883
/**
@@ -128,8 +113,7 @@ private String getBodyContentAsString() {
128113
try {
129114
String contentType = this.messageProperties.getContentType();
130115
if (MessageProperties.CONTENT_TYPE_SERIALIZED_OBJECT.equals(contentType)) {
131-
return SerializationUtils.deserialize(new ByteArrayInputStream(this.body), ALLOWED_LIST_PATTERNS,
132-
ClassUtils.getDefaultClassLoader()).toString();
116+
return "[serialized object]";
133117
}
134118
String encoding = encoding();
135119
if (MessageProperties.CONTENT_TYPE_TEXT_PLAIN.equals(contentType)

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

+2-3
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.addAllowedListPatterns(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)