[
https://issues.apache.org/jira/browse/XMLCOMMONS-1?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Elliotte Rusty Harold closed XMLCOMMONS-1.
------------------------------------------
> Correction to earlier AttributesImpl bug-fix
> --------------------------------------------
>
> Key: XMLCOMMONS-1
> URL: https://issues.apache.org/jira/browse/XMLCOMMONS-1
> Project: XML Commons
> Issue Type: Bug
> Components: XML Commons External (SAX)
> Affects Versions: 1.x
> Environment: Operating System: other
> Platform: Other
> Reporter: Glenn Marcy
> Priority: Major
>
> AttributesImpl.java includes a "fix" that changed the original:
> public void removeAttribute (int index)
> {
> if (index >= 0 && index < length) {
> if (index < length - 1) {
> System.arraycopy(data, (index+1)*5, data, index*5,
> (length-index)*5);
> }
> length--;
> } else {
> badIndex(index);
> }
> }
> to:
> public void removeAttribute (int index)
> {
> if (index >= 0 && index < length) {
> data[index*5] = null;
> data[index*5+1] = null;
> data[index*5+2] = null;
> data[index*5+3] = null;
> data[index*5+4] = null;
> if (index < length - 1) {
> System.arraycopy(data, (index+1)*5, data, index*5,
> (length-index-1)*5);
> }
> length--;
> } else {
> badIndex(index);
> }
> }
> The original code was clearing the entry at the new end of the list by
> copying
> the presumably empty entry "one past the end" over the last entry. The
> change
> correctly changed the length of the copy to no longer reference past the end
> of
> the data array, which would sometimes raise an ArrayIndexOutOfBoundsException.
> However, the code to clear the element being removed just before it is copied
> over can only be useful in the single case where the copy doesn't happen,
> i.e.
> the attr removed is the last one in the list. The correct code would always
> clear the entry that actually needs to be cleared, which is the one that was
> previously in the last position before one was removed. The following code
> does
> so:
> public void removeAttribute (int index)
> {
> if (index >= 0 && index < length) {
> if (index < length - 1) {
> System.arraycopy(data, (index+1)*5, data, index*5,
> (length-index-1)*5);
> }
> length--;
> data[length*5] = null;
> data[length*5+1] = null;
> data[length*5+2] = null;
> data[length*5+3] = null;
> data[length*5+4] = null;
> } else {
> badIndex(index);
> }
> }
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]