firebase-android-sdk icon indicating copy to clipboard operation
firebase-android-sdk copied to clipboard

NPE in In-App Messaging component, possibly related to activity switching.

Open littleariel opened this issue 8 years ago • 5 comments

[REQUIRED] Step 2: Describe your environment

  • Android Studio version: 3.2
  • Firebase Component: In-App Messaging
  • Component version: 17.0.3

[REQUIRED] Step 3: Describe the problem

NullPointerException happening in Firebase's in-app message code:

java.lang.RuntimeException: 
  at android.app.ActivityThread.performResumeActivity (ActivityThread.java:3788)
  at android.app.ActivityThread.handleResumeActivity (ActivityThread.java:3828)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3036)
  at android.app.ActivityThread.-wrap11 (Unknown Source)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1696)
  at android.os.Handler.dispatchMessage (Handler.java:105)
  at android.os.Looper.loop (Looper.java:164)
  at android.app.ActivityThread.main (ActivityThread.java:6938)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:327)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)
Caused by: java.lang.NullPointerException: 
  at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay.showActiveFiam
  at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay.onActivityResumed
  at android.app.Application.dispatchActivityResumed (Application.java:240)
  at android.app.Activity.onResume (Activity.java:1364)
  at android.support.v4.app.FragmentActivity.onResume (FragmentActivity.java:485)
  at com.MYAPP.MYACTIVITY.onResume (MyActivity.java:58)
  at android.app.Instrumentation.callActivityOnResume (Instrumentation.java:1361)
  at android.app.Activity.performResume (Activity.java:7353)
  at android.app.ActivityThread.performResumeActivity (ActivityThread.java:3763)

Steps to reproduce:

Not 100% sure but we're seeing this happen fairly frequently in our app in production. Our current hunch is that it's related to an in-app message we have scheduled and the crash may occur if the user switches activity while the in-app message is supposed to be displayed.

Not sure it's relevant, but we are using the "top banner" type of message.

Relevant Code:

None - using the stock implementation of the In-App Messaging component.

littleariel avatar Nov 14 '18 01:11 littleariel

Note, this may be related to https://github.com/firebase/firebase-android-sdk/issues/112

littleariel avatar Nov 14 '18 01:11 littleariel

Hi @samtstern @MeghaB - is this issue confirmed on your side? Let me know if there's anything we can do to alleviate that in our own code. This is causing the vast majority of crashes in our app today and we'd love to solve it without abandoning Firebase in-app messages.

littleariel avatar Nov 20 '18 17:11 littleariel

False-alarm! We looked into this a bit further and figured out it was related to something in our code. The crash was an NPE happening at https://github.com/firebase/firebase-android-sdk/blob/master/firebase-inappmessaging-display/src/main/java/com/google/firebase/inappmessaging/display/FirebaseInAppMessagingDisplay.java#L262.

The cause was that our activities override findViewById() and that override would return null for android.R.id.content in some instances. Fixed that piece of code and it fixed the crash.

Closing as a non-issue.

littleariel avatar Nov 28 '18 15:11 littleariel

Thanks for following up! Also just curious since I've never heard of someone overriding findViewById before - what were you using that for?

On Wed, Nov 28, 2018, 7:51 AM Ariel [email protected] wrote:

Closed #130 https://github.com/firebase/firebase-android-sdk/issues/130.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/firebase/firebase-android-sdk/issues/130#event-1992823526, or mute the thread https://github.com/notifications/unsubscribe-auth/AIEw6vkn65KVuySnHFJ0u0-io8Pj8BZnks5uzrEDgaJpZM4Yc3Dp .

samtstern avatar Nov 29 '18 05:11 samtstern

It's in a very old piece of code that was written by another engineer who is no longer with the company, so I can only guess - but it's looking like it was used to provide some kind of backwards compatibility with very old versions of Android and ActionBar support. Chances are that it was a misguided approach to solving that problem, I agree that overriding findViewById is a bit of an odd (and risky!) choice.

littleariel avatar Nov 29 '18 16:11 littleariel