camel-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tom So (JIRA)" <>
Subject [jira] [Created] (CAMEL-8118) BigDecimalPatternFormat overwrites Locale setting
Date Wed, 03 Dec 2014 13:16:12 GMT
Tom So created CAMEL-8118:

             Summary: BigDecimalPatternFormat overwrites Locale setting
                 Key: CAMEL-8118
             Project: Camel
          Issue Type: Bug
          Components: camel-bindy
    Affects Versions: 2.14.0
            Reporter: Tom So

Because of this change request ( 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:

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();
    DecimalFormat df = (DecimalFormat)getNumberFormat();
    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;

This message was sent by Atlassian JIRA

View raw message