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 555b660cd2 fix: prevent NullPointerException in PluginHandleService by
using Objects.equals for data type comparison and add test cases (#6936)
555b660cd2 is described below
commit 555b660cd2005b33a6da4b6e981023b6dc585316
Author: Limbo <[email protected]>
AuthorDate: Sat Aug 22 10:04:29 2026 +0800
fix: prevent NullPointerException in PluginHandleService by using
Objects.equals for data type comparison and add test cases (#6936)
Co-authored-by: aias00 <[email protected]>
---
.../service/impl/PluginHandleServiceImpl.java | 4 ++--
.../admin/service/PluginHandleServiceTest.java | 26 ++++++++++++++++++++++
2 files changed, 28 insertions(+), 2 deletions(-)
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 9517ed61b7..1e766d5def 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 (pluginHandleDO.getDataType() == SELECT_BOX_DATA_TYPE) {
+ if (Objects.equals(pluginHandleDO.getDataType(),
SELECT_BOX_DATA_TYPE)) {
dictOptions =
shenyuDictMapper.findByType(pluginHandleDO.getField())
.stream()
.filter(item -> Objects.equals(item.getEnabled(),
Boolean.TRUE))
@@ -219,7 +219,7 @@ public class PluginHandleServiceImpl implements
PluginHandleService {
private List<PluginHandleVO> buildPluginHandleVO(final
List<PluginHandleDO> pluginHandleDOList) {
List<String> fieldList = pluginHandleDOList.stream()
- .filter(pluginHandleDO -> pluginHandleDO.getDataType() ==
SELECT_BOX_DATA_TYPE)
+ .filter(pluginHandleDO ->
Objects.equals(pluginHandleDO.getDataType(), SELECT_BOX_DATA_TYPE))
.map(PluginHandleDO::getField)
.distinct()
.collect(Collectors.toList());
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/PluginHandleServiceTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/PluginHandleServiceTest.java
index 53e861d600..5c47aad55a 100644
---
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/PluginHandleServiceTest.java
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/PluginHandleServiceTest.java
@@ -46,7 +46,9 @@ import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
@@ -174,6 +176,18 @@ public final class PluginHandleServiceTest {
assertThat(result.getDictOptions().size(), equalTo(1));
}
+ @Test
+ public void testFindByIdWhenDataTypeIsNull() {
+ PluginHandleDO pluginHandleDO = buildPluginHandleDO();
+ pluginHandleDO.setDataType(null);
+
given(this.pluginHandleMapper.selectById("4")).willReturn(pluginHandleDO);
+
+ PluginHandleVO result = assertDoesNotThrow(() ->
this.pluginHandleService.findById("4"));
+
+ assertThat(result, notNullValue());
+ assertNull(result.getDataType());
+ }
+
private List<ShenyuDictDO> buildShenyuDictDOs() {
Timestamp now = Timestamp.valueOf(LocalDateTime.now());
final ShenyuDictDO result = ShenyuDictDO.builder()
@@ -212,6 +226,18 @@ public final class PluginHandleServiceTest {
assertEquals(pluginHandleDOs.size(), result.size());
}
+ @Test
+ public void testListWhenDataTypeIsNull() {
+ PluginHandleDO pluginHandleDO = buildPluginHandleDO();
+ pluginHandleDO.setDataType(null);
+
given(this.pluginHandleMapper.selectByQuery(any())).willReturn(Collections.singletonList(pluginHandleDO));
+
+ List<PluginHandleVO> result = assertDoesNotThrow(() ->
this.pluginHandleService.list("4", 2));
+
+ assertEquals(1, result.size());
+ assertNull(result.get(0).getDataType());
+ }
+
@Test
public void testListAllData() {
final List<PluginHandleDO> pluginHandleDOs = buildPluginHandleDOList();