Bug 38316 - [sax][patch] Fix for Attributes2Impl issues
Summary: [sax][patch] Fix for Attributes2Impl issues
Status: NEW
Alias: None
Product: XmlCommons - Now in JIRA
Classification: Unclassified
Component: SAX (show other bugs)
Version: 1.x
Hardware: Other other
: P2 normal (vote)
Target Milestone: ---
Assignee: Commons Developers Mailing List
Depends on:
Reported: 2006-01-19 06:06 UTC by Nathan Beyer
Modified: 2006-02-24 23:23 UTC (History)
2 users (show)

Attributes2Impl patch (700 bytes, patch)
2006-01-19 06:08 UTC, Nathan Beyer
Details | Diff
Attributes2Impl.java Patch (13.66 KB, patch)
2006-01-31 03:47 UTC, Nathan Beyer
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nathan Beyer 2006-01-19 06:06:40 UTC
Attached is a fix for a couple issues in the Attributes2Impl class. This should
resolve the following issues [1][2].

[2] http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6205431
Comment 1 Nathan Beyer 2006-01-19 06:08:07 UTC
Created attachment 17446 [details]
Attributes2Impl patch

A patch to resolve NPE and IndexOutOfBoundsExceptions.
Comment 2 Michael Glavassevich 2006-01-23 06:27:27 UTC
Hi Nathan,

With your patch there still appear to be conditions where an 
ArrayIndexOutOfBoundsException could be thrown. Consider the case where the 
object has been cleared (which sets the length to zero). The call to 
System.arraycopy() assumes that the length of the new array is longer than the 
old one, but if length < declared.length that isn't true so you would get an 

Aside from the exceptions thrown, the current code also has a performance 
issue. With the new size of the array always set to the length of the attribute 
list, there will be a new array allocated and an array copy just about every 
time an attributed is added. AttributesImpl doubles the size of its String 
array when it runs out of space in the current one. The same should probably be 
done with the boolean arrays in Attributes2Impl.
Comment 3 Nathan Beyer 2006-01-31 03:47:21 UTC
Created attachment 17543 [details]
Attributes2Impl.java Patch

I completely rewrote the implementation of this class. I tried to model it
after the implementations of the AttributesImpl class.

Let me know what you think.
Comment 4 Michael Glavassevich 2006-02-25 08:23:50 UTC
Looks pretty good. A couple things jumped out at me while reviewing it. The use 
of java.util.Arrays creates a dependency on JDK 1.2. I'm pretty sure the SAX 
API otherwise compiles on JDK 1.1.8. The Arrays class is being used to set all 
of the values in the data array to false when the Attributes object is cleared. 
I don't see the benefit of that. It appears that when the data array is 
created, its initial size will always be 100 which seems a bit too large.

A discussion [1] has just started on the SAX development list which has sparked 
the possibility of a new maintenance release of SAX (I guess it would be SAX 
2.0.3). On the thread, I mentioned the bugs in Attributes2Impl and cited this 
report (in addition to the other two [2][3]). I would like to see the ASF copy 
of SAX stay in synch with the official distribution. Perhaps your patch will 
get merged into it. I'm going to hold off making changes here until there's a 
resolution in the SAX community.

[1] http://sourceforge.net/mailarchive/forum.php?thread_id=9795444&forum_id=1472
[2] https://sourceforge.net/tracker/index.php?
[3] http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6205431