From e54609bb7638386b09d5e3cacf5f4430c5651fc7 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Wed, 7 Oct 2015 11:41:16 -0400 Subject: [PATCH] INT-3848: ERROR log for the `null` `beanName` JIRA: https://jira.spring.io/browse/INT-3848 When the `ConsumerEndpointFactoryBean` is created programmatically the `beanName` property may be missed and the `catch` for the `NPE` just hides an issue with the `DEBUG` log message. Add check for the `null` on the `bean` and log the issue on ERROR level. **Cherry-pick to the 4.1.x, 4.0.x and 3.0.x** --- .../config/ConsumerEndpointFactoryBean.java | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/ConsumerEndpointFactoryBean.java b/spring-integration-core/src/main/java/org/springframework/integration/config/ConsumerEndpointFactoryBean.java index 1c65641677..bba94b57b9 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/ConsumerEndpointFactoryBean.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/ConsumerEndpointFactoryBean.java @@ -139,23 +139,30 @@ public class ConsumerEndpointFactoryBean @Override public void afterPropertiesSet() throws Exception { - try { - if (!this.beanName.startsWith("org.springframework")) { - MessageHandler targetHandler = this.handler; - if (AopUtils.isAopProxy(targetHandler)) { - Object target = ((Advised) targetHandler).getTargetSource().getTarget(); - if (target instanceof MessageHandler) { - targetHandler = (MessageHandler) target; + if (this.beanName == null) { + logger.error("The MessageHandler [" + this.handler + "] will be created without a 'componentName'. " + + "Consider specifying the 'beanName' property on this ConsumerEndpointFactoryBean."); + } + else { + try { + if (!this.beanName.startsWith("org.springframework")) { + MessageHandler targetHandler = this.handler; + if (AopUtils.isAopProxy(targetHandler)) { + Object target = ((Advised) targetHandler).getTargetSource().getTarget(); + if (target instanceof MessageHandler) { + targetHandler = (MessageHandler) target; + } + } + if (targetHandler instanceof IntegrationObjectSupport) { + ((IntegrationObjectSupport) targetHandler).setComponentName(this.beanName); } } - if (targetHandler instanceof IntegrationObjectSupport) { - ((IntegrationObjectSupport) targetHandler).setComponentName(this.beanName); - } } - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("Could not set component name for handler " - + this.handler + " for " + this.beanName + " :" + e.getMessage()); + catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("Could not set component name for handler " + + this.handler + " for " + this.beanName + " :" + e.getMessage()); + } } } if (!CollectionUtils.isEmpty(this.adviceChain)) {