recruit-lifestyle / FloatingView

http://engineer.recruit-lifestyle.co.jp/techblog/2015-07-29-floatingview/
Apache License 2.0
1.15k stars 209 forks source link

NPE in addMovement #118

Open gmk57 opened 5 years ago

gmk57 commented 5 years ago

We see in Crashlytics a rare exception on Samsung devices with Android 8 and 9:

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.VelocityTracker.addMovement(android.view.MotionEvent)' on a null object reference
       at jp.co.recruit_lifestyle.android.floatingview.FloatingView.addMovement + 927(FloatingView.java:927)
       at jp.co.recruit_lifestyle.android.floatingview.FloatingView.dispatchTouchEvent + 859(FloatingView.java:859)
       at android.view.View.dispatchPointerEvent + 13719(View.java:13719)
       at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent + 6111(ViewRootImpl.java:6111)
       at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess + 5889(ViewRootImpl.java:5889)
       at android.view.ViewRootImpl$InputStage.deliver + 5338(ViewRootImpl.java:5338)
       at android.view.ViewRootImpl$InputStage.onDeliverToNext + 5391(ViewRootImpl.java:5391)
       at android.view.ViewRootImpl$InputStage.forward + 5357(ViewRootImpl.java:5357)
       at android.view.ViewRootImpl$AsyncInputStage.forward + 5516(ViewRootImpl.java:5516)
       at android.view.ViewRootImpl$InputStage.apply + 5365(ViewRootImpl.java:5365)
       at android.view.ViewRootImpl$AsyncInputStage.apply + 5573(ViewRootImpl.java:5573)
       at android.view.ViewRootImpl$InputStage.deliver + 5338(ViewRootImpl.java:5338)
       at android.view.ViewRootImpl$InputStage.onDeliverToNext + 5391(ViewRootImpl.java:5391)
       at android.view.ViewRootImpl$InputStage.forward + 5357(ViewRootImpl.java:5357)
       at android.view.ViewRootImpl$InputStage.apply + 5365(ViewRootImpl.java:5365)
       at android.view.ViewRootImpl$InputStage.deliver + 5338(ViewRootImpl.java:5338)
       at android.view.ViewRootImpl.deliverInputEvent + 8400(ViewRootImpl.java:8400)
       at android.view.ViewRootImpl.doProcessInputEvents + 8333(ViewRootImpl.java:8333)
       at android.view.ViewRootImpl.enqueueInputEvent + 8286(ViewRootImpl.java:8286)
       at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent + 8515(ViewRootImpl.java:8515)
       at android.view.InputEventReceiver.dispatchInputEvent + 198(InputEventReceiver.java:198)
       at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(InputEventReceiver.java)
       at android.view.InputEventReceiver.consumeBatchedInputEvents + 187(InputEventReceiver.java:187)
       at android.view.ViewRootImpl.doConsumeBatchedInput + 8474(ViewRootImpl.java:8474)
       at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run + 8542(ViewRootImpl.java:8542)
       at android.view.Choreographer$CallbackRecord.run + 949(Choreographer.java:949)
       at android.view.Choreographer.doCallbacks + 761(Choreographer.java:761)
       at android.view.Choreographer.doFrame + 690(Choreographer.java:690)
       at android.view.Choreographer$FrameDisplayEventReceiver.run + 935(Choreographer.java:935)
       at android.os.Handler.handleCallback + 873(Handler.java:873)
       at android.os.Handler.dispatchMessage + 99(Handler.java:99)
       at android.os.Looper.loop + 214(Looper.java:214)
       at android.app.ActivityThread.main + 7058(ActivityThread.java:7058)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run + 493(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main + 965(ZygoteInit.java:965)
Jwillc commented 4 years ago

I've been having this issue for awhile. You think at 927 in FloatingView you could do:

if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); mVelocityTracker.addMovement(event); } else { mVelocityTracker.addMovement(event); }

Or pass a non-null VelocityTracker to addMovement()?