Skip to content

Conversation

@zrlw
Copy link
Contributor

@zrlw zrlw commented Jul 31, 2025

What is the purpose of the change?

Since the non-static final fields initialized at declaration will not be initialized during it's owner object construction, NullPointerException (NPE)‌ will be thrown if using them during the construction just like #14848
These fields should be changed to non-final and be initialized at it's owner construction to prevent ‌NPE.

By the way, this PR only serves as a ‌mitigation measure‌. The ‌best solution‌ is to ‌refactor the code‌ by:

  • Splitting the Constructor‌: Isolating initialization logic from business logic.
  • Extracting Non-Construction Logic‌: Moving unrelated processing to separate methods.

See details at #15600

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?

@zrlw zrlw changed the title Fix uninitialized final variables issue in dubbo-remoting module Fix uninitialized final variables potential NPE issue in dubbo-remoting module Jul 31, 2025
@zrlw zrlw requested review from EarthChen and oxsean July 31, 2025 12:47
@zrlw zrlw changed the title Fix uninitialized final variables potential NPE issue in dubbo-remoting module Fix uninitialized non-static final variables potential NPE issue in dubbo-remoting module Jul 31, 2025
@zrlw zrlw changed the title Fix uninitialized non-static final variables potential NPE issue in dubbo-remoting module Fix uninitialized non-static final fields potential NPE issue in dubbo-remoting module Jul 31, 2025
@codecov-commenter
Copy link

codecov-commenter commented Jul 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.06%. Comparing base (ed65284) to head (ecfb27c).
⚠️ Report is 1 commits behind head on 3.3.

Additional details and impacted files
@@             Coverage Diff              @@
##                3.3   #15602      +/-   ##
============================================
+ Coverage     61.02%   61.06%   +0.03%     
- Complexity    11500    11693     +193     
============================================
  Files          1909     1909              
  Lines         86782    86783       +1     
  Branches      13094    13094              
============================================
+ Hits          52961    52995      +34     
+ Misses        28409    28372      -37     
- Partials       5412     5416       +4     
Flag Coverage Δ
integration-tests-java21 32.99% <58.33%> (-0.06%) ⬇️
integration-tests-java8 33.05% <58.33%> (-0.06%) ⬇️
samples-tests-java21 32.73% <25.00%> (+1.05%) ⬆️
samples-tests-java8 30.43% <25.00%> (+1.11%) ⬆️
unit-tests-java11 59.06% <100.00%> (-0.04%) ⬇️
unit-tests-java17 58.81% <100.00%> (+0.02%) ⬆️
unit-tests-java21 58.78% <100.00%> (+0.01%) ⬆️
unit-tests-java8 59.06% <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 Sentry.
📢 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.

@EarthChen EarthChen requested a review from Copilot August 1, 2025 02:34

This comment was marked as outdated.

@FoghostCn
Copy link
Contributor

FoghostCn commented Aug 1, 2025

non-static final fields has initialized before construction, did I misunderstand something

image

@EarthChen
Copy link
Member

EarthChen commented Aug 1, 2025

non-static final fields has initialized before construction, did I misunderstand something

image

#14848 It's different when there is multi-threading

@EarthChen EarthChen requested a review from Copilot August 1, 2025 03:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes potential NullPointerException issues in the dubbo-remoting module by addressing the initialization order of non-static final fields. The changes ensure that fields are properly initialized before they can be accessed during object construction, preventing NPEs that could occur when these fields are used in constructor chains or early method calls.

  • Converts final fields to non-final and moves their initialization to appropriate methods
  • Restructures timer task initialization to prevent early execution before configuration is complete
  • Adds proper initialization of collections and configuration values before potential usage

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
NettyServer.java (netty4) Moves serverShutdownTimeoutMills initialization from constructor to doOpen() method
NettyPortUnificationServer.java (netty4) Initializes dubboChannels and serverShutdownTimeoutMills in doOpen0() instead of constructor
NettyServer.java (netty) Adds comment clarification for channels field initialization
NettyPortUnificationServer.java (netty) Moves dubboChannels initialization to doOpen0() method
NettyHttp3Server.java Relocates pipelineConfigurator and serverShutdownTimeoutMills initialization to doOpen()
MultiMessageHandler.java Removes unnecessary @SuppressWarnings annotation
AbstractClient.java Moves connectLock initialization from field declaration to constructor
Timer task classes Restructures initialization to call start() after configuration instead of in parent constructor
AbstractPortUnificationServer.java Moves collection initialization to doOpen() method

this.hashedWheelTimer = hashedWheelTimer;
this.tick = tick;
start();
// do not start here because inheritor should set additional timeout parameters before doing task.
Copy link

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

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

The word 'inheritor' should be 'subclass' or 'subclasses' for better clarity and standard terminology.

Suggested change
// do not start here because inheritor should set additional timeout parameters before doing task.
// do not start here because subclass should set additional timeout parameters before doing task.

Copilot uses AI. Check for mistakes.
Copy link
Member

@EarthChen EarthChen left a comment

Choose a reason for hiding this comment

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

LGTM

@RainYuY
Copy link
Member

RainYuY commented Aug 1, 2025

LGTM

@EarthChen EarthChen merged commit af2625c into apache:3.3 Aug 1, 2025
32 checks passed
@zrlw zrlw deleted the 3.3-fixed-dubboRemoting-UninitializedFinalVariables branch August 1, 2025 08:10
MoritzArena pushed a commit to MoritzArena/dubbo that referenced this pull request Sep 4, 2025
…o-remoting module (apache#15602)

* Fix uninitialized final variables issue in dubbo-remoting

* Remove redundant initializations of AbstractPortUnificationServer fields

* Change modifier of AbstractTimerTask start method

---------

Co-authored-by: earthchen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants