material-components / material-components-android

Modular and customizable Material Design UI components for Android
Apache License 2.0
16.37k stars 3.07k forks source link

NPE In BottomSheetBehavior ViewDragHelper #1295

Closed eygraber closed 4 years ago

eygraber commented 4 years ago

Description: Crash (see logs below)

Expected behavior: Not to crash

Android API version: 8.1.0

Material Library version: com.google.android.material:material:1.2.0-alpha06

Device: Moto G (5) Plus

More Info: From Android issue tracker:

Looks like this is in https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java#L512 which should be filed on https://github.com/material-components/material-components-android/issues

There's already a null check earlier in that method at https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java#L498 so probably the same defensive check needs to be done everywhere viewDragHelper is used. Going to close this here - please refile in the Github tracker.

V8 is the obfuscated name of ViewDragHelper, and b is mTouchSlop.

Fatal Exception: java.lang.NullPointerException: Attempt to read from field 'int V8.b' on a null object reference
       at androidx.customview.widget.ViewDragHelper.getTouchSlop(ViewDragHelper.java:503)
       at com.google.android.material.bottomsheet.BottomSheetBehavior.onTouchEvent(BottomSheetBehavior.java:512)
       at androidx.coordinatorlayout.widget.CoordinatorLayout.performIntercept(CoordinatorLayout.java:505)
       at androidx.coordinatorlayout.widget.CoordinatorLayout.onTouchEvent(CoordinatorLayout.java:557)
       at android.view.View.dispatchTouchEvent(View.java:11779)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2965)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2643)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2971)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2971)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2971)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2971)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2971)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2971)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
       at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:477)
       at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1835)
       at android.app.Activity.dispatchTouchEvent(Activity.java:3326)
       at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69)
       at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:1)
       at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:439)
       at android.view.View.dispatchPointerEvent(View.java:12018)
       at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4829)
       at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4643)
       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4181)
       at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4234)
       at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4200)
       at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4327)
       at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4208)
       at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4384)
       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4181)
       at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4234)
       at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4200)
       at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4208)
       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4181)
       at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6744)
       at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6683)
       at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6644)
       at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6847)
       at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:193)
       at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
       at android.os.MessageQueue.next(MessageQueue.java:325)
       at android.os.Looper.loop(Looper.java:142)
       at android.app.ActivityThread.main(ActivityThread.java:6626)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
melaniegoetz commented 4 years ago

Hi there! Could you please share a small sample (app) that reproduces this bug?

eygraber commented 4 years ago

Nope. I have a huge app with tens of bottom sheets, and only get crash reports about it in production. I've never seen it happen locally.

A sample of the devices it happens on is:

Galaxy A70 - Android 10 Nexus 6P - Android 8.1 LG Q7+ - Android 9 LG Stylo3 - Android 7 Galaxy S20 Ultra 5G - Android 10 Moto G(5) Plus - Android 8.1

matpag commented 4 years ago

The problem seems that here we check if viewDragHelper is not null, than here we call viewDragHelper.getTouchSlop() without checking if viewDragHelper is not null again.

Probably we should skip this code block if viewDragHelper is null.

@melaniegoetz If you think this is the correct way to fix the problem I can open a PR

eygraber commented 4 years ago

Any idea when this might get merged? I get 5-10 crashes daily from this issue.

eygraber commented 4 years ago

Did this make it into 1.2.0?

matpag commented 4 years ago

Nope, this will be in the next 1.3.0