You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "Stellar1999 (via GitHub)" <gi...@apache.org> on 2025/02/18 04:09:20 UTC
[PR] FIX gRPC-related URL object caused a NullPointerException (NPE) [dubbo]
Stellar1999 opened a new pull request, #15157:
URL: https://github.com/apache/dubbo/pull/15157
## What is the purpose of the change?
fix issue #15108
## Checklist
- [x] Make sure there is a [GitHub_issue](https://github.com/apache/dubbo/issues) 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. If the new feature or significant change is committed, please remember to add sample in [dubbo samples](https://github.com/apache/dubbo-samples) project.
- [x] Make sure gitHub actions can pass. [Why the workflow is failing and how to fix it?](../CONTRIBUTING.md)
--
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 gRPC-related URL object caused a NullPointerException (NPE) [dubbo]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #15157:
URL: https://github.com/apache/dubbo/pull/15157#issuecomment-2664581259
## [Codecov](https://app.codecov.io/gh/apache/dubbo/pull/15157?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
Attention: Patch coverage is `0%` with `12 lines` in your changes missing coverage. Please review.
> Project coverage is 29.22%. Comparing base [(`437d38c`)](https://app.codecov.io/gh/apache/dubbo/commit/437d38c8978ae99f7f4b5c7bf05771e302be8ac3?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`abfc6b3`)](https://app.codecov.io/gh/apache/dubbo/commit/abfc6b326f7c1786b4ebe2e9c3ffcb3937bde66e?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/15157?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [...n/java/org/apache/dubbo/common/utils/UrlUtils.java](https://app.codecov.io/gh/apache/dubbo/pull/15157?src=pr&el=tree&filepath=dubbo-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fdubbo%2Fcommon%2Futils%2FUrlUtils.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZHViYm8tY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9kdWJiby9jb21tb24vdXRpbHMvVXJsVXRpbHMuamF2YQ==) | 0.00% | [6 Missing :warning: ](https://app.codecov.io/gh/apache/dubbo/pull/15157?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [...tocol/tri/h12/AbstractServerTransportListener.java](https://app.codecov.io/gh/apache/dubbo/pull/15157?src=pr&el=tree&filepath=dubbo-rpc%2Fdubbo-rpc-triple%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fdubbo%2Frpc%2Fprotocol%2Ftri%2Fh12%2FAbstractServerTransportListener.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZHViYm8tcnBjL2R1YmJvLXJwYy10cmlwbGUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2R1YmJvL3JwYy9wcm90b2NvbC90cmkvaDEyL0Fic3RyYWN0U2VydmVyVHJhbnNwb3J0TGlzdGVuZXIuamF2YQ==) | 0.00% | [6 Missing :warning: ](https://app.codecov.io/gh/apache/dubbo/pull/15157?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
> :exclamation: There is a different number of reports uploaded between BASE (437d38c) and HEAD (abfc6b3). Click for more details.
>
> <details><summary>HEAD has 2 uploads less than BASE</summary>
>
>| Flag | BASE (437d38c) | HEAD (abfc6b3) |
>|------|------|------|
>|integration-tests|1|0|
>|unit-tests|1|0|
></details>
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## 3.3 #15157 +/- ##
=============================================
- Coverage 60.74% 29.22% -31.53%
+ Complexity 10880 8876 -2004
=============================================
Files 1884 1884
Lines 86050 86060 +10
Branches 12893 12894 +1
=============================================
- Hits 52268 25147 -27121
- Misses 28333 56929 +28596
+ Partials 5449 3984 -1465
```
| [Flag](https://app.codecov.io/gh/apache/dubbo/pull/15157/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [integration-tests](https://app.codecov.io/gh/apache/dubbo/pull/15157/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [samples-tests](https://app.codecov.io/gh/apache/dubbo/pull/15157/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `29.22% <0.00%> (+0.01%)` | :arrow_up: |
| [unit-tests](https://app.codecov.io/gh/apache/dubbo/pull/15157/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 Sentry](https://app.codecov.io/gh/apache/dubbo/pull/15157?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).
--
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 gRPC-related URL object caused a NullPointerException (NPE) [dubbo]
Posted by "Stellar1999 (via GitHub)" <gi...@apache.org>.
Stellar1999 commented on code in PR #15157:
URL: https://github.com/apache/dubbo/pull/15157#discussion_r1960914059
##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/h12/AbstractServerTransportListener.java:
##########
@@ -279,6 +280,13 @@ protected final RpcInvocation buildRpcInvocation(RpcInvocationBuildContext conte
// customizer RpcInvocation
HeaderFilter[] headerFilters =
UrlUtils.computeServiceAttribute(invoker.getUrl(), HEADER_FILTERS_CACHE, this::loadHeaderFilters);
+ if (headerFilters == null) {
+ ExtensionLoader<HeaderFilter> headerFilterExtensionLoader =
+ frameworkModel.getExtensionLoader(HeaderFilter.class);
+ headerFilters = headerFilterExtensionLoader
+ .getActivateExtension(invoker.getUrl(), HEADER_FILTERS_CACHE)
+ .toArray(new HeaderFilter[0]);
Review Comment:
Yes, I've already verified it.
--
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 gRPC-related URL object caused a NullPointerException (NPE) [dubbo]
Posted by "AlbumenJ (via GitHub)" <gi...@apache.org>.
AlbumenJ merged PR #15157:
URL: https://github.com/apache/dubbo/pull/15157
--
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 gRPC-related URL object caused a NullPointerException (NPE) [dubbo]
Posted by "Stellar1999 (via GitHub)" <gi...@apache.org>.
Stellar1999 commented on code in PR #15157:
URL: https://github.com/apache/dubbo/pull/15157#discussion_r1960913843
##########
dubbo-common/src/main/java/org/apache/dubbo/common/utils/UrlUtils.java:
##########
@@ -690,7 +693,11 @@ public static boolean isConsumer(URL url) {
@SuppressWarnings("unchecked")
public static <T> T computeServiceAttribute(URL url, String key, Function<URL, T> fn) {
- return (T)
- url.getServiceModel().getServiceMetadata().getAttributeMap().computeIfAbsent(key, k -> fn.apply(url));
+ Optional<Map<String, Object>> attributeMap = Optional.ofNullable(url.getServiceModel())
+ .map(ServiceModel::getServiceMetadata)
+ .map(ServiceMetadata::getAttributeMap);
+ return attributeMap
+ .map(stringObjectMap -> (T) stringObjectMap.computeIfAbsent(key, k -> fn.apply(url)))
+ .orElse(null);
Review Comment:
I'll commit it later
--
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 gRPC-related URL object caused a NullPointerException (NPE) [dubbo]
Posted by "Stellar1999 (via GitHub)" <gi...@apache.org>.
Stellar1999 commented on PR #15157:
URL: https://github.com/apache/dubbo/pull/15157#issuecomment-2665160680
PTAL @AlbumenJ @CrazyHZM
--
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 gRPC-related URL object caused a NullPointerException (NPE) [dubbo]
Posted by "AlbumenJ (via GitHub)" <gi...@apache.org>.
AlbumenJ commented on code in PR #15157:
URL: https://github.com/apache/dubbo/pull/15157#discussion_r1960853132
##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/h12/AbstractServerTransportListener.java:
##########
@@ -279,6 +280,13 @@ protected final RpcInvocation buildRpcInvocation(RpcInvocationBuildContext conte
// customizer RpcInvocation
HeaderFilter[] headerFilters =
UrlUtils.computeServiceAttribute(invoker.getUrl(), HEADER_FILTERS_CACHE, this::loadHeaderFilters);
+ if (headerFilters == null) {
+ ExtensionLoader<HeaderFilter> headerFilterExtensionLoader =
+ frameworkModel.getExtensionLoader(HeaderFilter.class);
+ headerFilters = headerFilterExtensionLoader
+ .getActivateExtension(invoker.getUrl(), HEADER_FILTERS_CACHE)
+ .toArray(new HeaderFilter[0]);
Review Comment:
Will load success here?
##########
dubbo-common/src/main/java/org/apache/dubbo/common/utils/UrlUtils.java:
##########
@@ -690,7 +693,11 @@ public static boolean isConsumer(URL url) {
@SuppressWarnings("unchecked")
public static <T> T computeServiceAttribute(URL url, String key, Function<URL, T> fn) {
- return (T)
- url.getServiceModel().getServiceMetadata().getAttributeMap().computeIfAbsent(key, k -> fn.apply(url));
+ Optional<Map<String, Object>> attributeMap = Optional.ofNullable(url.getServiceModel())
+ .map(ServiceModel::getServiceMetadata)
+ .map(ServiceMetadata::getAttributeMap);
+ return attributeMap
+ .map(stringObjectMap -> (T) stringObjectMap.computeIfAbsent(key, k -> fn.apply(url)))
+ .orElse(null);
Review Comment:
```suggestion
return Optional.ofNullable(url.getServiceModel())
.map(ServiceModel::getServiceMetadata)
.map(ServiceMetadata::getAttributeMap)
.map(stringObjectMap -> (T) stringObjectMap.computeIfAbsent(key, k -> fn.apply(url)))
.orElse(null);
```
--
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 gRPC-related URL object caused a NullPointerException (NPE) [dubbo]
Posted by "Stellar1999 (via GitHub)" <gi...@apache.org>.
Stellar1999 commented on code in PR #15157:
URL: https://github.com/apache/dubbo/pull/15157#discussion_r1962768722
##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/h12/AbstractServerTransportListener.java:
##########
@@ -279,6 +280,13 @@ protected final RpcInvocation buildRpcInvocation(RpcInvocationBuildContext conte
// customizer RpcInvocation
HeaderFilter[] headerFilters =
UrlUtils.computeServiceAttribute(invoker.getUrl(), HEADER_FILTERS_CACHE, this::loadHeaderFilters);
+ if (headerFilters == null) {
+ ExtensionLoader<HeaderFilter> headerFilterExtensionLoader =
+ frameworkModel.getExtensionLoader(HeaderFilter.class);
+ headerFilters = headerFilterExtensionLoader
+ .getActivateExtension(invoker.getUrl(), HEADER_FILTERS_CACHE)
+ .toArray(new HeaderFilter[0]);
Review Comment:
You are right, they are no different. I just didn't notice that this piece of code caused me to write exactly the same code.
--
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 gRPC-related URL object caused a NullPointerException (NPE) [dubbo]
Posted by "AlbumenJ (via GitHub)" <gi...@apache.org>.
AlbumenJ commented on code in PR #15157:
URL: https://github.com/apache/dubbo/pull/15157#discussion_r1962703944
##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/h12/AbstractServerTransportListener.java:
##########
@@ -279,6 +280,13 @@ protected final RpcInvocation buildRpcInvocation(RpcInvocationBuildContext conte
// customizer RpcInvocation
HeaderFilter[] headerFilters =
UrlUtils.computeServiceAttribute(invoker.getUrl(), HEADER_FILTERS_CACHE, this::loadHeaderFilters);
+ if (headerFilters == null) {
+ ExtensionLoader<HeaderFilter> headerFilterExtensionLoader =
+ frameworkModel.getExtensionLoader(HeaderFilter.class);
+ headerFilters = headerFilterExtensionLoader
+ .getActivateExtension(invoker.getUrl(), HEADER_FILTERS_CACHE)
+ .toArray(new HeaderFilter[0]);
Review Comment:
What is the different between

--
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