Attached is a fix for a couple issues in the Attributes2Impl class. This should resolve the following issues [1][2]. [1] https://sourceforge.net/tracker/index.php?func=detail&aid=1207064&group_id=29449&atid=396219 [2] http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6205431
Created attachment 17446 [details] Attributes2Impl patch A patch to resolve NPE and IndexOutOfBoundsExceptions.
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 exception. 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.
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.
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? func=detail&aid=1207064&group_id=29449&atid=396219 [3] http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6205431