-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Unclear error message on BeanPostProcessor returning null [SPR-11951] #15997
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
Comments
Stéphane Nicoll commented Your If you change your @Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (beanName.equals("string")) {
return null;
}
return bean;
} Then your context start and you get a There's nothing wrong to return |
Benoit Lacelle commented Hi Stéphane, I agree my BeanPostProcessor is not relevant. It was just for the sake of the unit-test readablity. My usecase is less trivial: I have some interface like the following:
I don't own it, so I did not know it was a BeanPostProcessor. My actual unit-test was like the following:
Given the error message, I was not lead to understand SomeBean was the BeanPostProcessor returning null. Maybe we should check ConfigurationClassPostProcessor beans are never turned to null. My question was rather: could we improve the error message? By 'Error creating bean with name 'string' defined in class blasd.apex.server.config.spring.autonomy.TestApexSourceConfigAutonomy$ConfigA: factory-bean 'testApexSourceConfigAutonomy.ConfigA' returned null', I understand that "testApexSourceConfigAutonomy.ConfigA" returned a null instance. While the issue is "'beanPostProcessor' returned a null instance for 'testApexSourceConfigAutonomy.ConfigA'" |
Benoit Lacelle commented I re-open just to be sure if it is possible to improve the error message. I agree it works as designed. |
Juergen Hoeller commented I've reworded the exception's message to "factory-bean 'myBean' (or a BeanPostProcessor involved) returned null" We don't clearly know why we got a null result at that point of processing (since we're obtaining another bean instance there, constructed completely independently, with no context transferred to us)... but we can at least point out that a BeanPostProcessor may have been involved. Juergen |
Benoit Lacelle opened SPR-11951 and commented
Hello,
If one has a BeanPostProcessor which returns null, then the laoding of the application contact would break with an exception not clear before knowing the actual issue.
Running the following test, :
one would get
This seems trivial, but I got an equivalent issue while using Mockito to mock an interface, which I was unaware to be a BeanPostProcessor: Mockito returned null on postProcessBeforeInitialization, leading to this issue but the error message (and even debugging) took me a few hours to understand what was happening.
Instead of "Error creating bean with name 'string' defined in class blasd.apex.server.config.spring.autonomy.TestApexSourceConfigAutonomy$ConfigA: factory-bean 'testApexSourceConfigAutonomy.ConfigA' returned null", I would have expected something like "BeanPostProcessor named "beanPostProcessor" returned null for 'testApexSourceConfigAutonomy.ConfigA'"
Thanks
Affects: 3.2.9, 4.0.3
Referenced from: commits 83a7deb, 077c624, 6c41cc3
Backported to: 3.2.10
The text was updated successfully, but these errors were encountered: