android/platform_frameworks_base — pull request #45 by Meghaditya (2014-09-25 12:27:46+00:00)
Title: Fixing subtle bug in FragmentTransaction.replace

Here goes the api documentation for FragmentTransaction.replace -
"Replace an existing fragment that was added to a container. This is essentially the same as calling remove(Fragment) for all currently added fragments that were added with the same containerViewId and then add(int, Fragment, String) with the same arguments given here."

Bug in the code -
mManager.mAdded = {fragmentA, fragmentB}
I call fragmentTransaction.replace(containerId, fragmentA, null)
The code comes to run() with OP_Replace, enters the case OP_REPLACE, enters the for loop.
[old = fragmentA, f=fragmentA] (old.mContainerId == f.mContainerId), enters the if block, (old==f) sets op.fragment = f = null
enters the loop second time
[old = fragmentB, f=null] f == null, enters the if block, (old != f) removes fragmentB

Is that what I expected??

Fix:
Making the code simpler by doing what it says in documentation. I quote - "For all currently added fragments (the for loop) that were added with the same containerViewId (the 2nd if check inside the loop) calling remove(Fragment) (the block inside if) and then and then add(int, Fragment, String) with the same arguments given here. (the block just before break).

Thanks,
Megha