-
Notifications
You must be signed in to change notification settings - Fork 37.7k
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
Accepting null as default value for a property [SPR-14896] #19462
Comments
Juergen Hoeller commented What does Generally speaking, specifying an empty String as a default value works against number types works as long as they are number wrappers (i.e. If you'd like to make a special String such as "null" work, you could specify it as a custom |
Antonio Anzivino commented Good point, if that is because of my custom property placeholder I will update my codebase accordingly. The EncryptedPropertyResolver class decrypts properties wrapped between special markers #ENC(xxxxxxx)#. Basically it queries all the configured PropertySources to obtain the plaintext property as encoded in the property file, then if it is wrapped in the special markers it will decrypt the ciphertext. I still think this issue is not related to #18943 because I can't see my property resolver in the stack trace. While the property resolver is enabled, the exception still occurs before the property resolver is called. I can update my stack trace with full information. The error occurs when creating beans that do not use encrypted properties. |
Antonio Anzivino commented Requesting to close as I needed to add the appropriate property to my EncrypedPropertyPlaceholderConfigurer. As per documentation, by default the system PropertyPlaceholderConfigurer does not set a nullValue, and since my special resolver (aimed at decrypting properties if encrypted) is a PropertyPlaceholderConfigurer, the nullValue must be applied to it
|
Antonio Anzivino opened SPR-14896 and commented
Very silly issue.
I have a configuration mechanism that is based on both XML and property files and I use SpEL with a custom property resolver (the same as #18943).
Example XML
Then in the property files, if I want not to use this component, I can set null to its value:
This requires a property password.oldValues to be defined in the property files.
Since I am maintaining an application already in production, I have been asked not to require additional properties. So I wanted to use null as default value (which is legal in my case) without adding a line to my property file. If I don't add the property, even empty, I get an exception
I have tried the following SpEL
The following article reminds that Integer.valueOf does not accept null, so it shall be treated in advance
https://stackoverflow.com/questions/15115772/why-integer-doesnt-solve-null-string
As for the solution, I don't care whether empty string or "null" (actually, "null" is a legitimate String) should be the correct solution, but Spring should be smart enough to parse it as a null number
Point of fix should be
org.springframework.util.NumberUtils.parseNumber(NumberUtils.java:208)
Open to discussion. I currently don't know about any workaround
Affects: 4.3.3
Issue Links:
The text was updated successfully, but these errors were encountered: