Guard remaining mListener accesses against null (refs #25)#29
Open
jim-daf wants to merge 1 commit into
Open
Conversation
Commit a5ec6be (Aug 2021) wrapped most mListener.hppManagerFailedWithError calls in onError(), which null-checks mListener. Three direct accesses were missed and can still NPE in the same crash family reported in globalpayments#25 when the fragment is detached or onDestroy fires twice: * onDestroy(): mListener.hppManagerCancelled() * WebView back-key OnKeyListener: mListener.hppManagerCancelled() * postHPPData success callback: mListener.getClass().getDeclaredMethods() Each is now guarded by an explicit null check, mirroring the defensive pattern already used in onSuccess()/onError().
There was a problem hiding this comment.
Pull request overview
This PR hardens HPPManagerFragment against NullPointerExceptions when asynchronous callbacks arrive after the fragment has been detached and mListener has already been cleared. It fits into the library’s payment-result delivery flow by making the fragment’s terminal callback paths more defensive.
Changes:
- Add a null guard around the cancellation callback in
onDestroy(). - Add a null guard around the back-navigation cancellation callback in the
WebViewkey listener. - Add a null guard before reflecting on
mListenerin the response-consumer success callback.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+144
to
147
| if (!isResultReceived && mListener != null) { | ||
| mListener.hppManagerCancelled(); | ||
| } | ||
| mListener = null; |
Comment on lines
+168
to
171
| if (mListener != null) { | ||
| mListener.hppManagerCancelled(); | ||
| } | ||
| isResultReceived = true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This issue's stack trace landed in
HPPManagerFragment$3.onReceivedError, which (in the v2.0 code) calledmListener.hppManagerFailedWithError(...)directly. Commit a5ec6be (Aug 2021, "added rules to proguard file, and handle null listener, ...") routed all the WebViewClient error callbacks throughonError()/onSuccess(), both of which guardmListenerwith a null check. That eliminates the exact NPE in the report.However, three direct
mListeneraccesses were missed in that pass and can still NPE in the same crash family (fragment detached,onDestroyre-entered, or async callback fires after the fragment has been torn down):onDestroy()mListener.hppManagerCancelled()OnKeyListenermListener.hppManagerCancelled()postHPPDatasuccessCallbackmListener.getClass().getDeclaredMethods()This PR adds an explicit
mListener != nullguard at each of those three sites, mirroring the defensive pattern already used inonSuccess()/onError(). No behavioral change when the listener is attached.Refs #25.