Community
Participate
Working Groups
Build Identifier: Version: 3.6.2.v201102251823 Build id: M20110210-1200 A call normalize(String value, boolean collapse) will result in a java.lang.StringIndexOutOfBoundsException: String index out of range: -1 when value contains only whitespaces. Line 179: buffer.deleteCharAt(i - offset++); //unsafe for String containing only whitespaces as it results in a boundary exception as stated earlier. Fix: Call to String.trim() before length check at line 158. Reproducible: Always Steps to Reproduce: 1. Create a XML document with a element enclosing whitespaces: e.g. <?xml version="1.0" encoding="UTF-8"?> <empty> </empty> 2. Call org.eclipse.emf.ecore.xml.XMLTypeUtil.normalize on element empty
Can you show me a string value I can pass that will display this problem. I can't reproduce it with any value I've tried, including null, an empty string, a string with one space, a string with two spaces, a string with three spaces, or anything else I tried. String[] EXAMPLES = { null, "", " ", " ", " ", " a ", "\n\ta\t\n"}; for (int i = 0; i < EXAMPLES.length; ++i) { for (int j = 0; j < 2; ++j) { System.out.println("'" + EXAMPLES[i] + "' -> '" + XMLTypeUtil.normalize(EXAMPLES[i], j !=0) + "'"); } } I don't know how to "call normalize on element empty". Please provide an actual test case I can run locally and then reopen.
Hi there, indeed your sample works pretty well for me, too! In fact the bug occurred when we were assign a value to an element of a DataObject (IBM WebSphere ESB Implementation specifc). The value is propagated down to XMLTypeUtil.normalize and is binary a string of spaces as printed via String.format("%x", new BigInteger( value )) -> 20 20 20 20 So the error might be somewhere in between as we have a valid String before and within calling XMLTypeUtil.norrmalize we'll end up with this StringIndexOutOfBoundsException. I'll have to catch what's propagated in the final call. Thanks so far!