JDK-6205431 : Attributes2Impl addAttribute throws ArrayIndexOutOfBoundsException
  • Type: Bug
  • Component: xml
  • Sub-Component: org.xml.sax
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-12-07
  • Updated: 2012-04-25
  • Resolved: 2007-06-28
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.0Resolved
Description
FULL PRODUCT VERSION :
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
The test to determine whether to grow the specified and declared arrays is backwards. Specifically in the addAttribute method, the comparison on line 232 of the file org.xml.sax.ext.Attributes2Impl.java currently reads:

	if (length < specified.length) {

This is incorrect and should be:

	if (length > specified.length) {

The incorrect comparison results in the "specified" and "declared" arrays being reallocated when they do not need to be, and not being reallocated when it needs to be thereby throwing an ArrayIndexOutOfBoundsException exception in line 244.

In addition, as a performance enhancement, I would suggest reallocating in chunks larger 1.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Instantiate an Attributes2Impl object. Call its addAttribute method. See the ArrayIndexOutOfBoundsException exception get thrown.


REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROND :
Create private copy of Attributes2Impl with the correct comparison.
###@###.### 2004-12-07 22:45:06 GMT
###@###.### 2005-2-01 08:36:14 GMT

Comments
EVALUATION This bug appeared to have been fixed two years ago. Refer to this change: http://fisheye5.cenqua.com/browse/jaxp-sources/jaxp-api/src/org/xml/sax/ext/Attributes2Impl.java?r1=1.1&r2=1.2 The comment was "sync with JAXP 1.4 CVS."
2007-06-28

EVALUATION Fix understood and in process of fixing ###@###.### 2005-2-01 09:14:20 GMT
2005-02-01