Uploaded image for project: 'Commons BeanUtils'
  1. Commons BeanUtils
  2. BEANUTILS-351

FloatLocaleConverter cannot parse 0

    XMLWordPrintableJSON

Details

    Description

      FloatLocaleConverter fails to parse the "0" string, complaining that the value is not of type Float.

      Doing new LocaleConvertUtilsBean().convert("0", Float.class, Locale.US, null) results in the following exception:

      Exception in thread "main" org.apache.commons.beanutils.ConversionException: Supplied number is not of type Float: 0
      at org.apache.commons.beanutils.locale.converters.FloatLocaleConverter.parse(FloatLocaleConverter.java:222)
      at org.apache.commons.beanutils.locale.BaseLocaleConverter.convert(BaseLocaleConverter.java:232)
      at org.apache.commons.beanutils.locale.LocaleConvertUtilsBean.convert(LocaleConvertUtilsBean.java:285)
      at Code.main(Code.java:65)

      Looking at the source of FloatLocaleConverter, line 221 which originally reads

      if (posDouble < Float.MIN_VALUE || posDouble > Float.MAX_VALUE) {

      should be changed to

      if ((posDouble > 0 && posDouble < Float.MIN_VALUE) || posDouble > Float.MAX_VALUE) {

      in order to fix the bug.

      Attachments

        Activity

          People

            niallp Niall Pemberton
            lucianc Lucian Chirita
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: