Skip to content

Commit 8efa84a

Browse files
committed
DefaultDeserializer.getClassLoader() instead of reflection
Related to: spring-projects/spring-framework#36827 (cherry picked from commit 7e31047) # Conflicts: # spring-integration-core/src/main/java/org/springframework/integration/support/converter/AllowListDeserializingConverter.java
1 parent a4d6827 commit 8efa84a

1 file changed

Lines changed: 4 additions & 11 deletions

File tree

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.LinkedHashSet;
2525
import java.util.Set;
2626

27-
import org.springframework.beans.DirectFieldAccessor;
2827
import org.springframework.core.ConfigurableObjectInputStream;
2928
import org.springframework.core.convert.converter.Converter;
3029
import org.springframework.core.serializer.DefaultDeserializer;
@@ -89,15 +88,8 @@ public AllowListDeserializingConverter(ClassLoader classLoader) {
8988
public AllowListDeserializingConverter(Deserializer<Object> deserializer) {
9089
Assert.notNull(deserializer, "Deserializer must not be null");
9190
this.deserializer = deserializer;
92-
if (deserializer instanceof DefaultDeserializer) {
93-
ClassLoader classLoader = null;
94-
try {
95-
classLoader = (ClassLoader) new DirectFieldAccessor(deserializer).getPropertyValue("classLoader");
96-
}
97-
catch (Exception e) {
98-
// no-op
99-
}
100-
this.defaultDeserializerClassLoader = classLoader;
91+
if (deserializer instanceof DefaultDeserializer defaultDeserializer) {
92+
this.defaultDeserializerClassLoader = defaultDeserializer.getClassLoader();
10193
this.usingDefaultDeserializer = true;
10294
}
10395
else {
@@ -109,7 +101,7 @@ public AllowListDeserializingConverter(Deserializer<Object> deserializer) {
109101
/**
110102
* Set simple patterns for allowable packages/classes for deserialization.
111103
* The patterns will be applied in order until a match is found.
112-
* A class can be fully qualified or a wildcard '*' is allowed at the
104+
* A class can be fully qualified, or a wildcard '*' is allowed at the
113105
* beginning or end of the class name.
114106
* Examples: {@code com.foo.*}, {@code *.MyClass}.
115107
* @param allowedPatterns the patterns.
@@ -160,6 +152,7 @@ protected Object deserialize(ByteArrayInputStream inputStream) throws IOExceptio
160152
@Override
161153
protected Class<?> resolveClass(ObjectStreamClass classDesc)
162154
throws IOException, ClassNotFoundException {
155+
163156
Class<?> clazz = super.resolveClass(classDesc);
164157
checkAllowList(clazz);
165158
return clazz;

0 commit comments

Comments
 (0)