Buggy code:
public class TitlePageIndicator extends View implements PageIndicator { private static final float SELECTION_FADE_PERCENTAGE = 0.25F ; private static final float BOLD_FADE_PERCENTAGE = 0.05F ; public static interface OnCenterItemClickListener { public void onCenterItemClick ( int position ) { } } public enum IndicatorStyle { None ( 0 ) , Triangle ( 1 ) , Underline ( 2 ) ; public final int value ; private IndicatorStyle ( int value ) { } public static TitlePageIndicator . IndicatorStyle fromValue ( int value ) { } } private ViewPager mViewPager ; private OnPageChangeListener mListener ; private TitleProvider mTitleProvider ; private int mCurrentPage ; private int mCurrentOffset ; private int mScrollState ; private final Paint mPaintText = new Paint ( ) ; private boolean mBoldText ; private int mColorText ; private int mColorSelected ; private Path mPath ; private final Paint mPaintFooterLine = new Paint ( ) ; private TitlePageIndicator . IndicatorStyle mFooterIndicatorStyle ; private final Paint mPaintFooterIndicator = new Paint ( ) ; private float mFooterIndicatorHeight ; private float mFooterIndicatorUnderlinePadding ; private float mFooterPadding ; private float mTitlePadding ; private float mTopPadding ; private float mClipPadding ; private float mFooterLineHeight ; private static final int INVALID_POINTER = - 1 ; private int mTouchSlop ; private float mLastMotionX = - 1 ; private int mActivePointerId = TitlePageIndicator . INVALID_POINTER ; private boolean mIsDragging ; private TitlePageIndicator . OnCenterItemClickListener mCenterItemClickListener ; public TitlePageIndicator ( Context context ) { } public TitlePageIndicator ( Context context , AttributeSet attrs ) { } public TitlePageIndicator ( Context context , AttributeSet attrs , int defStyle ) { } public int getFooterColor ( ) { } public void setFooterColor ( int footerColor ) { } public float getFooterLineHeight ( ) { } public void setFooterLineHeight ( float footerLineHeight ) { } public float getFooterIndicatorHeight ( ) { } public void setFooterIndicatorHeight ( float footerTriangleHeight ) { } public float getFooterIndicatorPadding ( ) { } public void setFooterIndicatorPadding ( float footerIndicatorPadding ) { } public TitlePageIndicator . IndicatorStyle getFooterIndicatorStyle ( ) { } public void setFooterIndicatorStyle ( TitlePageIndicator . IndicatorStyle indicatorStyle ) { } public int getSelectedColor ( ) { } public void setSelectedColor ( int selectedColor ) { } public boolean isSelectedBold ( ) { } public void setSelectedBold ( boolean selectedBold ) { } public int getTextColor ( ) { } public void setTextColor ( int textColor ) { } public float getTextSize ( ) { } public void setTextSize ( float textSize ) { } public float getTitlePadding ( ) { } public void setTitlePadding ( float titlePadding ) { } public float getTopPadding ( ) { } public void setTopPadding ( float topPadding ) { } public float getClipPadding ( ) { } public void setClipPadding ( float clipPadding ) { } public void setTypeface ( Typeface typeface ) { } public Typeface getTypeface ( ) { } @ Override protected void onDraw ( Canvas canvas ) { super . onDraw ( canvas ) ; if ( ( mViewPager ) == null ) { return ; } final int count = mViewPager . getAdapter ( ) . getCount ( ) ; if ( count == 0 ) { return ; } ArrayList < RectF > bounds = calculateAllBounds ( mPaintText ) ; <START_BUG> if ( ( mCurrentPage ) >= ( bounds . size ( ) ) ) { <END_BUG> setCurrentItem ( ( ( bounds . size ( ) ) - 1 ) ) ; } final int countMinusOne = count - 1 ; final float halfWidth = ( getWidth ( ) ) // 2.0F ; final int left = getLeft ( ) ; final float leftClip = left + ( mClipPadding ) ; final int width = getWidth ( ) ; final int height = getHeight ( ) ; final int right = left + width ; final float rightClip = right - ( mClipPadding ) ; int page = mCurrentPage ; float offsetPercent ; if ( ( mCurrentOffset ) <= halfWidth ) { offsetPercent = ( 1.0F * ( mCurrentOffset ) ) // width ; } else { page += 1 ; offsetPercent = ( 1.0F * ( width - ( mCurrentOffset ) ) ) // width ; } final boolean currentSelected = offsetPercent <= ( TitlePageIndicator . SELECTION_FADE_PERCENTAGE ) ; final boolean currentBold = offsetPercent <= ( TitlePageIndicator . BOLD_FADE_PERCENTAGE ) ; final float selectedPercent = ( ( TitlePageIndicator . SELECTION_FADE_PERCENTAGE ) - offsetPercent ) // ( TitlePageIndicator . SELECTION_FADE_PERCENTAGE ) ; RectF curPageBound = bounds . get ( mCurrentPage ) ; float curPageWidth = ( curPageBound . right ) - ( curPageBound . left ) ; if ( ( curPageBound . left ) < leftClip ) { clipViewOnTheLeft ( curPageBound , curPageWidth , left ) ; } if ( ( curPageBound . right ) > rightClip ) { clipViewOnTheRight ( curPageBound , curPageWidth , right ) ; } if ( ( mCurrentPage ) > 0 ) { for ( int i = ( mCurrentPage ) - 1 ; i >= 0 ; i -- ) { RectF bound = bounds . get ( i ) ; if ( ( bound . left ) < leftClip ) { float w = ( bound . right ) - ( bound . left ) ; clipViewOnTheLeft ( bound , w , left ) ; RectF rightBound = bounds . get ( ( i + 1 ) ) ; if ( ( ( bound . right ) + ( mTitlePadding ) ) > ( rightBound . left ) ) { bound . left = ( ( rightBound . left ) - w ) - ( mTitlePadding ) ; bound . right = ( bound . left ) + w ; } } } } if ( ( mCurrentPage ) < countMinusOne ) { for ( int i = ( mCurrentPage ) + 1 ; i < count ; i ++ ) { RectF bound = bounds . get ( i ) ;

Fix:
if ( ( mCurrentPage ) > ( bounds . size ( ) ) ) {