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 "Michael Glavassevich (JIRA)" <xe...@xml.apache.org> on 2007/10/15 17:43:50 UTC

[jira] Resolved: (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:all-tabpanel ]

Michael Glavassevich resolved XERCESJ-1275.
-------------------------------------------

    Resolution: Duplicate

Duplicate of XERCESJ-1015.

==========================

The Javadoc for Reader.read(char[] cbuf, int off, int len) says:

Reads characters into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.

The Javadoc for InputStream.read(byte[] b, int off, int len) says:

"...

This method blocks until input data is available, end of file is detected, or an exception is thrown. 

If b is null, a NullPointerException is thrown. 

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown. 

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.

..."

Zero bytes will only be read if the length specified is zero, otherwise at least one byte will be read. When the length parameter is non-zero a *conforming* InputStream must return at least one byte (or one char in the case of a Reader) or -1 if the end of the stream has been reached. It sounds like the InputStream/Reader you are using is violating this condition and returning 0 instead of -1 at the end of the stream. This is a bug in the InputStream/Reader, not the parser and should be fixed at the source. When the stream is broken the parser shouldn't be guessing what it's trying to tell it.

> 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