Fixed
Status Update
Comments
il...@google.com <il...@google.com>
cl...@google.com <cl...@google.com>
ap...@google.com <ap...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 92bd7222fcfd7523e8fa80b7f72e967b8bbf4750
Author: Ian Lake <ilake@google.com>
Date: Tue Aug 27 10:07:52 2019
Split LifecycleCallbacks from FragmentManager
Create a separate FragmentLifecycleCallbacksDispatcher
object that is responsible for dispatching
FragmentLifecycleCallbacks events.
Test: existing FragmentLifecycleTest pass
BUG: 139536619
Change-Id: I64cc2b364af65760b0008efb317a742df2c0718d
A fragment/fragment/src/main/java/androidx/fragment/app/FragmentLifecycleCallbacksDispatcher.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
https://android-review.googlesource.com/1110155
https://goto.google.com/android-sha1/92bd7222fcfd7523e8fa80b7f72e967b8bbf4750
Branch: androidx-master-dev
commit 92bd7222fcfd7523e8fa80b7f72e967b8bbf4750
Author: Ian Lake <ilake@google.com>
Date: Tue Aug 27 10:07:52 2019
Split LifecycleCallbacks from FragmentManager
Create a separate FragmentLifecycleCallbacksDispatcher
object that is responsible for dispatching
FragmentLifecycleCallbacks events.
Test: existing FragmentLifecycleTest pass
BUG: 139536619
Change-Id: I64cc2b364af65760b0008efb317a742df2c0718d
A fragment/fragment/src/main/java/androidx/fragment/app/FragmentLifecycleCallbacksDispatcher.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
fa...@hotmail.com <fa...@hotmail.com> #3
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 092d14cd22c174405221b930665869f7c9fc8b65
Author: Ian Lake <ilake@google.com>
Date: Tue Aug 27 14:46:02 2019
Remove FragmentState mInstance
Make FragmentState a simple Parcelable by removing
its mInstance field and its instantiate() method.
This required we change the order of restoring:
instead of reconnecting retained Fragments with their
FragmentState instances, we first iterate through
all FragmentState instances and do one of two things:
1) Reconnect the retained fragment if it exists
2) Create a new fragment from the FragmentState
This allows us to do just one pass through our
FragmentState objects and run the edge case of
detecting retained fragments created after the
state was saved after creating the set of active
fragments.
Test: all existing tests pass
BUG: 139536619
Change-Id: Iba7cc300c127bc05127d122fa5acc1ccc871a76b
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManagerViewModel.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentState.java
https://android-review.googlesource.com/1108716
https://goto.google.com/android-sha1/092d14cd22c174405221b930665869f7c9fc8b65
Branch: androidx-master-dev
commit 092d14cd22c174405221b930665869f7c9fc8b65
Author: Ian Lake <ilake@google.com>
Date: Tue Aug 27 14:46:02 2019
Remove FragmentState mInstance
Make FragmentState a simple Parcelable by removing
its mInstance field and its instantiate() method.
This required we change the order of restoring:
instead of reconnecting retained Fragments with their
FragmentState instances, we first iterate through
all FragmentState instances and do one of two things:
1) Reconnect the retained fragment if it exists
2) Create a new fragment from the FragmentState
This allows us to do just one pass through our
FragmentState objects and run the edge case of
detecting retained fragments created after the
state was saved after creating the set of active
fragments.
Test: all existing tests pass
BUG: 139536619
Change-Id: Iba7cc300c127bc05127d122fa5acc1ccc871a76b
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManagerViewModel.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentState.java
Description
Version used: 2.1.0-alpha01
Devices/Android versions reproduced on: API 28 emulator, Chrome OS
MediatorLiveData.addSource doesn't manually check for null source argument (annotation is there, which is good)
It's possible to accidentally add a null (or not yet initialized) source.
The issue is buried until the MediatorLiveData is observed, making it hard to find the original issue.
Best solution would be a quick check of the variables and fast fail before processing. e.g. assertNotNull(source)
- Sample project attached
relevant code:
private val mediatorLiveData = MediatorLiveData<Int>().apply {
// Here is the mistake, (allowed at compile time).
addSource(dataSource) { value = (it ?: 0) + 1 }
}
private val dataSource = MutableLiveData<Int>()
// This triggers the exception
mediatorLiveData.observe(this, Observer { // process })
Error output without check: (unhelpful unless you know the internals of MediatorLiveData)
2019-01-18 10:58:39.891 6385-6385/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.google.example.mediatorlatecheck, PID: 6385
java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.lifecycle.LiveData.observeForever(androidx.lifecycle.Observer)' on a null object reference
at androidx.lifecycle.MediatorLiveData$Source.plug(MediatorLiveData.java:141)
at androidx.lifecycle.MediatorLiveData.onActive(MediatorLiveData.java:118)
at androidx.lifecycle.LiveData$ObserverWrapper.activeStateChanged(LiveData.java:436)
at androidx.lifecycle.LiveData$LifecycleBoundObserver.onStateChanged(LiveData.java:394)
at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:355)
at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:293)
at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:333)
at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:138)
at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:124)
at androidx.lifecycle.ReportFragment.dispatch(ReportFragment.java:123)
at androidx.lifecycle.ReportFragment.onStart(ReportFragment.java:83)
at android.app.Fragment.performStart(Fragment.java:2548)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1334)
at android.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1576)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1637)
at android.app.FragmentManagerImpl.dispatchMoveToState(FragmentManager.java:3046)
at android.app.FragmentManagerImpl.dispatchStart(FragmentManager.java:3003)
at android.app.FragmentController.dispatchStart(FragmentController.java:193)
at android.app.Activity.performStart(Activity.java:7165)
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:2937)
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:180)
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)