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 a4595683c3 fix(admin): null-guard PluginHandleServiceImpl#findById for 
unknown ids (#7327)
a4595683c3 is described below

commit a4595683c311e688cad500f66f7075afde5bd8de
Author: Sean-Walker0 <[email protected]>
AuthorDate: Wed Sep 30 09:59:59 2026 +0800

    fix(admin): null-guard PluginHandleServiceImpl#findById for unknown ids 
(#7327)
    
    findById passes mapper.selectById(id) straight into
    buildPluginHandleVO, which dereferences pluginHandleDO.getDataType();
    for a deleted or nonexistent handle id the mapper returns null and the
    admin API answers 500 (NullPointerException) instead of an empty
    result. Sibling services guard the same pattern: DetailServiceImpl and
    FieldServiceImpl both null-check the mapper result around their VO
    builders, and PluginHandleVO.buildPluginHandleVO itself is already
    null-safe. Add the missing guard so an unknown id resolves to null like
    the VO builder already handles.
    
    The new test fails on current master with the exact NPE and passes with
    this change.
    
    Co-authored-by: Sean-Walker0 
<[email protected]>
---
 .../service/impl/PluginHandleServiceImpl.java      |  2 +-
 .../service/impl/PluginHandleServiceImplTest.java  | 52 ++++++++++++++++++++++
 2 files changed, 53 insertions(+), 1 deletion(-)

diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/PluginHandleServiceImpl.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/PluginHandleServiceImpl.java
index 1e766d5def..5d8eb9b736 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/PluginHandleServiceImpl.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/PluginHandleServiceImpl.java
@@ -206,7 +206,7 @@ public class PluginHandleServiceImpl implements 
PluginHandleService {
 
     private PluginHandleVO buildPluginHandleVO(final PluginHandleDO 
pluginHandleDO) {
         List<ShenyuDictVO> dictOptions = null;
-        if (Objects.equals(pluginHandleDO.getDataType(), 
SELECT_BOX_DATA_TYPE)) {
+        if (Objects.nonNull(pluginHandleDO) && 
Objects.equals(pluginHandleDO.getDataType(), SELECT_BOX_DATA_TYPE)) {
             dictOptions = 
shenyuDictMapper.findByType(pluginHandleDO.getField())
                     .stream()
                     .filter(item -> Objects.equals(item.getEnabled(), 
Boolean.TRUE))
diff --git 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/impl/PluginHandleServiceImplTest.java
 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/impl/PluginHandleServiceImplTest.java
new file mode 100644
index 0000000000..4bf29cebac
--- /dev/null
+++ 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/impl/PluginHandleServiceImplTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.admin.service.impl;
+
+import org.apache.shenyu.admin.mapper.PluginHandleMapper;
+import org.apache.shenyu.admin.mapper.ShenyuDictMapper;
+import org.apache.shenyu.admin.service.publish.PluginHandleEventPublisher;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.Mockito.when;
+
+/**
+ * Test case for {@link PluginHandleServiceImpl}.
+ */
+@ExtendWith(MockitoExtension.class)
+public final class PluginHandleServiceImplTest {
+
+    @Mock
+    private PluginHandleMapper pluginHandleMapper;
+
+    @Mock
+    private ShenyuDictMapper shenyuDictMapper;
+
+    @Mock
+    private PluginHandleEventPublisher eventPublisher;
+
+    @Test
+    public void findByIdShouldNotThrowForUnknownId() {
+        PluginHandleServiceImpl service = new 
PluginHandleServiceImpl(pluginHandleMapper, shenyuDictMapper, eventPublisher);
+        when(pluginHandleMapper.selectById("missing")).thenReturn(null);
+        assertNull(service.findById("missing"));
+    }
+}

Reply via email to