Skip to content

[bug-fix]fix ClientWorker NullPointer judement order - #9461

Merged
KomachiSion merged 1 commit into
alibaba:developfrom
Maksim-lk:fix-ClientWorker-NullPointer-Judgement
Nov 4, 2022
Merged

KomachiSion merged 1 commit into
alibaba:developfrom
Maksim-lk:fix-ClientWorker-NullPointer-Judgement

Conversation

@Maksim-lk

Copy link
Copy Markdown
Contributor

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:

  • Make sure there is a Github issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in test module.
  • Run mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true to make sure basic checks pass. Run mvn clean install -DskipITs to make sure unit-test pass. Run mvn clean test-compile failsafe:integration-test to make sure integration-test pass.

@KomachiSion KomachiSion added area/Config area/Client Related to Nacos Client SDK labels Nov 4, 2022
@KomachiSion
KomachiSion merged commit c8c64a1 into alibaba:develop Nov 4, 2022
@KomachiSion KomachiSion added this to the 2.2.0 milestone Nov 4, 2022
wushiyuanmaimob added a commit to wushiyuanmaimob/nacos that referenced this pull request May 23, 2026
wushiyuanmaimob added a commit to wushiyuanmaimob/nacos that referenced this pull request May 23, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/Client Related to Nacos Client SDK area/Config

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants