You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by "Konrad Windszus (JIRA)" <xe...@xml.apache.org> on 2007/10/16 09:27:50 UTC

[jira] Commented: (XERCESJ-1275) java.lang.ArrayIndexOutOfBoundsException at org.apache.xerces.impl.XMLEntityScanner.skipSpaces

    [ https://issues.apache.org/jira/browse/XERCESJ-1275?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12535170 ] 

Konrad Windszus commented on XERCESJ-1275:
------------------------------------------

I think the Javadoc is at least a littlebit misleading here. I found the following paragraph in the Doc of InputStream.read(...) 
...
"Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read, possibly zero. The number of bytes actually read is returned as an integer. "
...
That shows, that zero is a valid return value, although you could interpret it as allowed only in the case of len equals zero too.

"If len is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value -1 is returned; otherwise, at least one byte is read and stored into b. "

Nevertheless there is no statement about the return value in Reader.read(). Therefore I would suggest improving the behaviour of Xerces in the case, 0 is returned. It should be very easy to accomplish and shouldn't have any impact on the performance overall.



> java.lang.ArrayIndexOutOfBoundsException at org.apache.xerces.impl.XMLEntityScanner.skipSpaces
> ----------------------------------------------------------------------------------------------
>
>                 Key: XERCESJ-1275
>                 URL: https://issues.apache.org/jira/browse/XERCESJ-1275
>             Project: Xerces2-J
>          Issue Type: Bug
>    Affects Versions: 2.7.1, 2.9.1
>            Reporter: Konrad Windszus
>
> Under some rare circumstances you get an ArrayIndexOutOfBoundsException in Xerces. This is the case if the Reader you give with the SaxParser.parse-Method returns 0 for the method public int read(char[] cbuf, int off, int len) 
> This can lead to that exception.
> Apparently Xerces reads in the XML in chunks of 2048 bytes. If the last read(..) call returns 2048 filled bytes, and the following read returns 0 (although it should return -1) this exception occurs. You should prevent this by accepting 0 as valid return of read, although it does not indicate, that the end of file has been reached.
>     

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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