Repository navigation
[bug-fix]fix ClientWorker NullPointer judement order - #9461
Merged
KomachiSion merged 1 commit intoNov 4, 2022
Merged
KomachiSion merged 1 commit into
KomachiSion merged 1 commit into
Conversation
shiyiyue1102
approved these changes
Nov 4, 2022
wushiyuanmaimob
added a commit
to wushiyuanmaimob/nacos
that referenced
this pull request
May 23, 2026
…nCache (re-introduces alibaba#9461)
wushiyuanmaimob
added a commit
to wushiyuanmaimob/nacos
that referenced
this pull request
May 23, 2026
…nCache (re-introduces alibaba#9461)
wushiyuanmaimob
added a commit
to wushiyuanmaimob/nacos
that referenced
this pull request
May 25, 2026
…rver returns unknown key Reproduces the same bug class fixed by alibaba#9461: when the server returns a changeKey in ConfigChangeBatchListenResponse that has been concurrently removed from the local cacheMap (e.g. user has just called removeListener), the unsafe pre-dereference cacheMap.get().get(changeKey).isInitializing() throws NPE. The exception is swallowed by the surrounding catch (Throwable) and only surfaces as "Execute listen config change error" log noise, but the batch processing of the remaining changeKeys is silently aborted. The new test ClientWorkerTest#testCheckListenCacheSkipsRemovedKey asserts that no NPE-induced batch abort happens when the server returns an unknown changeKey. Without the fix the test fails because the swallowed NPE leaves the local cache's isInitializing() flag unchanged. Assisted-by: Claude Code Signed-off-by: wushiyuanmaimob <wushiyuanwork@outlook.com>
wushiyuanmaimob
added a commit
to wushiyuanmaimob/nacos
that referenced
this pull request
May 25, 2026
…nCache (re-introduces alibaba#9461) The original fix in alibaba#9461 (milestone 2.2.0, commit c8c64a1) moved the notify computation into refreshContentAndCheck so that the existing cache != null guard would protect both call sites. When the gRPC long- connection variant ConfigRpcTransportClient was introduced in 3.x, a fresh copy of refreshContentAndCheck(RpcClient, String, boolean) was added — its body has a defensive null-check, but the two callers re-introduced the unsafe pattern cacheMap.get().get(changeKey).isInitializing(), defeating the protection. Refactor refreshContentAndCheck(RpcClient, String, boolean) to refreshContentAndCheck(RpcClient, String) so notify = !cache.isInitializing() is computed inside the method, under the existing cache != null guard. Take a single cacheMap.get() snapshot to avoid duplicate volatile reads and replace containsKey + get double-lookup with a single get + null check. Assisted-by: Claude Code Signed-off-by: wushiyuanmaimob <wushiyuanwork@outlook.com>
KomachiSion
pushed a commit
that referenced
this pull request
May 25, 2026
…nt.checkListenCache (#15226) * test(client): add regression test for NPE in checkListenCache when server returns unknown key Reproduces the same bug class fixed by #9461: when the server returns a changeKey in ConfigChangeBatchListenResponse that has been concurrently removed from the local cacheMap (e.g. user has just called removeListener), the unsafe pre-dereference cacheMap.get().get(changeKey).isInitializing() throws NPE. The exception is swallowed by the surrounding catch (Throwable) and only surfaces as "Execute listen config change error" log noise, but the batch processing of the remaining changeKeys is silently aborted. The new test ClientWorkerTest#testCheckListenCacheSkipsRemovedKey asserts that no NPE-induced batch abort happens when the server returns an unknown changeKey. Without the fix the test fails because the swallowed NPE leaves the local cache's isInitializing() flag unchanged. Assisted-by: Claude Code Signed-off-by: wushiyuanmaimob <wushiyuanwork@outlook.com> * fix(client): regression of NPE in ConfigRpcTransportClient.checkListenCache (re-introduces #9461) The original fix in #9461 (milestone 2.2.0, commit c8c64a1) moved the notify computation into refreshContentAndCheck so that the existing cache != null guard would protect both call sites. When the gRPC long- connection variant ConfigRpcTransportClient was introduced in 3.x, a fresh copy of refreshContentAndCheck(RpcClient, String, boolean) was added — its body has a defensive null-check, but the two callers re-introduced the unsafe pattern cacheMap.get().get(changeKey).isInitializing(), defeating the protection. Refactor refreshContentAndCheck(RpcClient, String, boolean) to refreshContentAndCheck(RpcClient, String) so notify = !cache.isInitializing() is computed inside the method, under the existing cache != null guard. Take a single cacheMap.get() snapshot to avoid duplicate volatile reads and replace containsKey + get double-lookup with a single get + null check. Assisted-by: Claude Code Signed-off-by: wushiyuanmaimob <wushiyuanwork@outlook.com> --------- Signed-off-by: wushiyuanmaimob <wushiyuanwork@outlook.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please do not create a Pull Request without creating an issue first.
What is the purpose of the change
fix ClientWorker nullpointer judgement order around function "refreshContentAndCheck "
the judgement " if (cache != null) " is executed after "cacheMap.get().get(changeKey).isInitializing()"
and the object "cache" could be null
Brief changelog
XX
Verifying this change
XXXX
Follow this checklist to help us incorporate your contribution quickly and easily:
[ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=trueto make sure basic checks pass. Runmvn clean install -DskipITsto make sure unit-test pass. Runmvn clean test-compile failsafe:integration-testto make sure integration-test pass.