Bugs item #2789052, was opened at 2009-05-08 18:08 Message generated for change (Comment added) made by latemic 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: Denys Nikolayenko (latemic) Date: 2011-03-18 16:08 Message: This change worked for me: public QName getAttributeQName(String namespaceURI, String localName, String qualifiedName) { // Fix: qualifiedName is empty on Android 2.1 if (qualifiedName == null || qualifiedName.length() == 0) { qualifiedName = localName; } ---------------------------------------------------------------------- Comment By: Denys Nikolayenko (latemic) Date: 2011-03-18 12:07 Message: It seems to be exactly my issue (http://stackoverflow.com/questions/4921674/android-1-5-and-dom4j-attributes-names-parsed-incorrectly) I tried two versions dom4j 1.6 and 2.0 alpha and it exists in both. For me the problems happens only on Android 2.1 emulator. Do you know exact reason for that ? Why it works fine for Android 2.2 ? ---------------------------------------------------------------------- Comment By: Guido (guigar) Date: 2009-07-31 12: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 ------------------------------------------------------------------------------ Colocation vs. Managed Hosting A question and answer guide to determining the best fit for your organization - today and in the future. http://p.sf.net/sfu/internap-sfd2d _______________________________________________ dom4j-dev mailing list dom4j-dev@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/dom4j-dev