You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "AryamannSingh7 (via GitHub)" <gi...@apache.org> on 2026/06/25 04:57:50 UTC
[PR] Fix startup NPE when a weakly dependent registry is unavailable (check=false) [dubbo]
AryamannSingh7 opened a new pull request, #16356:
URL: https://github.com/apache/dubbo/pull/16356
## What is the purpose of the change?
Fixes #16178.
When a service subscribes to multiple registries and one of them is **weakly dependent** (`check="false"`) and **unavailable at startup**, the application fails to start with:
```
java.lang.NullPointerException: Cannot invoke "org.apache.dubbo.registry.Registry.getUrl()" because "this.registry" is null
at org.apache.dubbo.registry.ListenerRegistryWrapper.getUrl(ListenerRegistryWrapper.java:44)
at org.apache.dubbo.registry.integration.RegistryDirectory.subscribe(RegistryDirectory.java:...)
```
This is a regression: Dubbo `3.2.0`–`3.2.4` start successfully, `3.2.5`+ fail (also reproduced on `3.3.x`).
### Root cause
Under `check=false`, when a registry cannot be created (the registry is down), `AbstractRegistryFactory#getRegistry` swallows the exception and returns `null`. `RegistryFactoryWrapper` still wraps this `null` into a `ListenerRegistryWrapper`, so a null delegate is an **expected state** — `ListenerRegistryWrapper` already guards `register` / `unregister` / `subscribe` with `if (registry != null)`.
However:
- `getUrl` / `isAvailable` / `destroy` / `unsubscribe` / `isServiceDiscovery` / `lookup` were **not** guarded.
- `RegistryDirectory#subscribe` computes a metrics cluster name via `registry.getUrl().getParameter(...)` unconditionally. That line was introduced in #12582 (released in `3.2.5`), which is exactly why the NPE appears from `3.2.5` onward.
### What changed
1. **`ListenerRegistryWrapper`** — complete the existing null-safety: `getUrl` returns `null`, `isAvailable` / `isServiceDiscovery` return `false`, `destroy` / `unsubscribe` become no-ops, and `lookup` returns an empty list when the delegate registry is `null`.
2. **`RegistryDirectory#subscribe`** — guard the metrics cluster-name computation against a `null` registry URL (no cluster name is reported when the registry is unavailable). `RegistryEvent#toSubscribeEvent` already tolerates a `null` name.
### Verification
Added `ListenerRegistryWrapperTest#testNullRegistryIsTolerated`, which reproduces the exact NPE **without** the fix and passes **with** it. `:dubbo-registry-api` tests and `spotless:check` pass locally (JDK 21).
## Checklist
- [x] Make sure there is a [GitHub issue](https://github.com/apache/dubbo/issues/16178) field for the change.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit-test to verify your logic correction.
- [x] Make sure GitHub actions can pass.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Fix startup NPE when a weakly dependent registry is unavailable (check=false) [dubbo]
Posted by "AryamannSingh7 (via GitHub)" <gi...@apache.org>.
AryamannSingh7 commented on PR #16356:
URL: https://github.com/apache/dubbo/pull/16356#issuecomment-5020946024
Hi @EarthChen, @CrazyHZM — could either of you take a look at this one for the second approve?
@zrlw reviewed and approved it on 10 July, and the PR is still on `status/wait for another approve`, so I think it just needs one more sign-off to go in.
It's a small, self-contained fix: under a multi-registry setup with a weakly dependent registry (`check=false`) that's down at startup, the app fails to boot with an NPE instead of degrading gracefully. It's a regression — `3.2.0`–`3.2.4` start fine, `3.2.5`+ don't, tracing to the metrics line added in #12582. The change completes null-safety that was already half-present in `ListenerRegistryWrapper` and guards that one metrics lookup; no behaviour change when the registry is non-null. +46/-10 across 3 files, with `ListenerRegistryWrapperTest#testNullRegistryIsTolerated` reproducing the NPE without the fix. CI is green on the current `3.3` rebase.
Full detail is in the description and [my earlier comment](https://github.com/apache/dubbo/pull/16356#issuecomment-4928458524). Happy to reshape it if you'd prefer the guard elsewhere (e.g. not wrapping a null registry in `RegistryFactoryWrapper` at all). Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Fix startup NPE when a weakly dependent registry is unavailable (check=false) [dubbo]
Posted by "AryamannSingh7 (via GitHub)" <gi...@apache.org>.
AryamannSingh7 commented on PR #16356:
URL: https://github.com/apache/dubbo/pull/16356#issuecomment-4995516625
Thanks for the review, @zrlw. The PR is still marked `status/wait for another approve`, so it looks like it needs a second committer sign-off before it can be merged. Is there anything I can do to help line that up — or are you able to merge it as-is? Happy to ping a specific reviewer if that's the usual flow here. Appreciate the help.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Fix startup NPE when a weakly dependent registry is unavailable (check=false) [dubbo]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #16356:
URL: https://github.com/apache/dubbo/pull/16356#issuecomment-4796141683
## [Codecov](https://app.codecov.io/gh/apache/dubbo/pull/16356?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `61.53846%` with `5 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 60.27%. Comparing base ([`2626e28`](https://app.codecov.io/gh/apache/dubbo/commit/2626e28c16193a099b9cf89e133cd9d55b7d9add?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`15d657b`](https://app.codecov.io/gh/apache/dubbo/commit/15d657be78cb53fdd6c4c527300500283157b7e1?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
| [Files with missing lines](https://app.codecov.io/gh/apache/dubbo/pull/16356?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [...apache/dubbo/registry/ListenerRegistryWrapper.java](https://app.codecov.io/gh/apache/dubbo/pull/16356?src=pr&el=tree&filepath=dubbo-registry%2Fdubbo-registry-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fdubbo%2Fregistry%2FListenerRegistryWrapper.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZHViYm8tcmVnaXN0cnkvZHViYm8tcmVnaXN0cnktYXBpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9kdWJiby9yZWdpc3RyeS9MaXN0ZW5lclJlZ2lzdHJ5V3JhcHBlci5qYXZh) | 62.50% | [1 Missing and 2 partials :warning: ](https://app.codecov.io/gh/apache/dubbo/pull/16356?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [.../dubbo/registry/integration/RegistryDirectory.java](https://app.codecov.io/gh/apache/dubbo/pull/16356?src=pr&el=tree&filepath=dubbo-registry%2Fdubbo-registry-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fdubbo%2Fregistry%2Fintegration%2FRegistryDirectory.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZHViYm8tcmVnaXN0cnkvZHViYm8tcmVnaXN0cnktYXBpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9kdWJiby9yZWdpc3RyeS9pbnRlZ3JhdGlvbi9SZWdpc3RyeURpcmVjdG9yeS5qYXZh) | 60.00% | [1 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/dubbo/pull/16356?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## 3.3 #16356 +/- ##
============================================
- Coverage 60.81% 60.27% -0.54%
- Complexity 30 10252 +10222
============================================
Files 1953 1953
Lines 89213 89198 -15
Branches 13460 13376 -84
============================================
- Hits 54254 53764 -490
- Misses 29374 29766 +392
- Partials 5585 5668 +83
```
| [Flag](https://app.codecov.io/gh/apache/dubbo/pull/16356/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [integration-tests-java21](https://app.codecov.io/gh/apache/dubbo/pull/16356/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [integration-tests-java8](https://app.codecov.io/gh/apache/dubbo/pull/16356/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [samples-tests-java21](https://app.codecov.io/gh/apache/dubbo/pull/16356/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `32.16% <30.76%> (+<0.01%)` | :arrow_up: |
| [samples-tests-java8](https://app.codecov.io/gh/apache/dubbo/pull/16356/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `29.74% <30.76%> (-0.08%)` | :arrow_down: |
| [unit-tests-java11](https://app.codecov.io/gh/apache/dubbo/pull/16356/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [unit-tests-java17](https://app.codecov.io/gh/apache/dubbo/pull/16356/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `58.56% <61.53%> (+<0.01%)` | :arrow_up: |
| [unit-tests-java21](https://app.codecov.io/gh/apache/dubbo/pull/16356/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [unit-tests-java25](https://app.codecov.io/gh/apache/dubbo/pull/16356/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [unit-tests-java8](https://app.codecov.io/gh/apache/dubbo/pull/16356/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/dubbo/pull/16356?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Fix startup NPE when a weakly dependent registry is unavailable (check=false) [dubbo]
Posted by "AryamannSingh7 (via GitHub)" <gi...@apache.org>.
AryamannSingh7 commented on PR #16356:
URL: https://github.com/apache/dubbo/pull/16356#issuecomment-4928458524
Hi @zrlw — following up here since you were tagged on this one.
Quick summary of why this matters: under a multi-registry setup where one registry is weakly dependent (`check=false`) and unavailable at startup, the application fails to boot with an NPE rather than degrading gracefully — which is the entire point of `check=false`. It's a regression: `3.2.0`–`3.2.4` start fine, `3.2.5`+ do not, and it reproduces on `3.3.x`.
The cause is that `AbstractRegistryFactory#getRegistry` returns `null` under `check=false` when the registry can't be created, and `RegistryFactoryWrapper` wraps that `null` into a `ListenerRegistryWrapper`. A null delegate is therefore an expected state — `register` / `unregister` / `subscribe` already guard for it — but `getUrl` / `isAvailable` / `destroy` / `unsubscribe` / `isServiceDiscovery` / `lookup` were never guarded. Separately, `RegistryDirectory#subscribe` calls `registry.getUrl().getParameter(...)` unconditionally for the metrics cluster name; that line came in with #12582, released in `3.2.5`, which is exactly where the regression starts.
The change just completes the null-safety that was already half-present, and guards the metrics lookup. There's no behaviour change when the registry is non-null. `ListenerRegistryWrapperTest#testNullRegistryIsTolerated` reproduces the NPE without the fix and passes with it; `:dubbo-registry-api` tests and `spotless:check` are green locally on JDK 21.
The branch is now rebased onto current `3.3`, so CI should be running clean. Happy to adjust the approach if you'd prefer the guard live somewhere else (e.g. in `RegistryFactoryWrapper`, by not wrapping a null registry at all). Would appreciate a look when you have time. Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org