material-components-android icon indicating copy to clipboard operation
material-components-android copied to clipboard

[SideSheetBehavior] NullPointerException in setState > runAfterLayout

Open eugenegff opened this issue 3 months ago • 0 comments

Description: NullPointerException in SideSheetBehavior setState > runAfterLayout, happens when viewRef was nullified as part of SideSheetBehavior.onDetachedFromLayoutParams() and only then accessed by setState() > runAfterLayout lambda. Similar nearby checks outside of lambda are not enough, as all of them are executed immediately, and access in lambda is done later, after layout.

Fix for the issue is in https://github.com/material-components/material-components-android/pull/4974

Screenshot of the problematic SideSheetBehavior.setState() code is attached below, line where viewRef is accessed without viewRef != null check is highlighted, viewRef was not null initially, during setState() call, but then SideSheetBehavior was detached from view, and only then view was layout and lambda with highlighted line of the already detached SideSheetBehavior was run

Image

Android API version: 30-36

Material Library version: 1.13, but actually any

eugenegff avatar Nov 18 '25 15:11 eugenegff