Bugs item #2789052, was opened at 2009-05-08 15:08
Message generated for change (Comment added) made by guigar
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=116035&aid=2789052&group_id=16035

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Matthias (kaeppler)
Assigned to: Nobody/Anonymous (nobody)
Summary: NamespaceStack.getAttributeQName caches incorrectly

Initial Comment:
Affects dom4j 1.6.1 (tested on Android 1.1 / Apache Harmony)

I just discovered a serious flaw in the caching of QName objects in 
NamespaceStack, which results in getting attributes by name only ever works for 
the first parsed attribute. The problem being with this method:

    public QName getAttributeQName(String namespaceURI, String localName,
            String qualifiedName) {
        if (qualifiedName == null) {
            qualifiedName = localName;
        }

        Map map = getNamespaceCache();
        QName answer = (QName) map.get(qualifiedName);

        if (answer != null) {
            return answer;
        }
    ...
    }

if qualifiedName is the empty string instead of null (which is the case for all 
attribute nodes being parsed), then this method always returns the same QName 
object from the cache! Hence, calling node.attribute("a") will return the 
attribute a if and only if it was parsed before all other attributes; for any 
other attribute name, that method returns null.

I don't have enough insight to tell whether the problem is with this exact 
method or if qualifiedName shouldn't ever be the empty string in the first 
place. One way or the other, it's broken.


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

Comment By: Guido (guigar)
Date: 2009-07-31 09:40

Message:
I am suffering exactly the same issue when using dom4j + android.  Every
call to obtain an attribute returns always the same (the first obtained)
attribute.

It can be fixed doing :

if (qualifiedName == null && !qualifiedName.equals("")) {
qualifiedName = localName;
}

But as Matthias said, I don't know if that is the right solution.

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

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=116035&aid=2789052&group_id=16035

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
dom4j-dev mailing list
dom4j-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-dev

Reply via email to