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

StringArrayConvertor does not convert int[] to String[]

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • Nightly Builds
    • None
    • None
    • None
    • Operating System: other
      Platform: Other

    • 18297

    Description

      I would only report this bug with knowledge that an inconsistency exists in the
      BeanUtils converters. When using the converter IntegerArrayConverter, the
      converter attempts to parse a String[] to an int[], however it makes no attempt
      to do the far easier conversion from int[] to String[] in StringArrayConverter.
      This happens to be a very important conversion since multiple select boxes in
      html forms must be set at a string array even though the model often transfers
      data to the form as an int[]. The two conversions are equally important and it
      is, in my mind, a missing feature that the conversion exists in one case and not
      in the other. The follow is the necessary patch to add this convertor.

      — StringArrayConverter.java.orig 2003-03-21 04:43:17.000000000 -0500
      +++ StringArrayConverter.java 2003-03-21 04:43:20.000000000 -0500
      @@ -113,6 +113,10 @@

      // ------------------------------------------------------- Static Variables

      + /**
      + * <p> Model object for int arrays.</p>
      + */
      + private static int ints[] = new int[0];

      /**

      • <p>Model object for type comparisons.</p>
        @@ -149,6 +153,19 @@
        return (value);
        }

      + // Deal with the input value as an int array
      + if (ints.getClass() == value.getClass())
      + {
      + int[] values = (int[]) value;
      + String[] results = new String[values.length];
      + for (int i = 0; i < values.length; i++)
      +

      { + results[i] = new StringBuffer().append(values[i]).toString(); + }

      +
      + return (results);
      + }
      +
      // Parse the input value as a String into elements
      // and convert to the appropriate type
      try {

      As you can see, the added functionality is copied almost directly from
      IntegerArrayConverter.

      Attachments

        Activity

          People

            Unassigned Unassigned
            dan@mojavelinux.com Dan Allen
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: