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 4d470820b2 fix(common,logging): repair two self-assigning no-op 
setters (#7281)
4d470820b2 is described below

commit 4d470820b2ce8165a59c56892dd912923388bf02
Author: Sean-Walker0 <[email protected]>
AuthorDate: Sat Sep 26 14:52:43 2026 +0800

    fix(common,logging): repair two self-assigning no-op setters (#7281)
    
    SofaUpstream#setRegister and CommonLoggingRuleHandle#setMaskType are
    no-ops: their parameter names (registry / desensitizeType) differ
    from the field names, so the right-hand side of each assignment
    resolves to the field itself and the caller's value is silently
    dropped:
    
        public void setRegister(final String registry) {
            this.register = register;   // reads the field, not the parameter
        }
    
    Runtime proof on master: setRegister("zookeeper://...") followed by
    getRegister() returns null. Neither setter is exercised in production
    today because both rule-handle DTOs are populated via Gson reflection
    (which writes fields directly), but any caller using the setters gets
    null back and fails downstream - e.g. DigestUtils.md5Hex(getRegister())
    NPEs while building the sofa reference cache key.
    
    Assign the parameter and add setter round-trip tests. Found by a
    repo-wide scan for assignments whose right-hand side is neither a
    parameter nor a literal; ShenyuMcpServerTool#setRequestConfig was
    flagged too but is a false positive (null-clearing guard branch).
    
    Co-authored-by: Sean-Walker0 
<[email protected]>
    Co-authored-by: aias00 <[email protected]>
---
 .../common/dto/convert/selector/SofaUpstream.java  |  2 +-
 .../dto/convert/selector/SofaUpstreamTest.java     | 42 ++++++++++++++++++++++
 .../common/entity/CommonLoggingRuleHandle.java     |  2 +-
 .../common/entity/CommonLoggingRuleHandleTest.java | 41 +++++++++++++++++++++
 4 files changed, 85 insertions(+), 2 deletions(-)

diff --git 
a/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/selector/SofaUpstream.java
 
b/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/selector/SofaUpstream.java
index cf1f343dd2..83c644833d 100644
--- 
a/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/selector/SofaUpstream.java
+++ 
b/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/selector/SofaUpstream.java
@@ -92,7 +92,7 @@ public final class SofaUpstream extends CommonUpstream {
      * @param registry registry
      */
     public void setRegister(final String registry) {
-        this.register = register;
+        this.register = registry;
     }
 
     /**
diff --git 
a/shenyu-common/src/test/java/org/apache/shenyu/common/dto/convert/selector/SofaUpstreamTest.java
 
b/shenyu-common/src/test/java/org/apache/shenyu/common/dto/convert/selector/SofaUpstreamTest.java
new file mode 100644
index 0000000000..fdcd3b5dec
--- /dev/null
+++ 
b/shenyu-common/src/test/java/org/apache/shenyu/common/dto/convert/selector/SofaUpstreamTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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.shenyu.common.dto.convert.selector;
+
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+/**
+ * Test case for SofaUpstream.
+ */
+public class SofaUpstreamTest {
+
+    @Test
+    public void testSetterRoundTrip() {
+        SofaUpstream upstream = 
SofaUpstream.builder().protocol("bolt").upstreamHost("host").upstreamUrl("url")
+                
.status(true).warmup(50).timestamp(1650549243L).weight(100).build();
+
+        // setRegister used to assign the field to itself and silently drop 
the value
+        upstream.setRegister("zookeeper://127.0.0.1:2181");
+        assertThat(upstream.getRegister(), is("zookeeper://127.0.0.1:2181"));
+
+        upstream.setAppName("app");
+        assertThat(upstream.getAppName(), is("app"));
+    }
+}
diff --git 
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common/src/main/java/org/apache/shenyu/plugin/logging/common/entity/CommonLoggingRuleHandle.java
 
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common/src/main/java/org/apache/shenyu/plugin/logging/common/entity/CommonLoggingRuleHandle.java
index c434e6ec40..7570824f40 100644
--- 
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common/src/main/java/org/apache/shenyu/plugin/logging/common/entity/CommonLoggingRuleHandle.java
+++ 
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common/src/main/java/org/apache/shenyu/plugin/logging/common/entity/CommonLoggingRuleHandle.java
@@ -71,7 +71,7 @@ public class CommonLoggingRuleHandle implements RuleHandle {
      * @param desensitizeType desensitize type
      */
     public void setMaskType(final String desensitizeType) {
-        this.maskType = maskType;
+        this.maskType = desensitizeType;
     }
 
     /**
diff --git 
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common/src/test/java/org/apache/shenyu/plugin/logging/common/entity/CommonLoggingRuleHandleTest.java
 
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common/src/test/java/org/apache/shenyu/plugin/logging/common/entity/CommonLoggingRuleHandleTest.java
new file mode 100644
index 0000000000..3680f4664b
--- /dev/null
+++ 
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common/src/test/java/org/apache/shenyu/plugin/logging/common/entity/CommonLoggingRuleHandleTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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.shenyu.plugin.logging.common.entity;
+
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+/**
+ * Test case for CommonLoggingRuleHandle.
+ */
+public class CommonLoggingRuleHandleTest {
+
+    @Test
+    public void testSetMaskTypeRoundTrip() {
+        CommonLoggingRuleHandle handle = new CommonLoggingRuleHandle();
+
+        // setMaskType used to assign the field to itself and silently drop 
the value
+        handle.setMaskType("mask");
+        assertThat(handle.getMaskType(), is("mask"));
+
+        handle.setMaskType(null);
+        assertThat(handle.getMaskType(), is((String) null));
+    }
+}

Reply via email to