Skip to content

fix a potential NPE in CallbackServiceCodec.java#5768

Merged
chickenlj merged 1 commit intoapache:masterfrom
seedeed:master
Mar 13, 2020
Merged

fix a potential NPE in CallbackServiceCodec.java#5768
chickenlj merged 1 commit intoapache:masterfrom
seedeed:master

Conversation

@seedeed
Copy link
Copy Markdown
Contributor

@seedeed seedeed commented Feb 20, 2020

What is the purpose of the change

Fix a potential NPE in CallbackServiceCodec.java

Brief changelog

Add a null check for url and parameters.

Follow this checklist to help us incorporate your contribution quickly and easily:

  • 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-io
Copy link
Copy Markdown

Codecov Report

Merging #5768 into master will increase coverage by 0.03%.
The diff coverage is 60%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #5768      +/-   ##
============================================
+ Coverage     61.42%   61.45%   +0.03%     
+ Complexity      498      497       -1     
============================================
  Files           979      979              
  Lines         38828    38875      +47     
  Branches       5569     5604      +35     
============================================
+ Hits          23851    23892      +41     
- Misses        12360    12367       +7     
+ Partials       2617     2616       -1
Impacted Files Coverage Δ Complexity Δ
...dubbo/rpc/protocol/dubbo/CallbackServiceCodec.java 81.75% <60%> (-0.96%) 0 <0> (ø)
...port/identifier/BaseServiceMetadataIdentifier.java 67.85% <0%> (-4.88%) 0% <0%> (ø)
...dubbo/common/status/support/LoadStatusChecker.java 46.15% <0%> (-3.85%) 0% <0%> (ø)
...pache/dubbo/remoting/transport/AbstractServer.java 53.75% <0%> (-3.75%) 0% <0%> (ø)
...he/dubbo/remoting/transport/netty/NettyServer.java 70.17% <0%> (-3.51%) 8% <0%> (-1%)
...pache/dubbo/registry/support/AbstractRegistry.java 78.35% <0%> (-2.99%) 0% <0%> (ø)
...ting/exchange/support/header/HeartbeatHandler.java 83.72% <0%> (-2%) 0% <0%> (ø)
...ache/dubbo/remoting/transport/mina/MinaClient.java 56.92% <0%> (-1.54%) 8% <0%> (-1%)
.../main/java/org/apache/dubbo/qos/textui/TTable.java 83.79% <0%> (-0.87%) 0% <0%> (ø)
...figcenter/file/FileSystemDynamicConfiguration.java 65.5% <0%> (-0.85%) 0% <0%> (ø)
... and 32 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 12d99d6...64376f0. Read the comment docs.

@chickenlj
Copy link
Copy Markdown
Contributor

Can you give one case that the URL can be null?

@seedeed
Copy link
Copy Markdown
Contributor Author

seedeed commented Mar 5, 2020

I'm not sure whether the url is always not null. But I found that there already exists a null check for the url before setting the variable named group in this method. So I thought one more null check for this url is still needed before calling its getParameters method anyway.

    /**
     * export or unexport callback service on client side
     *
     * @param channel
     * @param url
     * @param clazz
     * @param inst
     * @param export
     * @throws IOException
     */
    @SuppressWarnings({"unchecked", "rawtypes"})
    private static String exportOrUnexportCallbackService(Channel channel, URL url, Class clazz, Object inst, Boolean export) throws IOException {
        int instid = System.identityHashCode(inst);
        Map<String, String> params = new HashMap<>(3);
        // no need to new client again
        params.put(IS_SERVER_KEY, Boolean.FALSE.toString());
        // mark it's a callback, for troubleshooting
        params.put(IS_CALLBACK_SERVICE, Boolean.TRUE.toString());
        String group = (url == null ? null : url.getParameter(GROUP_KEY));
        if (group != null && group.length() > 0) {
            params.put(GROUP_KEY, group);
        }
        // add method, for verifying against method, automatic fallback (see dubbo protocol)
        params.put(METHODS_KEY, StringUtils.join(Wrapper.getWrapper(clazz).getDeclaredMethodNames(), ","));

        Map<String, String> tmpMap = new HashMap<>(url.getParameters());

@chickenlj chickenlj merged commit f8b8b3d into apache:master Mar 13, 2020
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.

3 participants