[jdom-interest] Bug in AttributeList.java - part 2
Bradley S. Huffman
hip at a.cs.okstate.edu
Wed Feb 20 09:14:10 PST 2002
I ran your xml file and looked at the Elements/Attributes created and
didn't see any problems with AttributeList.
What's the value of attributesSize at line 196? If it's not the same as
line 187, someone is modifing it somewhere. Try printing attributes.size()
after line 204 and 209 to make sure those 2 methods are not modifing
element.
You don't have multiple threads operating on the same document? JDOM methods
are not syncronized.
Brad
Joan Roch writes:
> -----------------------------------------------------------------------------
> ---
> This bug report applies to:
> JDOM-b8-dev - Checked out from CVS on Feb. 20, 2002
> -----------------------------------------------------------------------------
> ---
>
> While trying to go around the supposed bug, I hit another one, most probably
> related, and that may help you pinpoint the problem in the AttributeList clas
> s.
>
> There seem to be a discrepancy between the reported number of Attributes in t
> he list and the actual number of Attributes. None of my methods modify the At
> tributeList in any way. I don't see right any other explanation for such an E
> xception being thrown, but I don't have the knowledge to point out this bug,
> nor the time to acquire that knowledge :(
>
> -----------------------------------------------------------------------------
> ---
>
> The error is the following:
>
> java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
> at java.util.ArrayList.RangeCheck(Unknown Source)
> at java.util.ArrayList.get(Unknown Source)
> at org.jdom.AttributeList.get(AttributeList.java:339)
> at com.ermis.html.XhtmlTemplate.exploreElement(XhtmlTemplate.java:198)
> at com.ermis.html.XhtmlTemplate.exploreElement(XhtmlTemplate.java:222)
> at com.ermis.html.XhtmlTemplate.exploreElement(XhtmlTemplate.java:222)
> at com.ermis.html.XhtmlTemplate.exploreElement(XhtmlTemplate.java:222)
> at com.ermis.html.XhtmlTemplate.exploreElement(XhtmlTemplate.java:222)
> at com.ermis.html.XhtmlTemplate.exploreElement(XhtmlTemplate.java:222)
> at com.ermis.html.XhtmlTemplate.exploreElement(XhtmlTemplate.java:222)
> at com.ermis.html.XhtmlTemplate.<init>(XhtmlTemplate.java:124)
> at com.ermis.html.XhtmlPage.<init>(XhtmlPage.java:68)
> at TemplateTest.main(TemplateTest.java:22)
>
> -----------------------------------------------------------------------------
> ---
>
> Here is my modified code in XhtmlTemplate:
>
> 184: private void exploreElement(Element element) {
> 185: // we first explore the attributes of the current Element
> 186: List attributes = element.getAttributes();
> 187: /* LOG */ logger.debug("*** Exploring: <" + element.getName() + "> "
> + attributes.size() + " attributes.");
> 188:
> 189:// BUG IN JDOM - AttributeList - Original code
> 190:// Iterator attributeIterator = attributes.iterator();
> 191:// while (attributeIterator.hasNext()) {
> 192:// Attribute attribute = (Attribute) attributeIterator.next();
> 193:// BUG IN JDOM - AttributeList - Original code
> 194:
> 195:// BUG IN JDOM - AttributeList - Temporary solution
> 196: int attributesSize = attributes.size();
> 197: for (int index = 0; index < attributesSize; index++) {
> 198: Attribute attribute = (Attribute) attributes.get(index);
> 199:// BUG IN JDOM - AttributeList - Temporary solution
> 200:
> 201: // we check if the attribute is the special identifier
> 202: if (attribute.getName().equals(IDENTIFIER)) {
> 203: // special identifier - we store the current element for future r
> eference
> 204: addIdentifiedElement(attribute.getValue(), element);
> 205: } else {
> 206: // normal attribute - we check if the attribute value contains a
> variable
> 207: REMatch[] variables = varRegExp.getAllMatches(attribute.getValue(
> ));
> 208: for (int i = 0; i < variables.length; i++) {
> 209: addVariableReference(variables[i].toString(1), attribute);
> 210: }
> 211: }
> 212: }
> [..]
>
>
> -----------------------------------------------------------------------------
> ---
>
> The LOG file output:
>
> 171 [main] INFO com.ermis.html.XhtmlTemplate - Template found at 'file:/C:/E
> rmis/ermismail/templates/LinkTrackingHelper-list.xhtml'
> 832 [main] DEBUG com.ermis.html.XhtmlTemplate - Template 'file:/C:/Ermis/erm
> ismail/templates/LinkTrackingHelper-list.xhtml' successfully parsed.
> 832 [main] DEBUG com.ermis.html.XhtmlTemplate - *** Exploring: <html> 0 attr
> ibutes.
> 842 [main] DEBUG com.ermis.html.XhtmlTemplate - *** Exploring: <head> 0 attr
> ibutes.
> 842 [main] DEBUG com.ermis.html.XhtmlTemplate - *** Exploring: <title> 0 att
> ributes.
> 842 [main] DEBUG com.ermis.html.XhtmlTemplate - Reference to ${ermis.mailing
> Id} found in 'org.jdom.Text'.
> 842 [main] DEBUG com.ermis.html.XhtmlTemplate - *** Exploring: <body> 0 attr
> ibutes.
> 852 [main] DEBUG com.ermis.html.XhtmlTemplate - *** Exploring: <p> 0 attribu
> tes.
> 852 [main] DEBUG com.ermis.html.XhtmlTemplate - *** Exploring: <b> 0 attribu
> tes.
> 852 [main] DEBUG com.ermis.html.XhtmlTemplate - Reference to ${ermis.mailing
> Id} found in 'org.jdom.Text'.
> 852 [main] DEBUG com.ermis.html.XhtmlTemplate - *** Exploring: <form> 2 attr
> ibutes.
> 852 [main] DEBUG com.ermis.html.XhtmlTemplate - Reference to ${ermis.servlet
> } found in 'org.jdom.Attribute'.
> 852 [main] DEBUG com.ermis.html.XhtmlTemplate - *** Exploring: <ermis> 1 att
> ributes.
> 852 [main] DEBUG com.ermis.html.XhtmlTemplate - <ermis ermis-id="trackable-l
> ink"> added.
> 852 [main] DEBUG com.ermis.html.XhtmlTemplate - *** Exploring: <table> 3 att
> ributes.
> 852 [main] DEBUG com.ermis.html.XhtmlTemplate - <table ermis-id="zling"> add
> ed.
> 852 [main] DEBUG com.ermis.html.XhtmlTemplate - *** Exploring: <tr> 0 attrib
> utes.
> 852 [main] DEBUG com.ermis.html.XhtmlTemplate - *** Exploring: <td> 1 attrib
> utes.
> 852 [main] DEBUG com.ermis.html.XhtmlTemplate - *** Exploring: <small> 0 att
> ributes.
> 852 [main] DEBUG com.ermis.html.XhtmlTemplate - Reference to ${ermis.url} fo
> und in 'org.jdom.Text'.
> 852 [main] DEBUG com.ermis.html.XhtmlTemplate - *** Exploring: <tr> 0 attrib
> utes.
> 852 [main] DEBUG com.ermis.html.XhtmlTemplate - *** Exploring: <td> 1 attrib
> utes.
> 852 [main] DEBUG com.ermis.html.XhtmlTemplate - *** Exploring: <input> 3 att
> ributes.
> 862 [main] DEBUG com.ermis.html.XhtmlTemplate - Reference to ${ermis.i} foun
> d in 'org.jdom.Attribute'.
> 862 [main] DEBUG com.ermis.html.XhtmlTemplate - *** Exploring: <td> 3 attrib
> utes.
> 862 [main] DEBUG com.ermis.html.XhtmlTemplate - <td ermis-id="gronk"> added.
> java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
> at java.util.ArrayList.RangeCheck(Unknown Source)
> at java.util.ArrayList.get(Unknown Source)
> at org.jdom.AttributeList.get(AttributeList.java:339)
> at com.ermis.html.XhtmlTemplate.exploreElement(XhtmlTemplate.java:198)
> at com.ermis.html.XhtmlTemplate.exploreElement(XhtmlTemplate.java:222)
> at com.ermis.html.XhtmlTemplate.exploreElement(XhtmlTemplate.java:222)
> at com.ermis.html.XhtmlTemplate.exploreElement(XhtmlTemplate.java:222)
> at com.ermis.html.XhtmlTemplate.exploreElement(XhtmlTemplate.java:222)
> at com.ermis.html.XhtmlTemplate.exploreElement(XhtmlTemplate.java:222)
> at com.ermis.html.XhtmlTemplate.exploreElement(XhtmlTemplate.java:222)
> at com.ermis.html.XhtmlTemplate.<init>(XhtmlTemplate.java:124)
> at com.ermis.html.XhtmlPage.<init>(XhtmlPage.java:68)
> at TemplateTest.main(TemplateTest.java:22)
>
> -----------------------------------------------------------------------------
> ---
>
> And the parsed XML file:
>
> <html>
> <head>
> <title>Mailing ID: ${mailingId}</title>
> </head>
> <body>
> <p><b>Mailing ID: ${mailingId}</b></p>
> <form method="post" action="${servlet}?action=save">
> <ermis ermis-id="trackable-link">
> <table border="1" width="100%" ermis-id="zling">
> <tr>
> <td colspan="2"><small>${url}</small></td></tr>
> <tr>
> <td valign="middle"><input name="track-${i}" type="checkbox" chec
> ked="true"/> Track?</td>
> <td ermis-id="gronk" valign="middle" width="100%">$text</td>
> </tr>
> <tr>
> <td valign="middle"><input name="type-${i}" value="product" type=
> "radio" checked="true"/> Product<br/>
> <input name="type-${i}" value="other" type="r
> adio"/> Other</td>
> <td valign="middle" width="100%">Description [${i}]: <textarea na
> me="desc-${i}" cols="80" rows="1">${desc}</textarea> [${i}]</td>
> </tr>
> </table><br/>
> </ermis>
> <input type="submit" value="Submit"/>
> </form>
> </body>
> </html>
>
> -----------------------------------------------------------------------------
> ---
>
>
>
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost
> .com
More information about the jdom-interest
mailing list