Buggy code:
private static final int INVALID_POINTER = - 1 ; private VelocityTracker mVelocityTracker ; private int mMinimumVelocity ; private int mMaximumVelocity ; private int mFlingDistance ; private int mCloseEnough ; private static final int CLOSE_ENOUGH = 2 ; private boolean mFakeDragging ; private long mFakeDragBeginTime ; private EdgeEffectCompat mLeftEdge ; private EdgeEffectCompat mRightEdge ; private boolean mFirstLayout = true ; private boolean mNeedCalculatePageOffsets = false ; private boolean mCalledSuper ; private int mDecorChildCount ; private ViewPager . OnPageChangeListener mOnPageChangeListener ; private ViewPager . OnPageChangeListener mInternalPageChangeListener ; private ViewPager . OnAdapterChangeListener mAdapterChangeListener ; private ViewPager . PageTransformer mPageTransformer ; private Method mSetChildrenDrawingOrderEnabled ; private static final int DRAW_ORDER_DEFAULT = 0 ; private static final int DRAW_ORDER_FORWARD = 1 ; private static final int DRAW_ORDER_REVERSE = 2 ; private int mDrawingOrder ; private ArrayList < View > mDrawingOrderedChildren ; private static final ViewPager . ViewPositionComparator sPositionComparator = new ViewPager . ViewPositionComparator ( ) ; public static final int SCROLL_STATE_IDLE = 0 ; public static final int SCROLL_STATE_DRAGGING = 1 ; public static final int SCROLL_STATE_SETTLING = 2 ; private final Runnable mEndScrollRunnable = new Runnable ( ) { public void run ( ) { } } ; private int mScrollState = ViewPager . SCROLL_STATE_IDLE ; public interface OnPageChangeListener { public void onPageScrolled ( int position , float positionOffset , int positionOffsetPixels ) { } public void onPageSelected ( int position ) { } public void onPageScrollStateChanged ( int state ) { } } public static class SimpleOnPageChangeListener implements ViewPager . OnPageChangeListener { @ Override public void onPageScrolled ( int position , float positionOffset , int positionOffsetPixels ) { } @ Override public void onPageSelected ( int position ) { } @ Override public void onPageScrollStateChanged ( int state ) { } } public interface PageTransformer { public void transformPage ( View page , float position ) { } } interface OnAdapterChangeListener { public void onAdapterChanged ( PagerAdapter oldAdapter , PagerAdapter newAdapter ) { } } interface Decor { } public ViewPager ( Context context ) { } public ViewPager ( Context context , AttributeSet attrs ) { } void initViewPager ( ) { } @ Override protected void onDetachedFromWindow ( ) { } private void setScrollState ( int newState ) { } public void setAdapter ( PagerAdapter adapter ) { } private void removeNonDecorViews ( ) { } public PagerAdapter getAdapter ( ) { } void setOnAdapterChangeListener ( ViewPager . OnAdapterChangeListener listener ) { } private int getClientWidth ( ) { } public void setCurrentItem ( int item ) { } public void setCurrentItem ( int item , boolean smoothScroll ) { } public int getCurrentItem ( ) { } void setCurrentItemInternal ( int item , boolean smoothScroll , boolean always ) { } void setCurrentItemInternal ( int item , boolean smoothScroll , boolean always , int velocity ) { if ( ( ( mAdapter ) == null ) || ( ( mAdapter . getCount ( ) ) <= 0 ) ) { setScrollingCacheEnabled ( false ) ; return ; } if ( ( ( ! always ) && ( ( mCurItem ) == item ) ) && ( ( mItems . size ( ) ) != 0 ) ) { setScrollingCacheEnabled ( false ) ; return ; } if ( item < 0 ) { item = 0 ; } else if ( item >= ( mAdapter . getCount ( ) ) ) { item = ( mAdapter . getCount ( ) ) - 1 ; } final int pageLimit = mOffscreenPageLimit ; if ( ( item > ( ( mCurItem ) + pageLimit ) ) || ( item < ( ( mCurItem ) - pageLimit ) ) ) { for ( int i = 0 ; i < ( mItems . size ( ) ) ; i ++ ) { mItems . get ( i ) . scrolling = true ; } } <START_BUG> final boolean dispatchSelected = ( mCurItem ) != item ; <END_BUG> if ( mFirstLayout ) { mCurItem = item ; if ( dispatchSelected && ( ( mOnPageChangeListener ) != null ) ) { mOnPageChangeListener . onPageSelected ( item ) ; } if ( dispatchSelected && ( ( mInternalPageChangeListener ) != null ) ) { mInternalPageChangeListener . onPageSelected ( item ) ; } requestLayout ( ) ; } else { populate ( item ) ; scrollToItem ( item , smoothScroll , velocity , dispatchSelected ) ; } } private void scrollToItem ( int item , boolean smoothScroll , int velocity , boolean dispatchSelected ) { } public void setOnPageChangeListener ( ViewPager . OnPageChangeListener listener ) { } public void setPageTransformer ( boolean reverseDrawingOrder , ViewPager . PageTransformer transformer ) { } void setChildrenDrawingOrderEnabledCompat ( boolean enable ) { } @ Override protected int getChildDrawingOrder ( int childCount , int i ) { } ViewPager . OnPageChangeListener setInternalPageChangeListener ( ViewPager . OnPageChangeListener listener ) { } public int getOffscreenPageLimit ( ) { } public void setOffscreenPageLimit ( int limit ) { } public void setPageMargin ( int marginPixels ) { } public int getPageMargin ( ) { } public void setPageMarginDrawable ( Drawable d ) { } public void setPageMarginDrawable ( @ DrawableRes int resId ) { } @ Override protected boolean verifyDrawable ( Drawable who ) { } @ Override protected void drawableStateChanged ( ) { } float distanceInfluenceForSnapDuration ( float f ) { } void smoothScrollTo ( int x , int y ) { } void smoothScrollTo ( int x , int y , int velocity ) { } ViewPager . ItemInfo addNewItem ( int position , int index ) { } void dataSetChanged ( ) { } void populate ( ) { } void populate ( int newCurrentItem ) { } private void sortChildDrawingOrder ( ) { } private void calculatePageOffsets ( ViewPager . ItemInfo curItem , int curIndex , ViewPager . ItemInfo oldCurInfo ) { } public static class SavedState extends BaseSavedState { int position ; Parcelable adapterState ; ClassLoader loader ; public SavedState ( Parcelable superState ) { }

Fix:
final boolean dispatchSelected = ( ( mCurItem ) != item ) || ( mFirstLayout ) ;