Skip to content

Commit ab94a68

Browse files
committed
* Restore NPE check for the BeanFactory in the
`MessagingMethodInvokerHelper` to avoid breaking changes in the current point release * Some other polishing and optimizations in the `MessagingMethodInvokerHelper`
1 parent 0027357 commit ab94a68

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

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

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,9 @@ private MessagingMethodInvokerHelper(Object targetObject, Class<? extends Annota
398398
}
399399

400400
private boolean isProvidedMessageHandlerFactoryBean() {
401-
return getBeanFactory().containsBean(IntegrationContextUtils.MESSAGE_HANDLER_FACTORY_BEAN_NAME);
401+
BeanFactory beanFactory = getBeanFactory();
402+
return beanFactory != null
403+
&& beanFactory.containsBean(IntegrationContextUtils.MESSAGE_HANDLER_FACTORY_BEAN_NAME);
402404
}
403405

404406
private void createHandlerMethod() {
@@ -435,14 +437,14 @@ private void prepareEvaluationContext() throws Exception {
435437
if (this.expectedType != null) {
436438
Assert.state(context.getTypeConverter()
437439
.canConvert(TypeDescriptor.valueOf((this.method).getReturnType()), this.expectedType),
438-
"Cannot convert to expected type (" + this.expectedType + ") from " + this.method);
440+
() -> "Cannot convert to expected type (" + this.expectedType + ") from " + this.method);
439441
}
440442
}
441443
else {
442444
AnnotatedMethodFilter filter = new AnnotatedMethodFilter(this.annotationType, this.methodName,
443445
this.requiresReply);
444446
Assert.state(canReturnExpectedType(filter, targetType, context.getTypeConverter()),
445-
"Cannot convert to expected type (" + this.expectedType + ") from " + this.method);
447+
() -> "Cannot convert to expected type (" + this.expectedType + ") from " + this.method);
446448
context.registerMethodFilter(targetType, filter);
447449
}
448450
context.setVariable("target", this.targetObject);
@@ -703,9 +705,7 @@ && contentTypeIsJson(parameters.message)) {
703705

704706
}
705707
catch (Exception e) {
706-
if (logger.isDebugEnabled()) {
707-
logger.debug("Failed to convert from JSON", e);
708-
}
708+
logger.debug("Failed to convert from JSON", e);
709709
}
710710
}
711711
}
@@ -899,13 +899,14 @@ else if (!Modifier.isPublic(method1.getModifiers())) {
899899
}
900900

901901
Assert.state(!fallbackMethods.isEmpty() || !fallbackMessageMethods.isEmpty(),
902-
"Target object of type [" + this.targetObject.getClass() +
902+
() -> "Target object of type [" + this.targetObject.getClass() +
903903
"] has no eligible methods for handling Messages.");
904904

905-
Assert.isNull(ambiguousFallbackType.get(), "Found ambiguous parameter type [" + ambiguousFallbackType
906-
+ "] for method match: " + fallbackMethods.values());
905+
Assert.isNull(ambiguousFallbackType.get(),
906+
() -> "Found ambiguous parameter type [" + ambiguousFallbackType +
907+
"] for method match: " + fallbackMethods.values());
907908
Assert.isNull(ambiguousFallbackMessageGenericType.get(),
908-
"Found ambiguous parameter type ["
909+
() -> "Found ambiguous parameter type ["
909910
+ ambiguousFallbackMessageGenericType
910911
+ "] for method match: "
911912
+ fallbackMethods.values());
@@ -967,8 +968,9 @@ private void findSingleSpecifMethodOnInterfacesIfProxy(final Object targetObject
967968
}
968969

969970
private void checkSpelInvokerRequired(final Class<?> targetClass, Method methodArg, HandlerMethod handlerMethod) {
970-
UseSpelInvoker useSpel = AnnotationUtils.findAnnotation(AopUtils.getMostSpecificMethod(methodArg, targetClass),
971-
UseSpelInvoker.class);
971+
UseSpelInvoker useSpel =
972+
AnnotationUtils.findAnnotation(AopUtils.getMostSpecificMethod(methodArg, targetClass),
973+
UseSpelInvoker.class);
972974
if (useSpel == null) {
973975
useSpel = AnnotationUtils.findAnnotation(targetClass, UseSpelInvoker.class);
974976
}
@@ -1005,14 +1007,12 @@ private Class<?> getTargetClass(Object targetObject) {
10051007
try {
10061008
// Maybe a proxy with no target - e.g. gateway
10071009
Class<?>[] interfaces = ((Advised) targetObject).getProxiedInterfaces();
1008-
if (interfaces != null && interfaces.length == 1) {
1010+
if (interfaces.length == 1) {
10091011
targetClass = interfaces[0];
10101012
}
10111013
}
10121014
catch (Exception e) {
1013-
if (logger.isDebugEnabled()) {
1014-
logger.debug("Exception trying to extract interface", e);
1015-
}
1015+
logger.debug("Exception trying to extract interface", e);
10161016
}
10171017
}
10181018
}
@@ -1133,7 +1133,10 @@ public String toString() {
11331133
}
11341134

11351135
private String generateExpression(Method method) {
1136-
StringBuilder sb = new StringBuilder("#target." + method.getName() + "(");
1136+
StringBuilder sb =
1137+
new StringBuilder("#target.")
1138+
.append(method.getName())
1139+
.append('(');
11371140
Class<?>[] parameterTypes = method.getParameterTypes();
11381141
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
11391142
boolean hasUnqualifiedMapParameter = false;
@@ -1347,9 +1350,7 @@ public static class ParametersWrapper {
13471350
*/
13481351
public static Object getHeader(Map<?, ?> headers, String header) {
13491352
Object object = headers.get(header);
1350-
if (object == null) {
1351-
throw new IllegalArgumentException("required header not available: " + header);
1352-
}
1353+
Assert.notNull(object, () -> "required header not available: " + header);
13531354
return object;
13541355
}
13551356

0 commit comments

Comments
 (0)