[jdom-interest] Bug in AttributeList.java - part 2

Joan Roch joanr at k-os.com
Wed Feb 20 07:30:06 PST 2002


--------------------------------------------------------------------------------
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 class.

There seem to be a discrepancy between the reported number of Attributes in the list and the actual number of Attributes. None of my methods modify the AttributeList in any way. I don't see right any other explanation for such an Exception 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 reference
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:/Ermis/ermismail/templates/LinkTrackingHelper-list.xhtml'
832 [main] DEBUG com.ermis.html.XhtmlTemplate  - Template 'file:/C:/Ermis/ermismail/templates/LinkTrackingHelper-list.xhtml' successfully parsed.
832 [main] DEBUG com.ermis.html.XhtmlTemplate  - *** Exploring: <html> 0 attributes.
842 [main] DEBUG com.ermis.html.XhtmlTemplate  - *** Exploring: <head> 0 attributes.
842 [main] DEBUG com.ermis.html.XhtmlTemplate  - *** Exploring: <title> 0 attributes.
842 [main] DEBUG com.ermis.html.XhtmlTemplate  - Reference to ${ermis.mailingId} found in 'org.jdom.Text'.
842 [main] DEBUG com.ermis.html.XhtmlTemplate  - *** Exploring: <body> 0 attributes.
852 [main] DEBUG com.ermis.html.XhtmlTemplate  - *** Exploring: <p> 0 attributes.
852 [main] DEBUG com.ermis.html.XhtmlTemplate  - *** Exploring: <b> 0 attributes.
852 [main] DEBUG com.ermis.html.XhtmlTemplate  - Reference to ${ermis.mailingId} found in 'org.jdom.Text'.
852 [main] DEBUG com.ermis.html.XhtmlTemplate  - *** Exploring: <form> 2 attributes.
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 attributes.
852 [main] DEBUG com.ermis.html.XhtmlTemplate  - <ermis ermis-id="trackable-link"> added.
852 [main] DEBUG com.ermis.html.XhtmlTemplate  - *** Exploring: <table> 3 attributes.
852 [main] DEBUG com.ermis.html.XhtmlTemplate  - <table ermis-id="zling"> added.
852 [main] DEBUG com.ermis.html.XhtmlTemplate  - *** Exploring: <tr> 0 attributes.
852 [main] DEBUG com.ermis.html.XhtmlTemplate  - *** Exploring: <td> 1 attributes.
852 [main] DEBUG com.ermis.html.XhtmlTemplate  - *** Exploring: <small> 0 attributes.
852 [main] DEBUG com.ermis.html.XhtmlTemplate  - Reference to ${ermis.url} found in 'org.jdom.Text'.
852 [main] DEBUG com.ermis.html.XhtmlTemplate  - *** Exploring: <tr> 0 attributes.
852 [main] DEBUG com.ermis.html.XhtmlTemplate  - *** Exploring: <td> 1 attributes.
852 [main] DEBUG com.ermis.html.XhtmlTemplate  - *** Exploring: <input> 3 attributes.
862 [main] DEBUG com.ermis.html.XhtmlTemplate  - Reference to ${ermis.i} found in 'org.jdom.Attribute'.
862 [main] DEBUG com.ermis.html.XhtmlTemplate  - *** Exploring: <td> 3 attributes.
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" checked="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="radio"/> Other</td>
            <td valign="middle" width="100%">Description [${i}]: <textarea name="desc-${i}" cols="80" rows="1">${desc}</textarea> [${i}]</td>
          </tr>
        </table><br/>
      </ermis>
      <input type="submit" value="Submit"/>
    </form>
  </body>
</html>

--------------------------------------------------------------------------------






More information about the jdom-interest mailing list