Buggy code:
if ( ( ims == null ) || ( ( ims . mBatchEditNesting ) > 0 ) ) { return ; } final InputMethodManager imm = InputMethodManager . peekInstance ( ) ; if ( null == imm ) { return ; } if ( ! ( imm . isActive ( mTextView ) ) ) { return ; } if ( ! ( imm . isCursorAnchorInfoEnabled ( ) ) ) { return ; } Layout layout = mTextView . getLayout ( ) ; if ( layout == null ) { return ; } final CursorAnchorInfo . Builder builder = mSelectionInfoBuilder ; builder . reset ( ) ; final int selectionStart = mTextView . getSelectionStart ( ) ; builder . setSelectionRange ( selectionStart , mTextView . getSelectionEnd ( ) ) ; mViewToScreenMatrix . set ( mTextView . getMatrix ( ) ) ; mTextView . getLocationOnScreen ( mTmpIntOffset ) ; mViewToScreenMatrix . postTranslate ( mTmpIntOffset [ 0 ] , mTmpIntOffset [ 1 ] ) ; builder . setMatrix ( mViewToScreenMatrix ) ; final float viewportToContentHorizontalOffset = mTextView . viewportToContentHorizontalOffset ( ) ; final float viewportToContentVerticalOffset = mTextView . viewportToContentVerticalOffset ( ) ; final CharSequence text = mTextView . getText ( ) ; if ( text instanceof Spannable ) { final Spannable sp = ( ( Spannable ) ( text ) ) ; int composingTextStart = EditableInputConnection . getComposingSpanStart ( sp ) ; int composingTextEnd = EditableInputConnection . getComposingSpanEnd ( sp ) ; if ( composingTextEnd < composingTextStart ) { final int temp = composingTextEnd ; composingTextEnd = composingTextStart ; composingTextStart = temp ; } final boolean hasComposingText = ( 0 <= composingTextStart ) && ( composingTextStart < composingTextEnd ) ; if ( hasComposingText ) { final CharSequence composingText = text . subSequence ( composingTextStart , composingTextEnd ) ; builder . setComposingText ( composingTextStart , composingText ) ; final int minLine = layout . getLineForOffset ( composingTextStart ) ; final int maxLine = layout . getLineForOffset ( ( composingTextEnd - 1 ) ) ; for ( int line = minLine ; line <= maxLine ; ++ line ) { final int lineStart = layout . getLineStart ( line ) ; final int lineEnd = layout . getLineEnd ( line ) ; final int offsetStart = Math . max ( lineStart , composingTextStart ) ; final int offsetEnd = Math . min ( lineEnd , composingTextEnd ) ; final boolean ltrLine = ( layout . getParagraphDirection ( line ) ) == ( Layout . DIR_LEFT_TO_RIGHT ) ; final float [ ] widths = new float [ offsetEnd - offsetStart ] ; layout . getPaint ( ) . getTextWidths ( text , offsetStart , offsetEnd , widths ) ; final float top = layout . getLineTop ( line ) ; final float bottom = layout . getLineBottom ( line ) ; for ( int offset = offsetStart ; offset < offsetEnd ; ++ offset ) { final float charWidth = widths [ ( offset - offsetStart ) ] ; final boolean isRtl = layout . isRtlCharAt ( offset ) ; final float primary = layout . getPrimaryHorizontal ( offset ) ; final float secondary = layout . getSecondaryHorizontal ( offset ) ; final float left ; final float right ; if ( ltrLine ) { if ( isRtl ) { left = secondary - charWidth ; right = secondary ; } else { left = primary ; right = primary + charWidth ; } } else { if ( ! isRtl ) { left = secondary ; right = secondary + charWidth ; } else { left = primary - charWidth ; right = primary ; } } final float localLeft = left + viewportToContentHorizontalOffset ; final float localRight = right + viewportToContentHorizontalOffset ; final float localTop = top + viewportToContentVerticalOffset ; final float localBottom = bottom + viewportToContentVerticalOffset ; final boolean isTopLeftVisible = isPositionVisible ( localLeft , localTop ) ; final boolean isBottomRightVisible = isPositionVisible ( localRight , localBottom ) ; int characterBoundsFlags = 0 ; if ( isTopLeftVisible || isBottomRightVisible ) { characterBoundsFlags |= CursorAnchorInfo . FLAG_HAS_VISIBLE_REGION ; } <START_BUG> if ( ( ! isTopLeftVisible ) || ( ! isTopLeftVisible ) ) { <END_BUG> characterBoundsFlags |= CursorAnchorInfo . FLAG_HAS_INVISIBLE_REGION ; } if ( isRtl ) { characterBoundsFlags |= CursorAnchorInfo . FLAG_IS_RTL ; } builder . addCharacterBounds ( offset , localLeft , localTop , localRight , localBottom , characterBoundsFlags ) ; } } } } if ( 0 <= selectionStart ) { final int offset = selectionStart ; final int line = layout . getLineForOffset ( offset ) ; final float insertionMarkerX = ( layout . getPrimaryHorizontal ( offset ) ) + viewportToContentHorizontalOffset ; final float insertionMarkerTop = ( layout . getLineTop ( line ) ) + viewportToContentVerticalOffset ; final float insertionMarkerBaseline = ( layout . getLineBaseline ( line ) ) + viewportToContentVerticalOffset ; final float insertionMarkerBottom = ( layout . getLineBottom ( line ) ) + viewportToContentVerticalOffset ; final boolean isTopVisible = isPositionVisible ( insertionMarkerX , insertionMarkerTop ) ; final boolean isBottomVisible = isPositionVisible ( insertionMarkerX , insertionMarkerBottom ) ; int insertionMarkerFlags = 0 ; if ( isTopVisible || isBottomVisible ) { insertionMarkerFlags |= CursorAnchorInfo . FLAG_HAS_VISIBLE_REGION ; } if ( ( ! isTopVisible ) || ( ! isBottomVisible ) ) { insertionMarkerFlags |= CursorAnchorInfo . FLAG_HAS_INVISIBLE_REGION ; } if ( layout . isRtlCharAt ( offset ) ) { insertionMarkerFlags |= CursorAnchorInfo . FLAG_IS_RTL ; } builder . setInsertionMarkerLocation ( insertionMarkerX , insertionMarkerTop , insertionMarkerBaseline , insertionMarkerBottom , insertionMarkerFlags ) ; } imm . updateCursorAnchorInfo ( mTextView , builder . build ( ) ) ; } } private abstract class HandleView extends View implements Editor . TextViewPositionListener { protected Drawable mDrawable ; protected Drawable mDrawableLtr ; protected Drawable mDrawableRtl ; private final PopupWindow mContainer ; private int mPositionX ; private int mPositionY ; private boolean mIsDragging ; private float mTouchToWindowOffsetX ; private float mTouchToWindowOffsetY ; protected int mHotspotX ;

Fix:
if ( ( ! isTopLeftVisible ) || ( ! isBottomRightVisible ) ) {