Skip to content

Commit ac23d8c

Browse files
artembilangaryrussell
authored andcommitted
INT-4467: Fix transformer-util package tangles
JIRA: https://jira.spring.io/browse/INT-4467 The package tangles is caused by the explicit classes declarations. * Since we use only method definitions from those classes, there is just enough to use class names and use reflection to get class objects and then get methods from them _The fix is fully compatible for back-porting_ **Cherry-pick to 5.0.x**
1 parent 9dcb28b commit ac23d8c

File tree

1 file changed

+34
-11
lines changed
  • spring-integration-core/src/main/java/org/springframework/integration/util

1 file changed

+34
-11
lines changed

spring-integration-core/src/main/java/org/springframework/integration/util/ClassUtils.java

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import java.util.Set;
2323
import java.util.function.Function;
2424

25-
import org.springframework.integration.core.GenericSelector;
26-
import org.springframework.integration.transformer.GenericTransformer;
2725
import org.springframework.util.ReflectionUtils;
2826

2927
/**
@@ -41,23 +39,48 @@ public abstract class ClassUtils {
4139
ReflectionUtils.findMethod(Function.class, "apply", (Class<?>[]) null);
4240

4341
/**
44-
* The {@link GenericSelector#accept(Object)} method object.
42+
* The {@code org.springframework.integration.core.GenericSelector#accept(Object)} method object.
4543
*/
46-
public static final Method SELECTOR_ACCEPT_METHOD =
47-
ReflectionUtils.findMethod(GenericSelector.class, "accept", (Class<?>[]) null);
44+
public static final Method SELECTOR_ACCEPT_METHOD;
4845

4946
/**
50-
* The {@link GenericSelector#accept(Object)} method object.
47+
* The {@code org.springframework.integration.transformer.GenericTransformer#transform(Object)} method object.
5148
*/
52-
public static final Method TRANSFORMER_TRANSFORM_METHOD =
53-
ReflectionUtils.findMethod(GenericTransformer.class, "transform", (Class<?>[]) null);
49+
public static final Method TRANSFORMER_TRANSFORM_METHOD;
5450

5551
/**
5652
* The {@code org.springframework.integration.handler.GenericHandler#handle(Object, Map)} method object.
5753
*/
5854
public static final Method HANDLER_HANDLE_METHOD;
5955

6056
static {
57+
Class<?> genericSelectorClass = null;
58+
try {
59+
genericSelectorClass =
60+
org.springframework.util.ClassUtils.forName(
61+
"org.springframework.integration.core.GenericSelector",
62+
org.springframework.util.ClassUtils.getDefaultClassLoader());
63+
}
64+
catch (ClassNotFoundException e) {
65+
ReflectionUtils.rethrowRuntimeException(e);
66+
}
67+
68+
SELECTOR_ACCEPT_METHOD = ReflectionUtils.findMethod(genericSelectorClass, "accept", (Class<?>[]) null);
69+
70+
Class<?> genericTransformerClass = null;
71+
try {
72+
genericTransformerClass =
73+
org.springframework.util.ClassUtils.forName(
74+
"org.springframework.integration.transformer.GenericTransformer",
75+
org.springframework.util.ClassUtils.getDefaultClassLoader());
76+
}
77+
catch (ClassNotFoundException e) {
78+
ReflectionUtils.rethrowRuntimeException(e);
79+
}
80+
81+
TRANSFORMER_TRANSFORM_METHOD =
82+
ReflectionUtils.findMethod(genericTransformerClass, "transform", (Class<?>[]) null);
83+
6184
Class<?> genericHandlerClass = null;
6285
try {
6386
genericHandlerClass =
@@ -77,7 +100,7 @@ public abstract class ClassUtils {
77100
* Map with primitive wrapper type as key and corresponding primitive
78101
* type as value, for example: Integer.class -> int.class.
79102
*/
80-
private static final Map<Class<?>, Class<?>> primitiveWrapperTypeMap = new HashMap<Class<?>, Class<?>>(8);
103+
private static final Map<Class<?>, Class<?>> primitiveWrapperTypeMap = new HashMap<>(8);
81104

82105

83106
static {
@@ -102,8 +125,8 @@ public static Class<?> findClosestMatch(Class<?> type, Set<Class<?>> candidates,
102125
}
103126
else if (failOnTie && typeDiffWeight < Integer.MAX_VALUE && (typeDiffWeight == minTypeDiffWeight)) {
104127
throw new IllegalStateException("Unresolvable ambiguity while attempting to find closest match for [" +
105-
type.getName() + "]. Candidate types [" + closestMatch.getName() + "] and [" + candidate.getName() +
106-
"] have equal weight.");
128+
type.getName() + "]. Candidate types [" + closestMatch.getName() + "] and [" +
129+
candidate.getName() + "] have equal weight.");
107130
}
108131
}
109132
return closestMatch;

0 commit comments

Comments
 (0)