This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 78a59596c923 camel-wordpress: stop WordpressAPIConfiguration.equals
recursing forever (#29675)
78a59596c923 is described below
commit 78a59596c9236aed6992d926d95fbdf25ef0fa5f
Author: dhairya05 <[email protected]>
AuthorDate: Thu Nov 12 17:32:44 2026 +0530
camel-wordpress: stop WordpressAPIConfiguration.equals recursing forever
(#29675)
equals delegated back to itself:
return Objects.equals(this, obj);
Objects.equals(a, b) is `a == b || (a != null && a.equals(b))`, so for two
distinct instances this calls WordpressAPIConfiguration.equals again with
the
same arguments and recurses until the stack overflows. Only an identity
comparison ever terminated, and then only by the `obj == this` shortcut
inside
Objects.equals.
equals now compares the three fields hashCode already hashes - apiUrl,
apiVersion and authentication - so the two are consistent.
---
.../wordpress/api/WordpressAPIConfiguration.java | 10 ++--
.../api/WordpressAPIConfigurationTest.java | 64 ++++++++++++++++++++++
2 files changed, 70 insertions(+), 4 deletions(-)
diff --git
a/components/camel-wordpress/src/main/java/org/apache/camel/component/wordpress/api/WordpressAPIConfiguration.java
b/components/camel-wordpress/src/main/java/org/apache/camel/component/wordpress/api/WordpressAPIConfiguration.java
index 698d520deb8c..745009288e23 100644
---
a/components/camel-wordpress/src/main/java/org/apache/camel/component/wordpress/api/WordpressAPIConfiguration.java
+++
b/components/camel-wordpress/src/main/java/org/apache/camel/component/wordpress/api/WordpressAPIConfiguration.java
@@ -78,13 +78,15 @@ public final class WordpressAPIConfiguration implements
Serializable {
@Override
public boolean equals(Object obj) {
- if (obj == null) {
- return false;
+ if (this == obj) {
+ return true;
}
- if (!WordpressAPIConfiguration.class.isAssignableFrom(obj.getClass()))
{
+ if (!(obj instanceof WordpressAPIConfiguration other)) {
return false;
}
- return Objects.equals(this, obj);
+ return Objects.equals(this.apiUrl, other.apiUrl)
+ && Objects.equals(this.apiVersion, other.apiVersion)
+ && Objects.equals(this.authentication, other.authentication);
}
}
diff --git
a/components/camel-wordpress/src/test/java/org/apache/camel/component/wordpress/api/WordpressAPIConfigurationTest.java
b/components/camel-wordpress/src/test/java/org/apache/camel/component/wordpress/api/WordpressAPIConfigurationTest.java
new file mode 100644
index 000000000000..318a43363034
--- /dev/null
+++
b/components/camel-wordpress/src/test/java/org/apache/camel/component/wordpress/api/WordpressAPIConfigurationTest.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.wordpress.api;
+
+import
org.apache.camel.component.wordpress.api.auth.WordpressBasicAuthentication;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+public class WordpressAPIConfigurationTest {
+
+ @Test
+ public void testEqualsForTwoDistinctButEqualInstances() {
+ final WordpressAPIConfiguration one = new
WordpressAPIConfiguration("http://localhost/wp-json", "2");
+ final WordpressAPIConfiguration other = new
WordpressAPIConfiguration("http://localhost/wp-json", "2");
+
+ assertEquals(one, other);
+ assertEquals(one.hashCode(), other.hashCode());
+ }
+
+ @Test
+ public void testEqualsIsReflexive() {
+ final WordpressAPIConfiguration configuration = new
WordpressAPIConfiguration("http://localhost/wp-json", "2");
+
+ assertEquals(configuration, configuration);
+ }
+
+ @Test
+ public void testNotEqualsWhenAFieldDiffers() {
+ final WordpressAPIConfiguration configuration = new
WordpressAPIConfiguration("http://localhost/wp-json", "2");
+
+ assertNotEquals(configuration, new
WordpressAPIConfiguration("http://example.com/wp-json", "2"));
+ assertNotEquals(configuration, new
WordpressAPIConfiguration("http://localhost/wp-json", "3"));
+
+ final WordpressAPIConfiguration withAuthentication
+ = new WordpressAPIConfiguration("http://localhost/wp-json",
"2");
+ withAuthentication.setAuthentication(new
WordpressBasicAuthentication("user", "password"));
+ assertNotEquals(configuration, withAuthentication);
+ }
+
+ @Test
+ public void testNotEqualsForOtherTypesAndNull() {
+ final WordpressAPIConfiguration configuration = new
WordpressAPIConfiguration("http://localhost/wp-json", "2");
+
+ assertNotEquals(configuration, "http://localhost/wp-json");
+ assertNotEquals(null, configuration);
+ }
+
+}