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 d9e15292ce   fix: avoid NPE when API doc registration eventType is 
missing (#7573)
d9e15292ce is described below

commit d9e15292ce112f27bf03d3ed47b25aef72bb7f5b
Author: Southern <[email protected]>
AuthorDate: Wed Oct 14 09:28:07 2026 +0800

      fix: avoid NPE when API doc registration eventType is missing (#7573)
    
    Replace eventType.equals() calls with null-safe enum comparisons in
      RegisterApiDocServiceImpl so missing or unsupported event types are
      ignored without invoking API or tag services.
    
      Extend the existing parameterized test to cover null and all unsupported
      event types, asserting that processing neither throws nor calls either 
service.
---
 .../manager/impl/RegisterApiDocServiceImpl.java       |  4 ++--
 .../manager/RegisterApiDocServiceImplTest.java        | 19 ++++++++++++-------
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/RegisterApiDocServiceImpl.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/RegisterApiDocServiceImpl.java
index 051f2f4dd5..6907690899 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/RegisterApiDocServiceImpl.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/RegisterApiDocServiceImpl.java
@@ -51,7 +51,7 @@ public class RegisterApiDocServiceImpl implements 
RegisterApiDocService {
 
     @Override
     public void registerApiDocument(final ApiDocRegisterDTO apiDocRegisterDTO) 
{
-        if (apiDocRegisterDTO.getEventType().equals(EventType.REGISTER)) {
+        if (EventType.REGISTER == apiDocRegisterDTO.getEventType()) {
             ApiDTO apiDTO = buildApiDTO(apiDocRegisterDTO);
             apiService.deleteByApiPathHttpMethodRpcType(apiDTO.getApiPath(), 
apiDTO.getHttpMethod(), apiDTO.getRpcType());
             List<String> tagsIds = new ArrayList<>();
@@ -75,7 +75,7 @@ public class RegisterApiDocServiceImpl implements 
RegisterApiDocService {
             }
             apiDTO.setTagIds(tagsIds);
             apiService.createOrUpdate(apiDTO);
-        } else if (apiDocRegisterDTO.getEventType().equals(EventType.OFFLINE)) 
{
+        } else if (EventType.OFFLINE == apiDocRegisterDTO.getEventType()) {
             String contextPath = apiDocRegisterDTO.getContextPath();
             apiService.offlineByContextPath(contextPath);
         }
diff --git 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/manager/RegisterApiDocServiceImplTest.java
 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/manager/RegisterApiDocServiceImplTest.java
index 7db5de53eb..5f85e86157 100644
--- 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/manager/RegisterApiDocServiceImplTest.java
+++ 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/manager/RegisterApiDocServiceImplTest.java
@@ -27,6 +27,9 @@ import 
org.apache.shenyu.register.common.dto.ApiDocRegisterDTO;
 import org.apache.shenyu.register.common.enums.EventType;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.junit.jupiter.params.provider.NullSource;
 import org.mockito.ArgumentCaptor;
 import org.mockito.InjectMocks;
 import org.mockito.junit.jupiter.MockitoExtension;
@@ -36,10 +39,12 @@ import org.springframework.test.util.ReflectionTestUtils;
 import java.util.Collections;
 import java.util.List;
 
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
 import static org.mockito.Mockito.when;
 
 /** Tests for {@link RegisterApiDocServiceImpl}. */
@@ -104,14 +109,14 @@ public final class RegisterApiDocServiceImplTest {
         verify(apiService).createOrUpdate(any());
     }
 
-    @Test
-    public void testRegisterIgnoresOtherEventTypes() {
-        ReflectionTestUtils.setField(service, "apiService", apiService);
-        ReflectionTestUtils.setField(service, "tagService", tagService);
+    @ParameterizedTest
+    @NullSource
+    @EnumSource(value = EventType.class, names = {"REGISTER", "OFFLINE"}, mode 
= EnumSource.Mode.EXCLUDE)
+    public void testRegisterIgnoresMissingOrUnsupportedEventTypes(final 
EventType eventType) {
         ApiDocRegisterDTO dto = new ApiDocRegisterDTO();
-        dto.setEventType(EventType.UPDATED);
-        service.registerApiDocument(dto);
-        org.mockito.Mockito.verifyNoInteractions(apiService, tagService);
+        dto.setEventType(eventType);
+        assertDoesNotThrow(() -> service.registerApiDocument(dto));
+        verifyNoInteractions(apiService, tagService);
     }
 
     @Test

Reply via email to