Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error creating bean with name 'errorChannel' because of ClassCastException occurred in BeanPostProcessor globalErrorChannelCustomizer #2883

Closed
KirillMakrutin opened this issue Jan 15, 2024 · 1 comment
Labels
Milestone

Comments

@KirillMakrutin
Copy link

If 'errorChannel' bean has a custom definition, for example of amqp PointToPointSubscribableAmqpChannel, then an application fails to start because of thrown java.lang.ClassCastException happens in BeanPostProcessor globalErrorChannelCustomizer in BindingServiceConfiguration auto-configuration.

Actual behavior: globalErrorChannelCustomizer doesn't verify if errorChannel bean is of PublishSubscribeChannel before casting object:

@Bean
public static BeanPostProcessor globalErrorChannelCustomizer() {
    return new BeanPostProcessor() {
        @Override
        public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
            if ("errorChannel".equals(beanName)) {
                ((PublishSubscribeChannel) bean).setIgnoreFailures(true);
            }
            return bean;
        }
    };
}

Expected behavior: errorChannel object type must be verified before doing any cast on it to avoid java.lang.ClassCastException on application startup.

Version of the framework: tested on v.3.2.10, but this unsafe BeanPostProcessor declaration exist in main.

sobychacko added a commit that referenced this issue Jan 22, 2024
Resolves #2883

When an applicaiton provides a custom errorChannel bean that is not of type
`PublishSubscribeChannel`, the application fails to start with a CCE. This is
because `BindingServiceConfiguration` uses a hard cast on `PublishSubscribeChannel`
without pre-checking the channel type. Fixing this issue.
@sobychacko sobychacko modified the milestones: 4.1.1, 4.0.5 Jan 22, 2024
@sobychacko sobychacko added the bug label Jan 22, 2024
@sobychacko
Copy link
Contributor

@KirillMakrutin Thanks for reporting this. It is now addressed on the main branch (4.1.1-SNAPSHOT) and backported to 4.0.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants