This is an automated email from the ASF dual-hosted git repository. jianbin pushed a commit to branch 2.x in repository https://gitbox.apache.org/repos/asf/incubator-seata.git
The following commit(s) were added to refs/heads/2.x by this push: new fa80a257c3 bugfix: fix NPE when server-side filter is disabled and filter chain is null. (#7563) fa80a257c3 is described below commit fa80a257c3e93ce20fe2299c22e9871c4002e0b4 Author: xiaoyu <93440108+yvce...@users.noreply.github.com> AuthorDate: Wed Jul 30 09:13:22 2025 +0800 bugfix: fix NPE when server-side filter is disabled and filter chain is null. (#7563) --- changes/en-us/2.x.md | 1 + changes/zh-cn/2.x.md | 1 + .../netty/http/filter/HttpRequestFilterManager.java | 3 +-- .../http/filter/HttpRequestFilterManagerTest.java | 18 ++++++++++++++++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md index fb54cb76f8..cd3a82d3ef 100644 --- a/changes/en-us/2.x.md +++ b/changes/en-us/2.x.md @@ -28,6 +28,7 @@ Add changes here for all PR submitted to the 2.x branch. - [[#7538](https://github.com/apache/incubator-seata/pull/7538)] unify DmdbTimestamp comparison via UTC Instant to prevent rollback failure - [[#7546](https://github.com/seata/seata/pull/7546)] fix client spring version compatible - [[#7505](https://github.com/apache/incubator-seata/pull/7505)] prevent Netty I/O thread blocking by async channel release via reconnectExecutor +- [[#7563](https://github.com/apache/incubator-seata/pull/7563)] Fix NPE when server-side filter is disabled and filter chain is null. ### optimize: diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md index bc85327c39..e84b0a1148 100644 --- a/changes/zh-cn/2.x.md +++ b/changes/zh-cn/2.x.md @@ -28,6 +28,7 @@ - [[#7538](https://github.com/apache/incubator-seata/pull/7538)] 统一DmdbTimestamp比较方式,通过UTC比较,以防止回滚失败 - [[#7546](https://github.com/seata/seata/pull/7546)] 修复客户端spring版本兼容 - [[#7505](https://github.com/apache/incubator-seata/pull/7505)] 通过使用 reconnectExecutor 异步释放 channel,防止阻塞 Netty I/O 线程 +- [[#7563](https://github.com/apache/incubator-seata/pull/7563)] 修复在未开启服务端过滤器的状态下导致的过滤器链空指针异常 diff --git a/core/src/main/java/org/apache/seata/core/rpc/netty/http/filter/HttpRequestFilterManager.java b/core/src/main/java/org/apache/seata/core/rpc/netty/http/filter/HttpRequestFilterManager.java index 68b2f7adc1..e4975864d2 100644 --- a/core/src/main/java/org/apache/seata/core/rpc/netty/http/filter/HttpRequestFilterManager.java +++ b/core/src/main/java/org/apache/seata/core/rpc/netty/http/filter/HttpRequestFilterManager.java @@ -44,10 +44,9 @@ public class HttpRequestFilterManager { HTTP_REQUEST_FILTERS.add(filter); } } - HTTP_REQUEST_FILTERS.sort(Comparator.comparingInt(HttpRequestFilter::getOrder)); - HTTP_REQUEST_FILTER_CHAIN = new HttpRequestFilterChain(HTTP_REQUEST_FILTERS); } + HTTP_REQUEST_FILTER_CHAIN = new HttpRequestFilterChain(HTTP_REQUEST_FILTERS); initialized = true; } diff --git a/core/src/test/java/org/apache/seata/core/rpc/netty/http/filter/HttpRequestFilterManagerTest.java b/core/src/test/java/org/apache/seata/core/rpc/netty/http/filter/HttpRequestFilterManagerTest.java index d0a5340c33..d30f53caa0 100644 --- a/core/src/test/java/org/apache/seata/core/rpc/netty/http/filter/HttpRequestFilterManagerTest.java +++ b/core/src/test/java/org/apache/seata/core/rpc/netty/http/filter/HttpRequestFilterManagerTest.java @@ -118,6 +118,24 @@ class HttpRequestFilterManagerTest { } } + @Test + void testInitializeFilters_filterEnabledFalse() { + MockFilter filter = mock(MockFilter.class); + when(filter.shouldApply()).thenReturn(true); + + try (MockedStatic<ConfigurationFactory> configMock = mockStatic(ConfigurationFactory.class)) { + Configuration mockConfig = mock(Configuration.class); + when(mockConfig.getBoolean(ConfigurationKeys.SERVER_HTTP_FILTER_ENABLE, true)) + .thenReturn(false); + configMock.when(ConfigurationFactory::getInstance).thenReturn(mockConfig); + HttpRequestFilterManager.initializeFilters(); + + HttpRequestFilterChain chain = HttpRequestFilterManager.getFilterChain(); + assertNotNull(chain); + assertTrue(chain.getFilters().isEmpty(), "Filters list should be empty when filter config is false"); + } + } + @Test void testGetFilterChain_beforeInitialization_shouldThrow() { IllegalStateException exception = --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org For additional commands, e-mail: notifications-h...@seata.apache.org