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

Fix check for primitive return types #96

Conversation

yuppie-flu
Copy link
Contributor

The current version of Baigan assumes that the return type of any configuration key MUST NOT be a primitive type (e.g. int, boolean in Java). One must use wrapper types instead (e.g. Integer, Boolean, etc.)

The library contains a check to validate this on Spring Context initialization. However, the validation code contains a bug:

 if (value.getClass().isPrimitive())

value here is already an object of type java.lang.Class for majority of the cases, including for primitive types. value.getClass() return a class for java.lang.Class itself, not the class for int or boolean for example.

The fix changes the expression to:

if (value instanceof Class && ((Class<?>)value).isPrimitive())

Also the PR moves the validation check to the ConfigurationBeanDefinitionRegistrar class to make the error message from the thrown exception appears during Spring Context initialization. When the check is located in BaiganConfigClasses, Spring hides the exact error message in a generic Spring Context initialization message.

@yuppie-flu yuppie-flu force-pushed the forbid-primitive-types branch from 8d82794 to 67b75ca Compare December 24, 2023 20:35
@lukasniemeier-zalando
Copy link
Collaborator

👍

@lukasniemeier-zalando lukasniemeier-zalando merged commit 51b8281 into zalando-incubator:main Jan 5, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants