android-target-tooltip icon indicating copy to clipboard operation
android-target-tooltip copied to clipboard

Crash using tooltip in adapter

Open eduardbosch opened this issue 8 years ago • 0 comments

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

  1. 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
  2. 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
  3. 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.
  4. The FrameLayout continue 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

eduardbosch avatar Oct 19 '17 11:10 eduardbosch