You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Rahul Akolkar <ra...@gmail.com> on 2008/02/27 22:07:46 UTC

Re: [beanutils] svn commit: r618207

On 2/4/08, niallp@apache.org <ni...@apache.org> wrote:
> Author: niallp
>  Date: Mon Feb  4 00:55:29 2008
>  New Revision: 618207
>
>  URL: http://svn.apache.org/viewvc?rev=618207&view=rev
>  Log:
>  Fix for BEANUTILS-302 - NPE in ArrayConverter when converting a string with underscores to a string array - reported by Martin Bartlett
>
>  Modified:
>     commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/ArrayConverter.java
>     commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/ArrayConverterTestCase.java
>
>  Modified: commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/ArrayConverter.java
>  URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/ArrayConverter.java?rev=618207&r1=618206&r2=618207&view=diff
>  ==============================================================================
>  --- commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/ArrayConverter.java (original)
>  +++ commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/ArrayConverter.java Mon Feb  4 00:55:29 2008
>  @@ -434,10 +434,12 @@
>              while (true) {
>                  int ttype = st.nextToken();
>                  if ((ttype == StreamTokenizer.TT_WORD) || (ttype > 0)) {
>  -                    if (list == null) {
>  -                        list = new ArrayList();
>  +                    if (st.sval != null) {
>  +                        if (list == null) {
>  +                            list = new ArrayList();
>  +                        }
>  +                        list.add(st.sval);
>                      }
>  -                    list.add(st.sval.trim());
<snip/>

No trim() vs. trim() -- desired change?

-Rahul



>                  } else if (ttype == StreamTokenizer.TT_EOF) {
>                      break;
>                  } else {
>
>  Modified: commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/ArrayConverterTestCase.java
>  URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/ArrayConverterTestCase.java?rev=618207&r1=618206&r2=618207&view=diff
>  ==============================================================================
>  --- commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/ArrayConverterTestCase.java (original)
>  +++ commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/ArrayConverterTestCase.java Mon Feb  4 00:55:29 2008
>  @@ -361,6 +361,33 @@
>      }
>
>      /**
>  +     * Test for BEANUTILS-302 - throwing a NPE when underscore used
>  +     */
>  +    public void testUnderscore_BEANUTILS_302() {
>  +        String value = "first_value,second_value";
>  +        ArrayConverter converter = new ArrayConverter(String[].class, new StringConverter());
>  +
>  +        // test underscore not allowed (the default)
>  +        String[] result = (String[])converter.convert(String[].class, value);
>  +        assertNotNull("result.null", result);
>  +        assertEquals("result.length", 4, result.length);
>  +        assertEquals("result[0]", "first", result[0]);
>  +        assertEquals("result[1]", "value", result[1]);
>  +        assertEquals("result[2]", "second", result[2]);
>  +        assertEquals("result[3]", "value", result[3]);
>  +
>  +        // configure the converter to allow underscore
>  +        converter.setAllowedChars(new char[] {'.', '-', '_'});
>  +
>  +        // test underscore allowed
>  +        result = (String[])converter.convert(String[].class, value);
>  +        assertNotNull("result.null", result);
>  +        assertEquals("result.length", 2, result.length);
>  +        assertEquals("result[0]", "first_value", result[0]);
>  +        assertEquals("result[1]", "second_value", result[1]);
>  +    }
>  +
>  +    /**
>       * Check that two arrays are the same.
>       * @param msg Test prefix msg
>       * @param expected Expected Array value
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [beanutils] svn commit: r618207

Posted by Rahul Akolkar <ra...@gmail.com>.
On 2/28/08, Niall Pemberton <ni...@gmail.com> wrote:
> On Wed, Feb 27, 2008 at 9:07 PM, Rahul Akolkar <ra...@gmail.com> wrote:
>  > On 2/4/08, niallp@apache.org <ni...@apache.org> wrote:
>  >  > Author: niallp
>  >  >  Date: Mon Feb  4 00:55:29 2008
>  >  >  New Revision: 618207
>  >  >
<snip/>
>  >
>  >  No trim() vs. trim() -- desired change?
>
>
> It was intentional -
<snap/>

OK, thanks.

-Rahul



> the original AbstractArrayConverter from which
>  this code was derived didn't trim - also this new ArrayConverter
>  delegates individual element conversion to an appropriate converter,
>  so those delegates could do this and, for example, the new numeric
>  converter implementations do trim (from memory) and so for numeric
>  arrays its not an issue.
>
>  Niall
>
>
>  >  -Rahul
>  >
>  >

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [beanutils] svn commit: r618207

Posted by Niall Pemberton <ni...@gmail.com>.
On Wed, Feb 27, 2008 at 9:07 PM, Rahul Akolkar <ra...@gmail.com> wrote:
> On 2/4/08, niallp@apache.org <ni...@apache.org> wrote:
>  > Author: niallp
>  >  Date: Mon Feb  4 00:55:29 2008
>  >  New Revision: 618207
>  >
>  >  URL: http://svn.apache.org/viewvc?rev=618207&view=rev
>  >  Log:
>  >  Fix for BEANUTILS-302 - NPE in ArrayConverter when converting a string with underscores to a string array - reported by Martin Bartlett
>  >
>  >  Modified:
>  >     commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/ArrayConverter.java
>  >     commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/ArrayConverterTestCase.java
>  >
>  >  Modified: commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/ArrayConverter.java
>  >  URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/ArrayConverter.java?rev=618207&r1=618206&r2=618207&view=diff
>  >  ==============================================================================
>  >  --- commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/ArrayConverter.java (original)
>  >  +++ commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/ArrayConverter.java Mon Feb  4 00:55:29 2008
>  >  @@ -434,10 +434,12 @@
>  >              while (true) {
>  >                  int ttype = st.nextToken();
>  >                  if ((ttype == StreamTokenizer.TT_WORD) || (ttype > 0)) {
>  >  -                    if (list == null) {
>  >  -                        list = new ArrayList();
>  >  +                    if (st.sval != null) {
>  >  +                        if (list == null) {
>  >  +                            list = new ArrayList();
>  >  +                        }
>  >  +                        list.add(st.sval);
>  >                      }
>  >  -                    list.add(st.sval.trim());
>  <snip/>
>
>  No trim() vs. trim() -- desired change?

It was intentional - the original AbstractArrayConverter from which
this code was derived didn't trim - also this new ArrayConverter
delegates individual element conversion to an appropriate converter,
so those delegates could do this and, for example, the new numeric
converter implementations do trim (from memory) and so for numeric
arrays its not an issue.

Niall

>  -Rahul
>
>
>
>  >                  } else if (ttype == StreamTokenizer.TT_EOF) {
>  >                      break;
>  >                  } else {
>  >
>  >  Modified: commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/ArrayConverterTestCase.java
>  >  URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/ArrayConverterTestCase.java?rev=618207&r1=618206&r2=618207&view=diff
>  >  ==============================================================================
>  >  --- commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/ArrayConverterTestCase.java (original)
>  >  +++ commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/ArrayConverterTestCase.java Mon Feb  4 00:55:29 2008
>  >  @@ -361,6 +361,33 @@
>  >      }
>  >
>  >      /**
>  >  +     * Test for BEANUTILS-302 - throwing a NPE when underscore used
>  >  +     */
>  >  +    public void testUnderscore_BEANUTILS_302() {
>  >  +        String value = "first_value,second_value";
>  >  +        ArrayConverter converter = new ArrayConverter(String[].class, new StringConverter());
>  >  +
>  >  +        // test underscore not allowed (the default)
>  >  +        String[] result = (String[])converter.convert(String[].class, value);
>  >  +        assertNotNull("result.null", result);
>  >  +        assertEquals("result.length", 4, result.length);
>  >  +        assertEquals("result[0]", "first", result[0]);
>  >  +        assertEquals("result[1]", "value", result[1]);
>  >  +        assertEquals("result[2]", "second", result[2]);
>  >  +        assertEquals("result[3]", "value", result[3]);
>  >  +
>  >  +        // configure the converter to allow underscore
>  >  +        converter.setAllowedChars(new char[] {'.', '-', '_'});
>  >  +
>  >  +        // test underscore allowed
>  >  +        result = (String[])converter.convert(String[].class, value);
>  >  +        assertNotNull("result.null", result);
>  >  +        assertEquals("result.length", 2, result.length);
>  >  +        assertEquals("result[0]", "first_value", result[0]);
>  >  +        assertEquals("result[1]", "second_value", result[1]);
>  >  +    }
>  >  +
>  >  +    /**
>  >       * Check that two arrays are the same.
>  >       * @param msg Test prefix msg
>  >       * @param expected Expected Array value
>  >
>  >
>  >
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>  For additional commands, e-mail: dev-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org