This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/master by this push:
     new 54dabcba70 Fix XmlNode.equals returning false between two different 
node implementations (#10942) (#10947)
54dabcba70 is described below

commit 54dabcba70c4b11c93f383ed5302108518f4b47e
Author: Guillaume Nodet <[email protected]>
AuthorDate: Sat Jul 19 13:09:56 2025 +0200

    Fix XmlNode.equals returning false between two different node 
implementations (#10942) (#10947)
    
    (cherry picked from commit 2b1346fe29fdfbef89559c522601de3089fa05b9)
---
 .../src/main/java/org/apache/maven/api/xml/XmlNode.java | 17 ++++++-----------
 .../java/org/apache/maven/internal/xml/XmlNodeImpl.java | 17 ++++++-----------
 .../org/apache/maven/internal/xml/XmlNodeImplTest.java  | 12 ++++++++++++
 3 files changed, 24 insertions(+), 22 deletions(-)

diff --git 
a/api/maven-api-xml/src/main/java/org/apache/maven/api/xml/XmlNode.java 
b/api/maven-api-xml/src/main/java/org/apache/maven/api/xml/XmlNode.java
index 54a6c3443b..7cf78c9cc1 100644
--- a/api/maven-api-xml/src/main/java/org/apache/maven/api/xml/XmlNode.java
+++ b/api/maven-api-xml/src/main/java/org/apache/maven/api/xml/XmlNode.java
@@ -493,17 +493,12 @@ public XmlNode child(String name) {
 
             @Override
             public boolean equals(Object o) {
-                if (this == o) {
-                    return true;
-                }
-                if (o == null || getClass() != o.getClass()) {
-                    return false;
-                }
-                Impl that = (Impl) o;
-                return Objects.equals(this.name, that.name)
-                        && Objects.equals(this.value, that.value)
-                        && Objects.equals(this.attributes, that.attributes)
-                        && Objects.equals(this.children, that.children);
+                return this == o
+                        || o instanceof XmlNode that
+                                && Objects.equals(this.name, that.name())
+                                && Objects.equals(this.value, that.value())
+                                && Objects.equals(this.attributes, 
that.attributes())
+                                && Objects.equals(this.children, 
that.children());
             }
 
             @Override
diff --git 
a/impl/maven-xml/src/main/java/org/apache/maven/internal/xml/XmlNodeImpl.java 
b/impl/maven-xml/src/main/java/org/apache/maven/internal/xml/XmlNodeImpl.java
index db0025bc36..8ae8569b14 100644
--- 
a/impl/maven-xml/src/main/java/org/apache/maven/internal/xml/XmlNodeImpl.java
+++ 
b/impl/maven-xml/src/main/java/org/apache/maven/internal/xml/XmlNodeImpl.java
@@ -279,17 +279,12 @@ public static XmlNode merge(XmlNode dominant, XmlNode 
recessive) {
 
     @Override
     public boolean equals(Object o) {
-        if (this == o) {
-            return true;
-        }
-        if (o == null || getClass() != o.getClass()) {
-            return false;
-        }
-        XmlNodeImpl that = (XmlNodeImpl) o;
-        return Objects.equals(this.name, that.name)
-                && Objects.equals(this.value, that.value)
-                && Objects.equals(this.attributes, that.attributes)
-                && Objects.equals(this.children, that.children);
+        return this == o
+                || o instanceof XmlNode that
+                        && Objects.equals(this.name, that.name())
+                        && Objects.equals(this.value, that.value())
+                        && Objects.equals(this.attributes, that.attributes())
+                        && Objects.equals(this.children, that.children());
     }
 
     @Override
diff --git 
a/impl/maven-xml/src/test/java/org/apache/maven/internal/xml/XmlNodeImplTest.java
 
b/impl/maven-xml/src/test/java/org/apache/maven/internal/xml/XmlNodeImplTest.java
index 7aabba39f4..541b99c451 100644
--- 
a/impl/maven-xml/src/test/java/org/apache/maven/internal/xml/XmlNodeImplTest.java
+++ 
b/impl/maven-xml/src/test/java/org/apache/maven/internal/xml/XmlNodeImplTest.java
@@ -478,6 +478,18 @@ void testEquals() {
         assertNotEquals(dom, XmlNode.newInstance(""));
     }
 
+    /**
+     * <p>testEqualsComplex.</p>
+     */
+    @Test
+    void testEqualsComplex() throws XMLStreamException, 
XmlPullParserException, IOException {
+        String testDom = "<configuration><items 
thing='blah'><item>one</item><item>two</item></items></configuration>";
+        XmlNode dom1 = XmlService.read(new StringReader(testDom));
+        XmlNode dom2 = XmlNodeBuilder.build(new StringReader(testDom));
+
+        assertEquals(dom1, dom2);
+    }
+
     /**
      * <p>testEqualsWithDifferentStructures.</p>
      */

Reply via email to