On Wed, Feb 27, 2008 at 9:07 PM, Rahul Akolkar <[EMAIL PROTECTED]> wrote: > On 2/4/08, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]