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

ConvertUtilsBean doesn't handl conversion to String correctly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • Nightly Builds
    • 1.8.0
    • None
    • commons-beanutils-20070610-src.zip

    Description

      Either lookup(Class, Class) or convert(Object, Class) method doesn't work correctly in class ConvertUtilsBean.
      Problematic is the case when target class is String.

      The code from convert(..) which doesn't work:

      Object converted = value;
      Converter converter = lookup(sourceType, targetType);
      if (converter != null) {
      if (log.isTraceEnabled())

      { log.trace(" Using converter " + converter); }

      converted = converter.convert(targetType, value);
      }
      // here we already have converted value (String), but we will rewrite it by default .toString() - it's a bug
      if (targetType == String.class && value != null)

      { converted = value.toString(); }

      Attachments

        1. Test.java
          3 kB
          Josef Cacek

        Activity

          People

            niallp Niall Pemberton
            kwart Josef Cacek
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: