android-target-tooltip
android-target-tooltip copied to clipboard
Crash using tooltip in adapter
Hi to all! 🎉
As commented on this issue https://github.com/sephiroth74/android-target-tooltip/issues/28, using tooltips in adapters can cause NullPointerException when the adapter requests an update.
The problem is that when the adapter updates, the Tooltip might be removed if the adapter removes the Tooltip anchor from the layout. If this process happens in the middle of a FrameLayout.onLayout, that causes the onLayout to iterate on null objects.
By delaying the Tooltip remove from its parent, this problem is solved because we avoid deleting views in the middle of a layout request.
Crash example
- The layout is requested. Suppose that there are 4 children. https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/widget/FrameLayout.java#265
- The adapter updates its data in the middle of the layout request https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/widget/FrameLayout.java#323
- If during point 2 the Tooltip anchor is removed from the layout, the Tooltip is also removed from the layout. In that case, the children of the layout are not 4 anymore because a Tooltip has been removed. Suppose that now we have 3 children only.
- The
FrameLayoutcontinue iterating in 4 objects, but one of them is null and that causes this line to crash: https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/widget/FrameLayout.java#275