Skip to content

Fix misleading NPE when request parameter is not Serializable#16299

Open
chensishang wants to merge 4 commits into
apache:3.3from
chensishang:fix-16293-misleading-npe
Open

Fix misleading NPE when request parameter is not Serializable#16299
chensishang wants to merge 4 commits into
apache:3.3from
chensishang:fix-16293-misleading-npe

Conversation

@chensishang

Copy link
Copy Markdown

When a Dubbo service is called with non-serializable parameters, the invocation deserialization fails silently and path becomes null. This null path is then passed to GroupServiceKeyCache which uses a ConcurrentHashMap that does not accept null keys, resulting in a confusing NullPointerException.

Added a null check for path in DubboProtocol.getInvoker() to throw a clear RemotingException with a meaningful message pointing users to the actual cause (non-serializable parameters).

Fixes #16293

What is the purpose of the change?

Checklist

  • Make sure there is a GitHub_issue field for the change.
  • 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. If the new feature or significant change is committed, please remember to add sample in dubbo samples project.
  • Make sure gitHub actions can pass. Why the workflow is failing and how to fix it?

When a Dubbo service is called with non-serializable parameters, the
invocation deserialization fails silently and `path` becomes null. This
null path is then passed to GroupServiceKeyCache which uses a
ConcurrentHashMap that does not accept null keys, resulting in a
confusing NullPointerException.

Added a null check for `path` in DubboProtocol.getInvoker() to throw
a clear RemotingException with a meaningful message pointing users to
the actual cause (non-serializable parameters).

Fixes apache#16293

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@codecov-commenter

codecov-commenter commented May 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.78%. Comparing base (b65573e) to head (817f80b).
⚠️ Report is 15 commits behind head on 3.3.

Additional details and impacted files
@@             Coverage Diff              @@
##                3.3   #16299      +/-   ##
============================================
- Coverage     60.80%   60.78%   -0.03%     
- Complexity    11766    11768       +2     
============================================
  Files          1953     1953              
  Lines         89188    89211      +23     
  Branches      13454    13459       +5     
============================================
- Hits          54235    54229       -6     
- Misses        29391    29409      +18     
- Partials       5562     5573      +11     
Flag Coverage Δ
integration-tests-java21 32.11% <0.00%> (-0.02%) ⬇️
integration-tests-java8 32.25% <0.00%> (+0.01%) ⬆️
samples-tests-java21 32.16% <0.00%> (-0.02%) ⬇️
samples-tests-java8 29.71% <0.00%> (-0.15%) ⬇️
unit-tests-java11 59.03% <100.00%> (-0.03%) ⬇️
unit-tests-java17 58.51% <100.00%> (-0.03%) ⬇️
unit-tests-java21 58.51% <100.00%> (+0.02%) ⬆️
unit-tests-java25 58.47% <100.00%> (-0.01%) ⬇️
unit-tests-java8 59.03% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@chensishang

Copy link
Copy Markdown
Author

Hi reviewers, I noticed the Codecov check failed with "0% coverage". After checking, this seems to be due to an incomplete report upload ("HEAD比BASE少7次上传") rather than a problem with the code change itself.

I have already added a unit test (testGetInvokerThrowsOnNullPath) which covers the new null-check logic, and it passes locally. The Codecov result appears to be a false negative caused by the CI infrastructure.

Could you please take another look? Thanks!

zrlw
zrlw previously approved these changes Jun 1, 2026

@zrlw zrlw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zrlw zrlw added type/enhancement Everything related with code enhancement or performance status/wait for another approve labels Jun 1, 2026
@chensishang

Copy link
Copy Markdown
Author

Thanks for the review!

@chensishang

Copy link
Copy Markdown
Author

Hi @zrlw, thanks for the review!

The PR contains two commits: the actual fix (6a870129) and a merge commit for syncing with the latest 3.3 branch. The only real change is in DubboProtocol.java and DubboProtocolTest.java.

The maintainer can squash on merge if needed. Sorry for the noise!

@chensishang

Copy link
Copy Markdown
Author

@RainYuY

Hi, thanks for your time.

This PR has already received one approval and all checks are passing. It fixes the misleading NPE issue described in #16293 and includes a corresponding unit test.

Could you please help take a look when you have time?
Thank you!

int port = channel.getLocalAddress().getPort();
String path = (String) inv.getObjectAttachmentWithoutConvert(PATH_KEY);
if (path == null) {
throw new RemotingException(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is non-serializable parameter really the only scenario that can make path null here? In the normal Dubbo request format, the service path is encoded/decoded before arguments, and DubboInvoker also sets PATH_KEY before sending the request. So a null path seems more generally like missing/malformed invocation metadata, custom codec/invocation behavior, or decode/protocol incompatibility. Could we make this error message less specific than “Please ensure all parameter types implement Serializable” to avoid another misleading diagnosis?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the careful review — you're right, and I appreciate you pointing this out. A null path indicates missing or corrupted invocation metadata in general, and my original message attributing ▎ it solely to non-serializable parameters could indeed cause another misleading diagnosis

I've updated the message to describe the problem generically and only mention deserialization failure as one of several possible causes (along with protocol incompatibility and custom
codec/invocation implementations). Please let me know if the wording could be further improved — happy to adjust.

@chensishang

Copy link
Copy Markdown
Author

@zrlw

Sorry for the extra round — the review above pointed out that my error message was too specific, so I've updated the wording, which dismissed your earlier approval. Could you take another
▎ look when you have time? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/wait for another approve type/enhancement Everything related with code enhancement or performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misleading NullPointerException when request parameter is not Serializable

4 participants