This is an automated email from the ASF dual-hosted git repository.
Aias00 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 6e63edffdf fix(common): rename the ZombieUpstream selectorId setter
misnamed setSelectorName (#7322)
6e63edffdf is described below
commit 6e63edffdf5cc7d568903ea10e87942ed624c895
Author: Sean-Walker0 <[email protected]>
AuthorDate: Wed Sep 30 11:05:23 2026 +0800
fix(common): rename the ZombieUpstream selectorId setter misnamed
setSelectorName (#7322)
* fix(common): rename the ZombieUpstream selectorId setter misnamed
setSelectorName
The setter's own javadoc says "set selectorId", it assigns the
selectorId field, and the class declares no selectorName field at all,
yet the method was named setSelectorName. That broke the JavaBeans
contract for the class: the selectorId property had no write method and
a phantom write-only selectorName property appeared, so any
java.beans-based binding (Spring BeanUtils.copyProperties, EL, JMX)
cannot populate selectorId and callers writing setSelectorName silently
target the wrong property name. Every sibling accessor in the class maps
to its own field, confirming the copy-paste naming slip. No in-repo
caller uses the misnamed setter (construction goes through the builder
and transform()).
The new Introspector-based test fails on current master ('selectorId
must have a setter') and passes with this change; the existing test that
codified the misnamed setter is updated accordingly.
* test(common): polish the ZombieUpstream bean-contract test per review
Use imports instead of fully-qualified java.beans names, assert the
read method as well so the property pair is verified from both sides,
and note why Introspector.flushCaches is not needed for this lookup.
---------
Co-authored-by: Sean-Walker0
<[email protected]>
---
.../dto/convert/selector/ZombieUpstream.java | 2 +-
.../dto/convert/selector/ZombieUpstreamTest.java | 27 ++++++++++++++++++++--
2 files changed, 26 insertions(+), 3 deletions(-)
diff --git
a/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/selector/ZombieUpstream.java
b/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/selector/ZombieUpstream.java
index 5521f21c00..57d0b74ace 100644
---
a/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/selector/ZombieUpstream.java
+++
b/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/selector/ZombieUpstream.java
@@ -118,7 +118,7 @@ public class ZombieUpstream {
*
* @param selectorId selectorId
*/
- public void setSelectorName(final String selectorId) {
+ public void setSelectorId(final String selectorId) {
this.selectorId = selectorId;
}
diff --git
a/shenyu-common/src/test/java/org/apache/shenyu/common/dto/convert/selector/ZombieUpstreamTest.java
b/shenyu-common/src/test/java/org/apache/shenyu/common/dto/convert/selector/ZombieUpstreamTest.java
index 2a0b213fc7..ea8b249587 100644
---
a/shenyu-common/src/test/java/org/apache/shenyu/common/dto/convert/selector/ZombieUpstreamTest.java
+++
b/shenyu-common/src/test/java/org/apache/shenyu/common/dto/convert/selector/ZombieUpstreamTest.java
@@ -17,6 +17,11 @@
package org.apache.shenyu.common.dto.convert.selector;
+import java.beans.BeanInfo;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.util.Arrays;
+
import com.google.common.collect.ImmutableSet;
import org.junit.jupiter.api.Test;
@@ -25,6 +30,8 @@ import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Test case for ZombieUpstream.
@@ -36,7 +43,7 @@ public class ZombieUpstreamTest {
ZombieUpstream upstream =
ZombieUpstream.builder().selectorId("id").zombieCheckTimes(10)
.commonUpstream(new CommonUpstream()).build();
- upstream.setSelectorName("newId");
+ upstream.setSelectorId("newId");
upstream.setZombieCheckTimes(5);
upstream.setCommonUpstream(null);
@@ -65,8 +72,24 @@ public class ZombieUpstreamTest {
@Test
public void testTransform() {
ZombieUpstream upstream = ZombieUpstream.transform(new
CommonUpstream(), 10, "id");
-
+
assertThat(upstream, is(notNullValue()));
}
+ @Test
+ public void testSelectorIdFollowsJavaBeanContract() throws Exception {
+ // the JDK caches Introspector results JVM-wide per class; this is
fine under JUnit's
+ // default sequential execution and no flushCaches is needed for this
single lookup
+ BeanInfo info = Introspector.getBeanInfo(ZombieUpstream.class,
Object.class);
+ PropertyDescriptor[] descriptors = info.getPropertyDescriptors();
+ PropertyDescriptor selectorId = Arrays.stream(descriptors)
+ .filter(d -> "selectorId".equals(d.getName()))
+ .findFirst()
+ .orElseThrow(() -> new AssertionError("selectorId property not
found"));
+ assertNotNull(selectorId.getReadMethod(), "selectorId must have a
getter per the JavaBeans contract");
+ assertNotNull(selectorId.getWriteMethod(), "selectorId must have a
setter per the JavaBeans contract");
+ assertTrue(Arrays.stream(descriptors).noneMatch(d ->
"selectorName".equals(d.getName())),
+ "there is no selectorName field, so no phantom selectorName
property may exist");
+ }
+
}