material-components / material-components/material-components-android

AppBarLayout - Crashing when setExpand animate is true

Open
#3,854 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Widget: TopAppBar
Dominant language
Java
Stars
17.4k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

Description:
Crashing after repeated call of appBarLayout.setExpanded(true, true)

Expected behavior:
Not crashing

Source code:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".presentation.MainActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <com.google.android.material.appbar.MaterialToolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"
            app:menu="@menu/activity_main_menu"
            app:title="@string/home"
            app:subtitle="@string/assets"
            app:titleCentered="true"
            app:subtitleCentered="true"/>

    </com.google.android.material.appbar.AppBarLayout>

    <include layout="@layout/content_main" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

When a back press is called, the RecyclerView inside content_main scrolls up after calling recyclerView.smoothScrollToPosition(0) then we also call appBarLayout.setExpanded(true, true). It works for a while but after repeatedly triggering both method and clicking some action menu or navigation icon while the list is scrolling the error below kicks in.

JNI DETECTED ERROR IN APPLICATION: can't call void com.google.android.material.appbar.AppBarLayout.setElevation(float) on null object

Minimal sample app repro: N/A

Android API version: 21

Material Library version: 1.10.0

Device: Pixel (emulator)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with AppBarLayout.setExpanded(true, true) and its animation path, then examine the interaction with RecyclerView.smoothScrollToPosition(0) and menu or navigation clicks. Reproduce the repeated sequence on Android API 21 using Material Library 1.10.0; done means the sequence no longer produces the JNI null-object crash.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.