Source:
<code>public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { <START> if (this.singletonsInstantiated) { <END> if (bean instanceof MessageChannelMetrics) { MessageChannelMetrics monitor = (MessageChannelMetrics) bean; this.channels.add(monitor); registerChannel(monitor); } else if (bean instanceof MessageProducer && bean instanceof Lifecycle) { registerProducer((MessageProducer) bean); } else if (bean instanceof AbstractEndpoint) { if (bean instanceof IntegrationConsumer) { IntegrationConsumer integrationConsumer = (IntegrationConsumer) bean; MessageHandler handler = integrationConsumer.getHandler(); if (handler instanceof MessageHandlerMetrics) { MessageHandlerMetrics messageHandlerMetrics = (MessageHandlerMetrics) handler; registerHandler(messageHandlerMetrics); this.handlers.add(messageHandlerMetrics); return bean; } } else if (bean instanceof SourcePollingChannelAdapter) { SourcePollingChannelAdapter pollingChannelAdapter = (SourcePollingChannelAdapter) bean; MessageSource<?> messageSource = pollingChannelAdapter.getMessageSource(); if (messageSource instanceof MessageSourceMetrics) { MessageSourceMetrics messageSourceMetrics = (MessageSourceMetrics) messageSource; registerSource(messageSourceMetrics); this.sources.add(messageSourceMetrics); return bean; } } registerEndpoint((AbstractEndpoint) bean); } } return bean; }</code><technical_language>RC, add a try {...} catch {...} fail soft (and log error) instead of failing hard (just in case regression issues)</technical_language>

Target:
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (this.singletonsInstantiated) { try { if (bean instanceof MessageChannelMetrics) { MessageChannelMetrics monitor = (MessageChannelMetrics) extractTarget(bean); this.channels.add(monitor); registerChannel(monitor); this.runtimeBeans.add(bean); } else if (bean instanceof MessageProducer && bean instanceof Lifecycle) { registerProducer((MessageProducer) bean); this.runtimeBeans.add(bean); } else if (bean instanceof AbstractEndpoint) { if (bean instanceof IntegrationConsumer) { IntegrationConsumer integrationConsumer = (IntegrationConsumer) bean; MessageHandler handler = integrationConsumer.getHandler(); if (handler instanceof MessageHandlerMetrics) { MessageHandlerMetrics messageHandlerMetrics = (MessageHandlerMetrics) extractTarget(handler); registerHandler(messageHandlerMetrics); this.handlers.add(messageHandlerMetrics); this.runtimeBeans.add(messageHandlerMetrics); return bean; } } else if (bean instanceof SourcePollingChannelAdapter) { SourcePollingChannelAdapter pollingChannelAdapter = (SourcePollingChannelAdapter) bean; MessageSource<?> messageSource = pollingChannelAdapter.getMessageSource(); if (messageSource instanceof MessageSourceMetrics) { MessageSourceMetrics messageSourceMetrics = (MessageSourceMetrics) extractTarget(messageSource); registerSource(messageSourceMetrics); this.sources.add(messageSourceMetrics); this.runtimeBeans.add(messageSourceMetrics); return bean; } } registerEndpoint((AbstractEndpoint) bean); this.runtimeBeans.add(bean); } } catch (Exception e) { logger.error("Could not register an MBean for: " + beanName, e); } } return bean; }