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

fixed NPE in pulsar client #10470

Merged
merged 4 commits into from
May 3, 2021

Conversation

abhilashmandaliya
Copy link
Contributor

@abhilashmandaliya abhilashmandaliya commented May 3, 2021

Motivation

PulsarClientImpl throws NPE if we attempt to close the resource when conf.getServiceUrl is blank.

Modifications

Added a null check before accessing the resource.

This change is a trivial rework / code cleanup without any test coverage.

@abhilashmandaliya
Copy link
Contributor Author

@merlimat @codelipenghui PTAL

}
try {
closeCnxPool(cnxPool);
} catch (Throwable t) {
Copy link
Contributor

Choose a reason for hiding this comment

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

what about catching PulsarClientException and not a raw Throwable ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay. should I change it everywhere in this function? @eolivelli

Copy link
Contributor

Choose a reason for hiding this comment

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

I won't change other points, the effect may be unpredictable.

in your new function closeCnxPool you are already catching Throwable so here it is useless.

catching Throwable and Exception is always a code smell and we should do it only in very specific cases when we know what we are doing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

alright. thanks. I have changed it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eolivelli I changed at 2 other places in this function, which call some local private functions and they do throw PulsarClientException.
I believe it is safe as I had done those changes a month ago and we haven't released after that,

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

Copy link
Member

@lhotari lhotari left a comment

Choose a reason for hiding this comment

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

LGTM

@abhilashmandaliya
Copy link
Contributor Author

/pulsarbot run-failure-checks

1 similar comment
@abhilashmandaliya
Copy link
Contributor Author

/pulsarbot run-failure-checks

@merlimat merlimat added this to the 2.8.0 milestone May 3, 2021
@merlimat merlimat added the type/bug The PR fixed a bug or issue reported a bug label May 3, 2021
@merlimat merlimat merged commit 27f5b62 into apache:master May 3, 2021
@abhilashmandaliya abhilashmandaliya deleted the java-client-npe-fix branch May 4, 2021 04:24
eolivelli pushed a commit to eolivelli/pulsar that referenced this pull request May 11, 2021
* fixed NPE from pulsar client if we attempt to close the resource when conf.getServiceUrl is blank

* removed redundant check

* catching PulsarClientException instead of Throwable

* catching PulsarClientException instead of Throwable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug The PR fixed a bug or issue reported a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants