Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
2.14.0
-
None
-
Novice
Description
Because of this change request (https://issues.apache.org/jira/browse/CAMEL-7742) was a new feature implemented that allows pattern annotations for BigDecimal fields in CSV model classes for the Camel Bindy component.
The problem with that is, that the usage of this feature overwrites the current Locale setting of the environment. For example, if the current Locale was set to "German" and the provided pattern for the BigDecimal field requires "US" to unmarshal the numbers in the CSV file, then the method BigDecimalPatternFormat#parse(String) overwrites the Locale, but doesn't restore the former setting. This can cause problems for other software components that depends on the Locale setting.
The cause of the problem can be found here on line 21: Source of BigDecimalPatternFormat
A possible workaround would be storing the current locale temporarily, overwrite that setting, perform the formatting task and then restore the former locale setting.
Like in this code example:
if (getNumberFormat() != null) { final Locale currentLocale = Locale.getDefault(); Locale.setDefault(super.getLocale()); DecimalFormat df = (DecimalFormat)getNumberFormat(); df.setParseBigDecimal(true); BigDecimal bd = (BigDecimal)df.parse(string.trim()); if(super.getPrecision() != -1) { bd = bd.setScale(super.getPrecision(), RoundingMode.valueOf(super.getRounding())); } Locale.getDefault(); // what is the purpose of this line? Locale.setDefault(currentLocale); // restore the Locale setting return bd; }