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

FloatLocaleConverter cannot parse negative values

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.7.0
    • 1.8.0
    • None
    • Operating System: All
      Platform: All

    • 33841

    Description

      Problem found in Build 1.7

      LocaleBeanUtils.setProperty(bean, name, value);

      Does not handle negative values. When processing negative values the
      FloatLocaleConverter.parse(value, pattern) throws a ConversionException because
      of the following if test: -

      if(Math.abs(parsed.doubleValue() - parsed.floatValue()) >
      parsed.floatValue() * 0.00001) {
      throw new ConversionException(...);
      }

      This test will always fail for a valid negative value because the
      multiplication by 0.00001 will result in a negative value which will be less
      then the abs subtraction.

      A solution to this problem would be to check Math.abs(parsed.floatValue() *
      0.00001)

      We also suffer from the previously reported problem of the locale converters
      not supporting boolean to get round this problem we have to determine the
      property type and call either LocaleBeanUtils.setProperty() or
      BeanUtils.setProperty() this would be made easier if the: -

      protected Descriptor calculate(Object bean, String name)

      method was made public.

      Attachments

        Activity

          People

            niallp Niall Pemberton
            paul@jeek.co.uk Paul Jenkins
            Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: