Bugs item #3462449, was opened at 2011-12-19 06:53
Message generated for change (Comment added) made by spuckydaslama
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=116035&aid=3462449&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: dom4j 1.6.x
Status: Open
Resolution: None
Priority: 8
Private: No
Submitted By: Frank Jakop (maximalz)
Assigned to: Nobody/Anonymous (nobody)
Summary: NodeComparator NPE comparing element with different attribut

Initial Comment:
When I use the NodeComparator to compare two elements (or documents), which 
contain an element whose attribute's names are different, a NPE occurs.

XML 1
<element attribute1="value"/>

XML 2
<element attribute2="value"/>

new NodeComparator().compare(xml1, xml2) leads to

java.lang.NullPointerException
        at org.dom4j.util.NodeComparator.compare(NodeComparator.java:199)
        at org.dom4j.util.NodeComparator.compare(NodeComparator.java:184)
        ...


A JUnit-Test is attached.

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

Comment By: Daniel (spuckydaslama)
Date: 2012-01-24 02:34

Message:
i suggest the following patch:

Index: src/java/org/dom4j/util/NodeComparator.java
===================================================================
RCS file:
/cvsroot/dom4j/dom4j/src/java/org/dom4j/util/NodeComparator.java,v
retrieving revision 1.10
diff -u -r1.10 NodeComparator.java
--- src/java/org/dom4j/util/NodeComparator.java 29 Jan 2005 14:52:55
-0000   1.10
+++ src/java/org/dom4j/util/NodeComparator.java 24 Jan 2012 10:32:21 -0000
@@ -196,6 +196,9 @@
     }
 
     public int compare(Attribute n1, Attribute n2) {
+        if (n1 == null || n2 == null) {
+            return super.compare((Object) n1, (Object) n2);
+        }
         int answer = compare(n1.getQName(), n2.getQName());
 
         if (answer == 0) {


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

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

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
dom4j-dev mailing list
dom4j-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-dev

Reply via email to