Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix localAddress may be null,avoid throwing NullPointerException(#7621) #7622

Merged
merged 2 commits into from
Apr 27, 2021

Conversation

skyguard1
Copy link
Contributor

What is the purpose of the change

Fix localAddress may be null,and NullPointerException will be thrown in NetUtils
In this issue(#7621 ), this pr is to fix this issue, to avoid throwing NullPointerException in NetUtils, thanks

Brief changelog

Verifying this change

  • Make sure there is a GitHub_issue field 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 [Dubbo-XXX] Fix UnknownException when host config not exist #XXX. 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 sample in dubbo samples project.
  • Run mvn clean install -DskipTests=false & mvn clean test-compile failsafe:integration-test to make sure unit-test and integration-test pass.
  • If this contribution is large, please follow the Software Donation Guide.

@codecov-commenter
Copy link

codecov-commenter commented Apr 25, 2021

Codecov Report

Merging #7622 (1fbb870) into master (f8e25ec) will increase coverage by 0.03%.
The diff coverage is 66.66%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #7622      +/-   ##
============================================
+ Coverage     59.11%   59.14%   +0.03%     
- Complexity      528      529       +1     
============================================
  Files          1076     1076              
  Lines         43443    43445       +2     
  Branches       6346     6347       +1     
============================================
+ Hits          25681    25697      +16     
+ Misses        14917    14916       -1     
+ Partials       2845     2832      -13     
Impacted Files Coverage Δ Complexity Δ
...n/java/org/apache/dubbo/common/utils/NetUtils.java 66.55% <66.66%> (-0.12%) 0.00 <0.00> (ø)
...ntext/event/AwaitingNonWebApplicationListener.java 48.48% <0.00%> (-24.25%) 0.00% <0.00%> (ø%)
...o/remoting/transport/ChannelHandlerDispatcher.java 60.00% <0.00%> (-10.00%) 0.00% <0.00%> (ø%)
...mmon/serialize/kryo/utils/AbstractKryoFactory.java 75.43% <0.00%> (-3.51%) 0.00% <0.00%> (ø%)
...e/dubbo/registry/integration/RegistryProtocol.java 57.94% <0.00%> (-2.81%) 0.00% <0.00%> (ø%)
...ting/exchange/support/header/HeartbeatHandler.java 90.69% <0.00%> (-2.33%) 0.00% <0.00%> (ø%)
...pache/dubbo/remoting/telnet/codec/TelnetCodec.java 50.61% <0.00%> (-0.62%) 0.00% <0.00%> (ø%)
...n/java/org/apache/dubbo/common/utils/UrlUtils.java 74.14% <0.00%> (-0.35%) 0.00% <0.00%> (ø%)
...he/dubbo/registry/multicast/MulticastRegistry.java 68.37% <0.00%> (ø) 0.00% <0.00%> (ø%)
...apache/dubbo/common/extension/ExtensionLoader.java 78.17% <0.00%> (+0.22%) 0.00% <0.00%> (ø%)
... and 18 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f8e25ec...1fbb870. Read the comment docs.

Copy link
Contributor

@xiaoheng1 xiaoheng1 left a comment

Choose a reason for hiding this comment

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

I checked the code. If LOCAL_ADDRESS is empty and throws an exception, the previous logic is changed: in the getLocalHost method, if LOCAL_ADDRESS is empty, it will return a LOCALHOST_VALUE.

@skyguard1
Copy link
Contributor Author

skyguard1 commented Apr 25, 2021

But the return value of getLocalAddress method is localAddress, not LOCAL_ADDRESS, and getIpByHost(getLocalAddress().getHostName()) will be called in getIpByConfig(), and NullPointerException will be thrown here

@xiaoheng1
Copy link
Contributor

But the return value of getLocalAddress method is localAddress, not LOCAL_ADDRESS, and getIpByHost(getLocalAddress().getHostName()) will be called in getIpByConfig(), and NullPointerException will be thrown here

  1. The localAddress is assigned to LOCAL_ADDRESS, so it is the same.
  2. My opinion is to make a non-empty judgment on getLocalAddress() in getIpByConfig.

Copy link
Member

@AlbumenJ AlbumenJ left a comment

Choose a reason for hiding this comment

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

LGTM.

@AlbumenJ AlbumenJ merged commit 72531cb into apache:master Apr 27, 2021
goodjava pushed a commit to WZD-MI/incubator-dubbo that referenced this pull request May 6, 2021
…che#7622)

* Fix localAddress may be null,avoid throwing NullPointerException(apache#7621)

* Update by review

Co-authored-by: xingrufei <xingrufei@sogou-inc.com>
AlbumenJ added a commit to AlbumenJ/dubbo that referenced this pull request May 28, 2021
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.

None yet

4 participants