[ https://issues.apache.org/jira/browse/XMLBEANS-404?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12856151#action_12856151 ]
Stanislav Tsvetkov commented on XMLBEANS-404: --------------------------------------------- We run into this issue as well. It is happening when a value in CDATA ends with "]". For example: "test for XMLBEANS-404 it happens when we are working with array element[n]" We've decided not to patch XMLBEANS, but to implement a very simple workaround in our code. If a value has an extra space after "]" XMLBEANS works fine without any patch. /* * this fix for xmlbeans issue with CDATA */ private String xmlBeansFix(String val) { if (val.endsWith("]")) val += " "; return val; } > entitizeContent CDATA loop iterating too many times (causes assertion error > or ArrayIndexOutOfBoundsException in replace) > ------------------------------------------------------------------------------------------------------------------------- > > Key: XMLBEANS-404 > URL: https://issues.apache.org/jira/browse/XMLBEANS-404 > Project: XMLBeans > Issue Type: Bug > Affects Versions: Version 2.4 > Reporter: Andrew Parker > Priority: Critical > > In the entitizeContent routine in Saver.java there is a loop responsible for > modifying bad characters and the ">" in "]]>" when surrounding the text with > "<![CDATA[" and "]]>". The loop iterates _lastEmitCch times, but the first > two characters of the text have already been processed. > This causes problems in one of two rare scenarios: > The last character in _buf is a ']' and the next two unused characters are > ']' and '>' respectively > The last two characters in _buf are both ']' and the next unused character > is a '>' > In these instances replace invokes System.arraycopy with invalid parameters > as i is outside of the normal _out/_in range resulting in an > ArrayIndexOutOfBoundsException or an assertion error is they are enabled. > In addition, the first two characters are not checked against isBadChar as > they're processed outside of this loop. > I believe that a quick and dirty fix for the ArrayIndexOutOfBoundsException > (but not isBadChar) would be to change this particular loop from: > for ( int cch = _lastEmitCch ; cch > 0 ; cch-- ) > to > for ( int cch = _lastEmitCch ; cch > 2; cch-- ) > We don't get the isBadChar problem, so I would be grateful if you could > confirm the quick and dirty fix above fixes the > ArrayIndexOutOfBoundsException as I'd like to patch our production system. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@xmlbeans.apache.org For additional commands, e-mail: dev-h...@xmlbeans.apache.org