Skip to content

Guard remaining mListener accesses against null (refs #25)#29

Open
jim-daf wants to merge 1 commit into
globalpayments:masterfrom
jim-daf:fix/issue-25-null-listener-guards
Open

Guard remaining mListener accesses against null (refs #25)#29
jim-daf wants to merge 1 commit into
globalpayments:masterfrom
jim-daf:fix/issue-25-null-listener-guards

Conversation

@jim-daf

@jim-daf jim-daf commented May 2, 2026

Copy link
Copy Markdown

This issue's stack trace landed in HPPManagerFragment$3.onReceivedError, which (in the v2.0 code) called mListener.hppManagerFailedWithError(...) directly. Commit a5ec6be (Aug 2021, "added rules to proguard file, and handle null listener, ...") routed all the WebViewClient error callbacks through onError()/onSuccess(), both of which guard mListener with a null check. That eliminates the exact NPE in the report.

However, three direct mListener accesses were missed in that pass and can still NPE in the same crash family (fragment detached, onDestroy re-entered, or async callback fires after the fragment has been torn down):

Location Code
onDestroy() mListener.hppManagerCancelled()
WebView back-key OnKeyListener mListener.hppManagerCancelled()
postHPPData success Callback mListener.getClass().getDeclaredMethods()

This PR adds an explicit mListener != null guard at each of those three sites, mirroring the defensive pattern already used in onSuccess() / onError(). No behavioral change when the listener is attached.

Refs #25.

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().
@jim-daf jim-daf marked this pull request as ready for review May 2, 2026 21:14
Copilot AI review requested due to automatic review settings May 2, 2026 21:14

Copilot AI left a comment

Copy link
Copy Markdown

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 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 WebView key listener.
  • Add a null guard before reflecting on mListener in 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;
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.

2 participants