[jdom-interest] [Patch] Bug regarding attributes local name using JDOMResult

Mattias Jiderhamn mattias.jiderhamn at expertsystem.se
Mon Nov 21 23:53:00 PST 2005


At 2005-11-21 21:53, Elliotte Harold wrote:
>Mattias Jiderhamn wrote:
>>The only case when the current code would produce the expected 
>>output while the patched code would not, is if attQName contains 
>>both prefix and name while attLocalName is the empty string. I 
>>figured that if such a parser exists, it is erroneous and it 
>>shouldn't be JDOMs responsibility to handle this. But maybe I'm wrong here?
>
>Where and when SAX parsers report nulls and empty strings for the 
>qName and localName arguments is shockingly non-deterministic. Most 
>parsers do what you expect, but they're a few weird ones out there 
>that are still spec-conformant.
>...

I see. Below you will find a modified patch, that only changes the 
behaviour where the StringIndexOutOfBoundsException would previously be thrown.
Tested with Resin 2, Resin 3 and Xalan + Xerces.

   /Mattias Jiderhamn


Index: src/java/org/jdom/input/SAXHandler.java
===================================================================
RCS file: /home/cvspublic/jdom/src/java/org/jdom/input/SAXHandler.java,v
retrieving revision 1.71
diff -u -r1.71 SAXHandler.java
--- src/java/org/jdom/input/SAXHandler.java     11 Dec 2004 02:18:55 
-0000      1.71
+++ src/java/org/jdom/input/SAXHandler.java     22 Nov 2005 07:30:26 -0000
@@ -560,7 +560,11 @@
                  continue;
              }

-            if (!attQName.equals(attLocalName)) {
+            if ("".equals(attLocalName) && attQName.indexOf(":") == -1) {
+                attribute = factory.attribute(attQName, atts.getValue(i),
+                                              attType);
+                       }
+            else if (!attQName.equals(attLocalName)) {
                  String attPrefix = attQName.substring(0, 
attQName.indexOf(":"));
                  Namespace attNs = Namespace.getNamespace(attPrefix,
                                                           atts.getURI(i));



More information about the jdom-interest mailing list