Menu

#46 1.2 bug comparing missing attributes

Java_1.2
closed-fixed
None
5
2017-12-02
2008-12-04
No

There is a bug when comparing 2 xml fragments where one has a missing attribute, the error is reported correctly, but the xpath for the attribute being compared is incorrect. The test below produces:

Expected number of element attributes '2' but was '1' - comparing <bar...> at /foo[1]/bar[1] to <bar...> at /foo[1]/bar[1]
Expected attribute name 'y' but was 'null' - comparing <bar...> at /foo[1]/bar[1]/@a to <bar...> at /foo[1]/bar[1]/@a

The second diff says it is comparing attribute "y", but the xpath indicates attribute "a". Either the attribute in the xpath should be "y", or the xpath should only indicate /foo[1]/bar[1]

Matt

import java.util.List;

import org.custommonkey.xmlunit.DetailedDiff;
import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.XMLTestCase;

public class XmlUnitBug extends XMLTestCase {
public void testBug() throws Exception {
Diff myDiff = new Diff("<foo><bar a=\"x\" y=\"z\"/></foo>", "<foo><bar a=\"x\"/></foo>");
DetailedDiff myDDiff = new DetailedDiff(myDiff);

    List allDifferences = myDDiff.getAllDifferences\(\);
    for \(Object diff : allDifferences\) \{
        System.err.println\(diff\);
    \}
    assertTrue\(myDDiff.similar\(\)\);
\}

}

Discussion

  • Matthew Watson

    Matthew Watson - 2008-12-04

    I am using V1.2

     
  • Stefan Bodewig

    Stefan Bodewig - 2009-01-30

    confirmed, I have a failing unit test in my working copy now, and it would be in svn if sourceforge's svn let me.

    Hope to have a fix soon.

     
  • Stefan Bodewig

    Stefan Bodewig - 2009-01-30
    • milestone: --> Java_1.2
    • assigned_to: nobody --> bodewig
     
  • Stefan Bodewig

    Stefan Bodewig - 2009-01-30
    • status: open --> pending-fixed
     
  • SourceForge Robot

    This Tracker item was closed automatically by the system. It was
    previously set to a Pending status, and the original submitter
    did not respond within 14 days (the time period specified by
    the administrator of this Tracker).

     
  • SourceForge Robot

    • status: pending-fixed --> closed-fixed
     
  • Harikesh Kumar

    Harikesh Kumar - 2017-12-02

    Difference camparison fails when an element value is updated to null.
    Sample1: <root><firstChild>first</firstChild><secondChild>secondChild</secondChild></root>
    Sample2: <root><firstChild>first</firstChild><secondChild></secondChild></root>

    Diff diff = new Diff(oldXml, newXml);
    DetailedDiff detDiff = new DetailedDiff(diff);
    List<Difference> differences = detDiff.getAllDifferences();
    Collections.sort(differences, new Comparator<Difference>() {
    @Override
    public int compare(Difference o1, Difference o2) {
    int i = o2.getTestNodeDetail().getNode().compareDocumentPosition(o1.getTestNodeDetail().getNode());
    if(i == 2 || i == 8)
    return -1;
    else
    return 1;
    }
    });

            It throws NullPointerException at Collections.sort(....) method.
    
     
  • Stefan Bodewig

    Stefan Bodewig - 2017-12-02

    Harikesh, please don't comment on unrelated closed issues but create a new one if you think you've found a bug.

    In your case the NullPointerException probably stems from your comparator. Most likely there is a difference about an unmatched node (there is a text child node of secondChild in the control document but none in the test document). In the case of "missing nodes" one detail side of the Difference is null - which is the intended and documented behavior and so getTestNodeDetail() may be null and getTestNodeDetail().getNode() throws an exception.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.