nus-yam/ex-repair huggingface dataset:
Program: 184633
Project: 184633
Buggy source:
private static float getLatLng(Image img,String tag){
  String value=img.getExifTag(tag);
  String ref;
  if (tag == ExifInterface.TAG_GPS_LATITUDE) {
    ref=img.getExifTag(ExifInterface.TAG_GPS_LATITUDE_REF);
  }
 else {
    ref=img.getExifTag(ExifInterface.TAG_GPS_LONGITUDE_REF);
  }
  float f=INVALID_LATLNG;
  if (value != null && ref != null) {
    f=ExifInterface.convertRationalLatLonToFloat(value,ref);
  }
  return f;
}

Fixed version (ground truth):
private static float[] getLatLng(HashMap<String,String> exifData){
  if (exifData == null) {
    return null;
  }
  String latValue=exifData.get(ExifInterface.TAG_GPS_LATITUDE);
  String latRef=exifData.get(ExifInterface.TAG_GPS_LATITUDE_REF);
  String lngValue=exifData.get(ExifInterface.TAG_GPS_LONGITUDE);
  String lngRef=exifData.get(ExifInterface.TAG_GPS_LONGITUDE_REF);
  float[] latlng=null;
  if (latValue != null && latRef != null && lngValue != null && lngRef != null) {
    latlng=new float[2];
    latlng[0]=ExifInterface.convertRationalLatLonToFloat(latValue,latRef);
    latlng[1]=ExifInterface.convertRationalLatLonToFloat(lngValue,lngRef);
  }
  return latlng;
}
Program: 184634
Project: 184634
Buggy source:
private static float setLatLngDetails(View d,Image img,String tag,String refTag){
  int valueId=R.id.details_latitude_value;
  int rowId=R.id.details_latitude_row;
  float latlng=getLatLng(img,tag);
  if (tag == ExifInterface.TAG_GPS_LONGITUDE) {
    valueId=R.id.details_longitude_value;
    rowId=R.id.details_longitude_row;
  }
  if (latlng == INVALID_LATLNG) {
    hideDetailsRow(d,rowId);
    return INVALID_LATLNG;
  }
  setDetailsValue(d,String.valueOf(latlng),valueId);
  return latlng;
}

Fixed version (ground truth):
private static void setLatLngDetails(View d,Activity context,HashMap<String,String> exifData){
  float[] latlng=getLatLng(exifData);
  if (latlng != null) {
    setDetailsValue(d,String.valueOf(latlng[0]),R.id.details_latitude_value);
    setDetailsValue(d,String.valueOf(latlng[1]),R.id.details_longitude_value);
    setReverseGeocodingDetails(d,context,latlng[0],latlng[1]);
  }
 else {
    hideDetailsRow(d,R.id.details_latitude_row);
    hideDetailsRow(d,R.id.details_longitude_row);
    hideDetailsRow(d,R.id.details_location_row);
  }
}
Program: 184636
Project: 184636
Buggy source:
public void onZoom(boolean zoomIn){
  if (zoomIn) {
    mImageView.zoomIn();
  }
 else {
    mImageView.zoomOut();
  }
}

Fixed version (ground truth):
public void onZoom(boolean zoomIn){
  if (zoomIn) {
    mImageView.zoomIn();
  }
 else {
    mImageView.zoomOut();
  }
  updateZoomButtonsEnabled();
}
Program: 184637
Project: 184637
Buggy source:
private void setupZoomButtonController(View rootView){
  mGestureDetector=new GestureDetector(this,new MyGestureListener());
  mZoomButtonsController=new ZoomButtonsController(rootView);
  mZoomButtonsController.setAutoDismissed(false);
  mZoomButtonsController.setOnZoomListener(new ZoomButtonsController.OnZoomListener(){
    public void onVisibilityChanged(    boolean visible){
      if (visible) {
        updateZoomButtonsEnabled();
      }
    }
    public void onZoom(    boolean zoomIn){
      if (zoomIn) {
        mImageView.zoomIn();
      }
 else {
        mImageView.zoomOut();
      }
    }
  }
);
}

Fixed version (ground truth):
private void setupZoomButtonController(View rootView){
  mGestureDetector=new GestureDetector(this,new MyGestureListener());
  mZoomButtonsController=new ZoomButtonsController(rootView);
  mZoomButtonsController.setAutoDismissed(false);
  mZoomButtonsController.setOnZoomListener(new ZoomButtonsController.OnZoomListener(){
    public void onVisibilityChanged(    boolean visible){
      if (visible) {
        updateZoomButtonsEnabled();
      }
    }
    public void onZoom(    boolean zoomIn){
      if (zoomIn) {
        mImageView.zoomIn();
      }
 else {
        mImageView.zoomOut();
      }
      updateZoomButtonsEnabled();
    }
  }
);
}
Program: 184638
Project: 184638
Buggy source:
public int getRow(){
  throw new UnsupportedOperationException();
}

Fixed version (ground truth):
public int getRow(){
  return 0;
}
Program: 184639
Project: 184639
Buggy source:
public int getRow(){
  throw new UnsupportedOperationException();
}

Fixed version (ground truth):
public int getRow(){
  return 0;
}
Program: 184640
Project: 184640
Buggy source:
private void setStart(final int blockNumber){
synchronized (ImageBlock.this) {
    if (blockNumber == mBlockNumber) {
      return;
    }
    cancelExistingRequests();
    mBlockNumber=blockNumber;
    mRequestedMask=0;
    mCompletedMask=0;
    int imageNumber=blockNumber * mCurrentSpec.mColumns;
    int lastImageNumber=mAllImages.getCount() - 1;
    int spacing=mCurrentSpec.mCellSpacing;
    int leftSpacing=mCurrentSpec.mLeftEdgePadding;
    final int yPos=spacing;
    for (int col=0; col < mCurrentSpec.mColumns; col++) {
      if (imageNumber++ >= lastImageNumber) {
        break;
      }
      final int xPos=leftSpacing + (col * (mCurrentSpec.mCellWidth + spacing));
      mCanvas.drawRect(xPos,yPos,xPos + mCurrentSpec.mCellWidth,yPos + mCurrentSpec.mCellHeight,mPaint);
      paintSel(0,xPos,yPos);
    }
  }
}

Fixed version (ground truth):
private synchronized void setStart(final int blockNumber){
  if (blockNumber == mBlockNumber) {
    return;
  }
  cancelExistingRequests();
  mBlockNumber=blockNumber;
  mRequestedMask=0;
  mCompletedMask=0;
  mCanvas.drawColor(0xFF000000);
  mPaint.setColor(0xFFDDDDDD);
  LayoutSpec spec=GridViewSpecial.this.mCurrentSpec;
  int columnCount=spec.mColumns;
  int imageIndex=blockNumber * columnCount;
  int imageCount=mAllImages.getCount();
  int yPos=spec.mCellSpacing;
  int xPos=spec.mLeftEdgePadding;
  for (int i=0; i < columnCount && imageIndex < imageCount; ++i, ++imageIndex) {
    mCanvas.drawRect(xPos,yPos,xPos + spec.mCellWidth,yPos + spec.mCellHeight,mPaint);
    paintSel(0,xPos,yPos);
    xPos+=(spec.mCellWidth + spec.mCellSpacing);
  }
}
Program: 184641
Project: 184641
Buggy source:
/** 
 * @param newSel -2 means use old selection, -1 means remove selection
 * @param newPressed
 */
public void select(int newSel,boolean newPressed){
  if (newSel == -2) {
    newSel=mCurrentSelection;
  }
  int oldSel=mCurrentSelection;
  if ((oldSel == newSel) && (mCurrentSelectionPressed == newPressed)) {
    return;
  }
  mShowSelection=(newSel != REMOVE_SELCTION);
  mCurrentSelection=newSel;
  mCurrentSelectionPressed=newPressed;
  if (mImageBlockManager != null) {
    mImageBlockManager.repaintSelection(oldSel);
    mImageBlockManager.repaintSelection(newSel);
  }
  if (newSel != REMOVE_SELCTION) {
    ensureVisible(newSel);
  }
}

Fixed version (ground truth):
/** 
 * @param newSel -2 means use old selection, -1 means remove selection
 * @param newPressed
 */
public void select(int newSel,boolean newPressed){
  if (newSel == ORIGINAL_SELECT) {
    newSel=mCurrentSelection;
  }
  int oldSel=mCurrentSelection;
  if ((oldSel == newSel) && (mCurrentSelectionPressed == newPressed)) {
    return;
  }
  mShowSelection=(newSel != SELECT_NONE);
  mCurrentSelection=newSel;
  mCurrentSelectionPressed=newPressed;
  if (mImageBlockManager != null) {
    mImageBlockManager.repaintSelection(oldSel);
    mImageBlockManager.repaintSelection(newSel);
  }
  if (newSel != SELECT_NONE) {
    ensureVisible(newSel);
  }
  if (mListener != null) {
    mListener.onImageSelected(mCurrentSelection);
  }
}
Program: 184642
Project: 184642
Buggy source:
ImageBlock(){
  mPaint.setStyle(Paint.Style.FILL);
  mPaint.setColor(0xFFDDDDDD);
  mCanvas.drawColor(0xFF000000);
  mBlockNumber=REMOVE_SELCTION;
  mCellOutline=GridViewSpecial.this.getResources().getDrawable(android.R.drawable.gallery_thumb);
}

Fixed version (ground truth):
ImageBlock(){
  mPaint.setStyle(Paint.Style.FILL);
  mPaint.setColor(0xFFDDDDDD);
  mCanvas.drawColor(0xFF000000);
  mBlockNumber=SELECT_NONE;
  mCellOutline=GridViewSpecial.this.getResources().getDrawable(android.R.drawable.gallery_thumb);
}
Program: 184643
Project: 184643
Buggy source:
@Override public void onLayout(boolean changed,int left,int top,int right,int bottom){
  super.onLayout(changed,left,top,right,bottom);
  if (!mRunning) {
    return;
  }
  clearCache();
  mCurrentSpec=mCellSizeChoices[mSizeChoice];
  LayoutSpec spec=mCurrentSpec;
  int oldColumnCount=spec.mColumns;
  int width=right - left;
  spec.mColumns=1 + (width - spec.mCellWidth) / (spec.mCellWidth + spec.mCellSpacing);
  spec.mLeftEdgePadding=(width - ((spec.mColumns - 1) * spec.mCellSpacing) - (spec.mColumns * spec.mCellWidth)) / 2;
  spec.mRightEdgePadding=spec.mLeftEdgePadding;
  int rows=(mAllImages.getCount() + spec.mColumns - 1) / spec.mColumns;
  mMaxScrollY=spec.mCellSpacing + (rows * (spec.mCellSpacing + spec.mCellHeight)) - (bottom - top);
  if (mImageBlockManager == null) {
    mImageBlockManager=new ImageBlockManager(mLoader);
    mImageBlockManager.moveDataWindow(true);
  }
  mLayoutComplete=true;
  if (mListener != null)   mListener.onLayout();
}

Fixed version (ground truth):
@Override public void onLayout(boolean changed,int left,int top,int right,int bottom){
  super.onLayout(changed,left,top,right,bottom);
  if (!mRunning) {
    return;
  }
  clearCache();
  mCurrentSpec=mCellSizeChoices[mSizeChoice];
  LayoutSpec spec=mCurrentSpec;
  int oldColumnCount=spec.mColumns;
  int width=right - left;
  spec.mColumns=1 + (width - spec.mCellWidth) / (spec.mCellWidth + spec.mCellSpacing);
  spec.mLeftEdgePadding=(width - ((spec.mColumns - 1) * spec.mCellSpacing) - (spec.mColumns * spec.mCellWidth)) / 2;
  spec.mRightEdgePadding=spec.mLeftEdgePadding;
  int rows=(mAllImages.getCount() + spec.mColumns - 1) / spec.mColumns;
  mMaxScrollY=spec.mCellSpacing + (rows * (spec.mCellSpacing + spec.mCellHeight)) - (bottom - top);
  if (mImageBlockManager == null) {
    mImageBlockManager=new ImageBlockManager();
    mImageBlockManager.moveDataWindow(true);
  }
  mLayoutComplete=true;
  if (mListener != null)   mListener.onLayoutComplete(changed);
}
Program: 184644
Project: 184644
Buggy source:
@Override public boolean onFling(MotionEvent e1,MotionEvent e2,float velocityX,float velocityY){
  final float maxVelocity=2500;
  if (velocityY > maxVelocity) {
    velocityY=maxVelocity;
  }
 else   if (velocityY < -maxVelocity) {
    velocityY=-maxVelocity;
  }
  select(REMOVE_SELCTION,false);
  if (mFling) {
    mScroller=new Scroller(getContext());
    mScroller.fling(0,mScrollY,0,-(int)velocityY,0,0,0,mMaxScrollY);
    computeScroll();
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean onFling(MotionEvent e1,MotionEvent e2,float velocityX,float velocityY){
  final float maxVelocity=2500;
  if (velocityY > maxVelocity) {
    velocityY=maxVelocity;
  }
 else   if (velocityY < -maxVelocity) {
    velocityY=-maxVelocity;
  }
  select(SELECT_NONE,false);
  if (mFling) {
    mScroller=new Scroller(getContext());
    mScroller.fling(0,mScrollY,0,-(int)velocityY,0,0,0,mMaxScrollY);
    computeScroll();
  }
  return true;
}
Program: 184645
Project: 184645
Buggy source:
@Override public void scrollTo(int x,int y){
  y=Math.min(mMaxScrollY,y);
  y=Math.max(0,y);
  if (mListener != null && mCurrentSpec != null) {
    int index=Math.min(mAllImages.getCount(),Math.max(0,computeSelectedIndex(x,y)));
    mListener.onScroll(index);
  }
  super.scrollTo(x,y);
}

Fixed version (ground truth):
@Override public void scrollTo(int x,int y){
  y=Math.max(0,Math.min(mMaxScrollY,y));
  if (mListener != null && mCurrentSpec != null) {
    mListener.onScroll((float)mScrollY / mMaxScrollY);
  }
  super.scrollTo(x,y);
}
Program: 184646
Project: 184646
Buggy source:
@Override public boolean onDown(MotionEvent e){
  if (mScroller != null && !mScroller.isFinished()) {
    mScroller.forceFinished(true);
    return false;
  }
  int pos=computeSelectedIndex(e.getX(),e.getY());
  if (pos >= 0 && pos < mAllImages.getCount()) {
    select(pos,true);
  }
 else {
    select(REMOVE_SELCTION,false);
  }
  if (mImageBlockManager != null) {
    mImageBlockManager.repaintSelection(mCurrentSelection);
  }
  invalidate();
  return true;
}

Fixed version (ground truth):
@Override public boolean onDown(MotionEvent e){
  if (mScroller != null && !mScroller.isFinished()) {
    mScroller.forceFinished(true);
    return false;
  }
  int pos=computeSelectedIndex(e.getX(),e.getY());
  if (pos >= 0 && pos < mAllImages.getCount()) {
    select(pos,true);
  }
 else {
    select(SELECT_NONE,false);
  }
  if (mImageBlockManager != null) {
    mImageBlockManager.repaintSelection(mCurrentSelection);
  }
  invalidate();
  return true;
}
Program: 184647
Project: 184647
Buggy source:
public void onScroll(int index);

Fixed version (ground truth):
/** 
 * Invoked when the <code>GridViewSpecial</code> scrolls.
 * @param scrollPosition the position of the scroller in the range[0, 1], when 0 means on the top and 1 means on the button
 */
public void onScroll(float scrollPosition);
Program: 184648
Project: 184648
Buggy source:
public void setSizeChoice(int choice,int scrollY){
  mSizeChoice=choice;
  clearCache();
  scrollTo(0,scrollY);
  requestLayout();
  invalidate();
}

Fixed version (ground truth):
public void setSizeChoice(int choice){
  mSizeChoice=choice;
  clearCache();
  requestLayout();
  invalidate();
}
Program: 184649
Project: 184649
Buggy source:
@Override public boolean onKeyUp(int keyCode,KeyEvent event){
  if (!canHandleEvent())   return false;
  if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
    select(GridViewSpecial.ORIGINAL_SELECT,false);
    mHandler.removeCallbacks(mLongPressCallback);
    if (mListener != null)     mListener.onSelect(mCurrentSelection);
    return true;
  }
  return super.onKeyUp(keyCode,event);
}

Fixed version (ground truth):
@Override public boolean onKeyUp(int keyCode,KeyEvent event){
  if (!canHandleEvent())   return false;
  if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
    select(GridViewSpecial.ORIGINAL_SELECT,false);
    mHandler.removeCallbacks(mLongPressCallback);
    if (mListener != null)     mListener.onImageClicked(mCurrentSelection);
    return true;
  }
  return super.onKeyUp(keyCode,event);
}
Program: 184650
Project: 184650
Buggy source:
@Override public boolean onSingleTapUp(MotionEvent e){
  select(mCurrentSelection,false);
  int index=computeSelectedIndex(e.getX(),e.getY());
  if (index >= 0 && index < mAllImages.getCount()) {
    if (mListener != null)     mListener.onSelect(index);
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean onSingleTapUp(MotionEvent e){
  select(mCurrentSelection,false);
  int index=computeSelectedIndex(e.getX(),e.getY());
  if (index >= 0 && index < mAllImages.getCount()) {
    if (mListener != null)     mListener.onImageClicked(index);
    return true;
  }
  return false;
}
Program: 184651
Project: 184651
Buggy source:
ImageBlockManager(ImageLoader loader){
  mLoader=loader;
  mBlockCache=new ImageBlock[ROWS_PER_PAGE * (PAGES_PRE_CACHE + PAGES_POST_CACHE + 1)];
  for (int i=0; i < mBlockCache.length; i++) {
    mBlockCache[i]=new ImageBlock();
  }
  mWorkerThread=new Thread(new Runnable(){
    public void run(){
      while (true) {
        int workCounter;
synchronized (ImageBlockManager.this) {
          workCounter=mWorkCounter;
        }
        if (mDone) {
          mLoader.stop();
          for (int i=0; i < mBlockCache.length; i++) {
            ImageBlock block=mBlockCache[i];
            if (block != null) {
              block.recycleBitmaps();
              mBlockCache[i]=null;
            }
          }
          mBlockCache=null;
          mBlockCacheStartOffset=0;
          mBlockCacheFirstBlockNumber=0;
          break;
        }
        loadNext();
synchronized (ImageBlockManager.this) {
          if ((workCounter == mWorkCounter) && (!mDone)) {
            try {
              ImageBlockManager.this.wait();
            }
 catch (            InterruptedException ex) {
            }
          }
        }
      }
    }
  }
);
  mWorkerThread.setName("String_Node_Str");
  mWorkerThread.start();
}

Fixed version (ground truth):
ImageBlockManager(){
  mBlockCache=new ImageBlock[ROWS_PER_PAGE * (PAGES_PRE_CACHE + PAGES_POST_CACHE + 1)];
  for (int i=0; i < mBlockCache.length; i++) {
    mBlockCache[i]=new ImageBlock();
  }
  mWorkerThread=new Thread(new Runnable(){
    public void run(){
      while (true) {
        int workCounter;
synchronized (ImageBlockManager.this) {
          workCounter=mWorkCounter;
        }
        if (mDone) {
          mLoader.stop();
          for (int i=0; i < mBlockCache.length; i++) {
            ImageBlock block=mBlockCache[i];
            if (block != null) {
              block.recycleBitmaps();
              mBlockCache[i]=null;
            }
          }
          mBlockCache=null;
          mBlockCacheStartOffset=0;
          mBlockCacheFirstBlockNumber=0;
          break;
        }
        loadNext();
synchronized (ImageBlockManager.this) {
          if ((workCounter == mWorkCounter) && (!mDone)) {
            try {
              ImageBlockManager.this.wait();
            }
 catch (            InterruptedException ex) {
            }
          }
        }
      }
    }
  }
);
  mWorkerThread.setName("String_Node_Str");
  mWorkerThread.start();
}
Program: 184652
Project: 184652
Buggy source:
public void invalidateAllImages(){
  this.clearCache();
  mImageBlockManager=new ImageBlockManager(mLoader);
  mImageBlockManager.moveDataWindow(true);
}

Fixed version (ground truth):
public void invalidateAllImages(){
  this.clearCache();
  mImageBlockManager=new ImageBlockManager();
  mImageBlockManager.moveDataWindow(true);
}
Program: 184653
Project: 184653
Buggy source:
@Override protected void onRestoreInstanceState(Bundle state){
  super.onRestoreInstanceState(state);
  mTargetScroll=state.getInt(INSTANCE_STATE_TAG,0);
}

Fixed version (ground truth):
@Override protected void onRestoreInstanceState(Bundle state){
  super.onRestoreInstanceState(state);
  mScrollPosition=state.getFloat(STATE_SCROLL_POSITION,INVALID_POSITION);
  mSelectedIndex=state.getInt(STATE_SELECTED_INDEX,0);
}
Program: 184654
Project: 184654
Buggy source:
public void onScroll(int index){
  mFirstVisibleIndex=index;
}

Fixed version (ground truth):
public void onScroll(float scrollPosition){
  mScrollPosition=scrollPosition;
}
Program: 184656
Project: 184656
Buggy source:
@Override protected void onSaveInstanceState(Bundle state){
  super.onSaveInstanceState(state);
  mTargetScroll=mGvs.getScrollY();
  state.putInt(INSTANCE_STATE_TAG,mTargetScroll);
}

Fixed version (ground truth):
@Override protected void onSaveInstanceState(Bundle state){
  super.onSaveInstanceState(state);
  state.putFloat(STATE_SCROLL_POSITION,mScrollPosition);
  state.putInt(STATE_SELECTED_INDEX,mSelectedIndex);
}
Program: 184657
Project: 184657
Buggy source:
@Override public void onConfigurationChanged(Configuration newConfig){
  super.onConfigurationChanged(newConfig);
  mTargetScroll=mGvs.getScrollY();
}

Fixed version (ground truth):
@Override public void onConfigurationChanged(Configuration newConfig){
  super.onConfigurationChanged(newConfig);
  mConfigurationChanged=true;
}
Program: 184658
Project: 184658
Buggy source:
public void onCreateContextMenu(ContextMenu menu,View v,ContextMenu.ContextMenuInfo menuInfo){
  if (getCurrentImage() == null) {
    return;
  }
  boolean isImage=ImageManager.isImage(getCurrentImage());
  if (isImage) {
    menu.add(0,0,0,R.string.view).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
      public boolean onMenuItemClick(      MenuItem item){
        onSelect(mGvs.mCurrentSelection);
        return true;
      }
    }
);
  }
  menu.setHeaderTitle(isImage ? R.string.context_menu_header : R.string.video_context_menu_header);
  if ((mInclusion & (ImageManager.INCLUDE_IMAGES | ImageManager.INCLUDE_VIDEOS)) != 0) {
    MenuHelper.MenuItemsResult r=MenuHelper.addImageMenuItems(menu,MenuHelper.INCLUDE_ALL,isImage,ImageGallery.this,mHandler,mDeletePhotoRunnable,new MenuHelper.MenuInvoker(){
      public void run(      MenuHelper.MenuCallback cb){
        cb.run(getCurrentImageUri(),getCurrentImage());
        mGvs.clearCache();
        mGvs.invalidate();
        mGvs.requestLayout();
        mGvs.start();
        mNoImagesView.setVisibility(mAllImages.getCount() > 0 ? View.GONE : View.VISIBLE);
      }
    }
);
    if (r != null) {
      r.gettingReadyToOpen(menu,getCurrentImage());
    }
    if (isImage) {
      addSlideShowMenu(menu,1000);
    }
  }
}

Fixed version (ground truth):
public void onCreateContextMenu(ContextMenu menu,View v,ContextMenu.ContextMenuInfo menuInfo){
  if (getCurrentImage() == null) {
    return;
  }
  boolean isImage=ImageManager.isImage(getCurrentImage());
  if (isImage) {
    menu.add(0,0,0,R.string.view).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
      public boolean onMenuItemClick(      MenuItem item){
        onImageClicked(mGvs.mCurrentSelection);
        return true;
      }
    }
);
  }
  menu.setHeaderTitle(isImage ? R.string.context_menu_header : R.string.video_context_menu_header);
  if ((mInclusion & (ImageManager.INCLUDE_IMAGES | ImageManager.INCLUDE_VIDEOS)) != 0) {
    MenuHelper.MenuItemsResult r=MenuHelper.addImageMenuItems(menu,MenuHelper.INCLUDE_ALL,isImage,ImageGallery.this,mHandler,mDeletePhotoRunnable,new MenuHelper.MenuInvoker(){
      public void run(      MenuHelper.MenuCallback cb){
        cb.run(getCurrentImageUri(),getCurrentImage());
        mGvs.clearCache();
        mGvs.invalidate();
        mGvs.requestLayout();
        mGvs.start();
        mNoImagesView.setVisibility(mAllImages.getCount() > 0 ? View.GONE : View.VISIBLE);
      }
    }
);
    if (r != null) {
      r.gettingReadyToOpen(menu,getCurrentImage());
    }
    if (isImage) {
      addSlideShowMenu(menu,1000);
    }
  }
}
Program: 184659
Project: 184659
Buggy source:
public boolean onMenuItemClick(MenuItem item){
  onSelect(mGvs.mCurrentSelection);
  return true;
}

Fixed version (ground truth):
public boolean onMenuItemClick(MenuItem item){
  onImageClicked(mGvs.mCurrentSelection);
  return true;
}
Program: 184660
Project: 184660
Buggy source:
/** 
 * @param newSel -2 means use old selection, -1 means remove selection
 * @param newPressed
 */
public void select(int newSel,boolean newPressed){
  if (newSel == -2) {
    newSel=mCurrentSelection;
  }
  int oldSel=mCurrentSelection;
  if ((oldSel == newSel) && (mCurrentSelectionPressed == newPressed)) {
    return;
  }
  mShowSelection=(newSel != REMOVE_SELCTION);
  mCurrentSelection=newSel;
  mCurrentSelectionPressed=newPressed;
  if (mImageBlockManager != null) {
    mImageBlockManager.repaintSelection(oldSel);
    mImageBlockManager.repaintSelection(newSel);
  }
  if (newSel != REMOVE_SELCTION) {
    ensureVisible(newSel);
  }
}

Fixed version (ground truth):
/** 
 * @param newSel -2 means use old selection, -1 means remove selection
 * @param newPressed
 */
public void select(int newSel,boolean newPressed){
  if (newSel == ORIGINAL_SELECT) {
    newSel=mCurrentSelection;
  }
  int oldSel=mCurrentSelection;
  if ((oldSel == newSel) && (mCurrentSelectionPressed == newPressed)) {
    return;
  }
  mShowSelection=(newSel != SELECT_NONE);
  mCurrentSelection=newSel;
  mCurrentSelectionPressed=newPressed;
  if (mImageBlockManager != null) {
    mImageBlockManager.repaintSelection(oldSel);
    mImageBlockManager.repaintSelection(newSel);
  }
  if (newSel != SELECT_NONE) {
    ensureVisible(newSel);
  }
  if (mListener != null) {
    mListener.onImageSelected(mCurrentSelection);
  }
}
Program: 184661
Project: 184661
Buggy source:
ImageBlock(){
  mPaint.setStyle(Paint.Style.FILL);
  mPaint.setColor(0xFFDDDDDD);
  mCanvas.drawColor(0xFF000000);
  mBlockNumber=REMOVE_SELCTION;
  mCellOutline=GridViewSpecial.this.getResources().getDrawable(android.R.drawable.gallery_thumb);
}

Fixed version (ground truth):
ImageBlock(){
  mPaint.setStyle(Paint.Style.FILL);
  mPaint.setColor(0xFFDDDDDD);
  mCanvas.drawColor(0xFF000000);
  mBlockNumber=SELECT_NONE;
  mCellOutline=GridViewSpecial.this.getResources().getDrawable(android.R.drawable.gallery_thumb);
}
Program: 184662
Project: 184662
Buggy source:
@Override public void onLayout(boolean changed,int left,int top,int right,int bottom){
  super.onLayout(changed,left,top,right,bottom);
  if (!mRunning) {
    return;
  }
  clearCache();
  mCurrentSpec=mCellSizeChoices[mSizeChoice];
  LayoutSpec spec=mCurrentSpec;
  int oldColumnCount=spec.mColumns;
  int width=right - left;
  spec.mColumns=1 + (width - spec.mCellWidth) / (spec.mCellWidth + spec.mCellSpacing);
  spec.mLeftEdgePadding=(width - ((spec.mColumns - 1) * spec.mCellSpacing) - (spec.mColumns * spec.mCellWidth)) / 2;
  spec.mRightEdgePadding=spec.mLeftEdgePadding;
  int rows=(mAllImages.getCount() + spec.mColumns - 1) / spec.mColumns;
  mMaxScrollY=spec.mCellSpacing + (rows * (spec.mCellSpacing + spec.mCellHeight)) - (bottom - top);
  if (mImageBlockManager == null) {
    mImageBlockManager=new ImageBlockManager(mLoader);
    mImageBlockManager.moveDataWindow(true);
  }
  mLayoutComplete=true;
  if (mListener != null)   mListener.onLayout();
}

Fixed version (ground truth):
@Override public void onLayout(boolean changed,int left,int top,int right,int bottom){
  super.onLayout(changed,left,top,right,bottom);
  if (!mRunning) {
    return;
  }
  clearCache();
  mCurrentSpec=mCellSizeChoices[mSizeChoice];
  LayoutSpec spec=mCurrentSpec;
  int oldColumnCount=spec.mColumns;
  int width=right - left;
  spec.mColumns=1 + (width - spec.mCellWidth) / (spec.mCellWidth + spec.mCellSpacing);
  spec.mLeftEdgePadding=(width - ((spec.mColumns - 1) * spec.mCellSpacing) - (spec.mColumns * spec.mCellWidth)) / 2;
  spec.mRightEdgePadding=spec.mLeftEdgePadding;
  int rows=(mAllImages.getCount() + spec.mColumns - 1) / spec.mColumns;
  mMaxScrollY=spec.mCellSpacing + (rows * (spec.mCellSpacing + spec.mCellHeight)) - (bottom - top);
  if (mImageBlockManager == null) {
    mImageBlockManager=new ImageBlockManager();
    mImageBlockManager.moveDataWindow(true);
  }
  mLayoutComplete=true;
  if (mListener != null)   mListener.onLayoutComplete(changed);
}
Program: 184663
Project: 184663
Buggy source:
@Override public boolean onFling(MotionEvent e1,MotionEvent e2,float velocityX,float velocityY){
  final float maxVelocity=2500;
  if (velocityY > maxVelocity) {
    velocityY=maxVelocity;
  }
 else   if (velocityY < -maxVelocity) {
    velocityY=-maxVelocity;
  }
  select(REMOVE_SELCTION,false);
  if (mFling) {
    mScroller=new Scroller(getContext());
    mScroller.fling(0,mScrollY,0,-(int)velocityY,0,0,0,mMaxScrollY);
    computeScroll();
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean onFling(MotionEvent e1,MotionEvent e2,float velocityX,float velocityY){
  final float maxVelocity=2500;
  if (velocityY > maxVelocity) {
    velocityY=maxVelocity;
  }
 else   if (velocityY < -maxVelocity) {
    velocityY=-maxVelocity;
  }
  select(SELECT_NONE,false);
  if (mFling) {
    mScroller=new Scroller(getContext());
    mScroller.fling(0,mScrollY,0,-(int)velocityY,0,0,0,mMaxScrollY);
    computeScroll();
  }
  return true;
}
Program: 184664
Project: 184664
Buggy source:
@Override public void scrollTo(int x,int y){
  y=Math.min(mMaxScrollY,y);
  y=Math.max(0,y);
  if (mListener != null && mCurrentSpec != null) {
    int index=Math.min(mAllImages.getCount(),Math.max(0,computeSelectedIndex(x,y)));
    mListener.onScroll(index);
  }
  super.scrollTo(x,y);
}

Fixed version (ground truth):
@Override public void scrollTo(int x,int y){
  y=Math.max(0,Math.min(mMaxScrollY,y));
  if (mListener != null && mCurrentSpec != null) {
    mListener.onScroll((float)mScrollY / mMaxScrollY);
  }
  super.scrollTo(x,y);
}
Program: 184665
Project: 184665
Buggy source:
@Override public boolean onDown(MotionEvent e){
  if (mScroller != null && !mScroller.isFinished()) {
    mScroller.forceFinished(true);
    return false;
  }
  int pos=computeSelectedIndex(e.getX(),e.getY());
  if (pos >= 0 && pos < mAllImages.getCount()) {
    select(pos,true);
  }
 else {
    select(REMOVE_SELCTION,false);
  }
  if (mImageBlockManager != null) {
    mImageBlockManager.repaintSelection(mCurrentSelection);
  }
  invalidate();
  return true;
}

Fixed version (ground truth):
@Override public boolean onDown(MotionEvent e){
  if (mScroller != null && !mScroller.isFinished()) {
    mScroller.forceFinished(true);
    return false;
  }
  int pos=computeSelectedIndex(e.getX(),e.getY());
  if (pos >= 0 && pos < mAllImages.getCount()) {
    select(pos,true);
  }
 else {
    select(SELECT_NONE,false);
  }
  if (mImageBlockManager != null) {
    mImageBlockManager.repaintSelection(mCurrentSelection);
  }
  invalidate();
  return true;
}
Program: 184666
Project: 184666
Buggy source:
public void onScroll(int index);

Fixed version (ground truth):
/** 
 * Invoked when the <code>GridViewSpecial</code> scrolls.
 * @param scrollPosition the position of the scroller in the range[0, 1], when 0 means on the top and 1 means on the button
 */
public void onScroll(float scrollPosition);
Program: 184667
Project: 184667
Buggy source:
public void setSizeChoice(int choice,int scrollY){
  mSizeChoice=choice;
  clearCache();
  scrollTo(0,scrollY);
  requestLayout();
  invalidate();
}

Fixed version (ground truth):
public void setSizeChoice(int choice){
  mSizeChoice=choice;
  clearCache();
  requestLayout();
  invalidate();
}
Program: 184668
Project: 184668
Buggy source:
@Override public boolean onKeyUp(int keyCode,KeyEvent event){
  if (!canHandleEvent())   return false;
  if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
    select(GridViewSpecial.ORIGINAL_SELECT,false);
    mHandler.removeCallbacks(mLongPressCallback);
    if (mListener != null)     mListener.onSelect(mCurrentSelection);
    return true;
  }
  return super.onKeyUp(keyCode,event);
}

Fixed version (ground truth):
@Override public boolean onKeyUp(int keyCode,KeyEvent event){
  if (!canHandleEvent())   return false;
  if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
    select(GridViewSpecial.ORIGINAL_SELECT,false);
    mHandler.removeCallbacks(mLongPressCallback);
    if (mListener != null)     mListener.onImageClicked(mCurrentSelection);
    return true;
  }
  return super.onKeyUp(keyCode,event);
}
Program: 184669
Project: 184669
Buggy source:
@Override public boolean onSingleTapUp(MotionEvent e){
  select(mCurrentSelection,false);
  int index=computeSelectedIndex(e.getX(),e.getY());
  if (index >= 0 && index < mAllImages.getCount()) {
    if (mListener != null)     mListener.onSelect(index);
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean onSingleTapUp(MotionEvent e){
  select(mCurrentSelection,false);
  int index=computeSelectedIndex(e.getX(),e.getY());
  if (index >= 0 && index < mAllImages.getCount()) {
    if (mListener != null)     mListener.onImageClicked(index);
    return true;
  }
  return false;
}
Program: 184670
Project: 184670
Buggy source:
ImageBlockManager(ImageLoader loader){
  mLoader=loader;
  mBlockCache=new ImageBlock[ROWS_PER_PAGE * (PAGES_PRE_CACHE + PAGES_POST_CACHE + 1)];
  for (int i=0; i < mBlockCache.length; i++) {
    mBlockCache[i]=new ImageBlock();
  }
  mWorkerThread=new Thread(new Runnable(){
    public void run(){
      while (true) {
        int workCounter;
synchronized (ImageBlockManager.this) {
          workCounter=mWorkCounter;
        }
        if (mDone) {
          mLoader.stop();
          for (int i=0; i < mBlockCache.length; i++) {
            ImageBlock block=mBlockCache[i];
            if (block != null) {
              block.recycleBitmaps();
              mBlockCache[i]=null;
            }
          }
          mBlockCache=null;
          mBlockCacheStartOffset=0;
          mBlockCacheFirstBlockNumber=0;
          break;
        }
        loadNext();
synchronized (ImageBlockManager.this) {
          if ((workCounter == mWorkCounter) && (!mDone)) {
            try {
              ImageBlockManager.this.wait();
            }
 catch (            InterruptedException ex) {
            }
          }
        }
      }
    }
  }
);
  mWorkerThread.setName("String_Node_Str");
  mWorkerThread.start();
}

Fixed version (ground truth):
ImageBlockManager(){
  mBlockCache=new ImageBlock[ROWS_PER_PAGE * (PAGES_PRE_CACHE + PAGES_POST_CACHE + 1)];
  for (int i=0; i < mBlockCache.length; i++) {
    mBlockCache[i]=new ImageBlock();
  }
  mWorkerThread=new Thread(new Runnable(){
    public void run(){
      while (true) {
        int workCounter;
synchronized (ImageBlockManager.this) {
          workCounter=mWorkCounter;
        }
        if (mDone) {
          mLoader.stop();
          for (int i=0; i < mBlockCache.length; i++) {
            ImageBlock block=mBlockCache[i];
            if (block != null) {
              block.recycleBitmaps();
              mBlockCache[i]=null;
            }
          }
          mBlockCache=null;
          mBlockCacheStartOffset=0;
          mBlockCacheFirstBlockNumber=0;
          break;
        }
        loadNext();
synchronized (ImageBlockManager.this) {
          if ((workCounter == mWorkCounter) && (!mDone)) {
            try {
              ImageBlockManager.this.wait();
            }
 catch (            InterruptedException ex) {
            }
          }
        }
      }
    }
  }
);
  mWorkerThread.setName("String_Node_Str");
  mWorkerThread.start();
}
Program: 184671
Project: 184671
Buggy source:
public void invalidateAllImages(){
  this.clearCache();
  mImageBlockManager=new ImageBlockManager(mLoader);
  mImageBlockManager.moveDataWindow(true);
}

Fixed version (ground truth):
public void invalidateAllImages(){
  this.clearCache();
  mImageBlockManager=new ImageBlockManager();
  mImageBlockManager.moveDataWindow(true);
}
Program: 184672
Project: 184672
Buggy source:
@Override protected void onRestoreInstanceState(Bundle state){
  super.onRestoreInstanceState(state);
  mTargetScroll=state.getInt(INSTANCE_STATE_TAG,0);
}

Fixed version (ground truth):
@Override protected void onRestoreInstanceState(Bundle state){
  super.onRestoreInstanceState(state);
  mScrollPosition=state.getFloat(STATE_SCROLL_POSITION,INVALID_POSITION);
  mSelectedIndex=state.getInt(STATE_SELECTED_INDEX,0);
}
Program: 184673
Project: 184673
Buggy source:
public void onScroll(int index){
  mFirstVisibleIndex=index;
}

Fixed version (ground truth):
public void onScroll(float scrollPosition){
  mScrollPosition=scrollPosition;
}
Program: 184675
Project: 184675
Buggy source:
@Override protected void onSaveInstanceState(Bundle state){
  super.onSaveInstanceState(state);
  mTargetScroll=mGvs.getScrollY();
  state.putInt(INSTANCE_STATE_TAG,mTargetScroll);
}

Fixed version (ground truth):
@Override protected void onSaveInstanceState(Bundle state){
  super.onSaveInstanceState(state);
  state.putFloat(STATE_SCROLL_POSITION,mScrollPosition);
  state.putInt(STATE_SELECTED_INDEX,mSelectedIndex);
}
Program: 184676
Project: 184676
Buggy source:
@Override public void onConfigurationChanged(Configuration newConfig){
  super.onConfigurationChanged(newConfig);
  mTargetScroll=mGvs.getScrollY();
}

Fixed version (ground truth):
@Override public void onConfigurationChanged(Configuration newConfig){
  super.onConfigurationChanged(newConfig);
  mConfigurationChanged=true;
}
Program: 184677
Project: 184677
Buggy source:
public void onCreateContextMenu(ContextMenu menu,View v,ContextMenu.ContextMenuInfo menuInfo){
  if (getCurrentImage() == null) {
    return;
  }
  boolean isImage=ImageManager.isImage(getCurrentImage());
  if (isImage) {
    menu.add(0,0,0,R.string.view).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
      public boolean onMenuItemClick(      MenuItem item){
        onSelect(mGvs.mCurrentSelection);
        return true;
      }
    }
);
  }
  menu.setHeaderTitle(isImage ? R.string.context_menu_header : R.string.video_context_menu_header);
  if ((mInclusion & (ImageManager.INCLUDE_IMAGES | ImageManager.INCLUDE_VIDEOS)) != 0) {
    MenuHelper.MenuItemsResult r=MenuHelper.addImageMenuItems(menu,MenuHelper.INCLUDE_ALL,isImage,ImageGallery.this,mHandler,mDeletePhotoRunnable,new MenuHelper.MenuInvoker(){
      public void run(      MenuHelper.MenuCallback cb){
        cb.run(getCurrentImageUri(),getCurrentImage());
        mGvs.clearCache();
        mGvs.invalidate();
        mGvs.requestLayout();
        mGvs.start();
        mNoImagesView.setVisibility(mAllImages.getCount() > 0 ? View.GONE : View.VISIBLE);
      }
    }
);
    if (r != null) {
      r.gettingReadyToOpen(menu,getCurrentImage());
    }
    if (isImage) {
      addSlideShowMenu(menu,1000);
    }
  }
}

Fixed version (ground truth):
public void onCreateContextMenu(ContextMenu menu,View v,ContextMenu.ContextMenuInfo menuInfo){
  if (getCurrentImage() == null) {
    return;
  }
  boolean isImage=ImageManager.isImage(getCurrentImage());
  if (isImage) {
    menu.add(0,0,0,R.string.view).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
      public boolean onMenuItemClick(      MenuItem item){
        onImageClicked(mGvs.mCurrentSelection);
        return true;
      }
    }
);
  }
  menu.setHeaderTitle(isImage ? R.string.context_menu_header : R.string.video_context_menu_header);
  if ((mInclusion & (ImageManager.INCLUDE_IMAGES | ImageManager.INCLUDE_VIDEOS)) != 0) {
    MenuHelper.MenuItemsResult r=MenuHelper.addImageMenuItems(menu,MenuHelper.INCLUDE_ALL,isImage,ImageGallery.this,mHandler,mDeletePhotoRunnable,new MenuHelper.MenuInvoker(){
      public void run(      MenuHelper.MenuCallback cb){
        cb.run(getCurrentImageUri(),getCurrentImage());
        mGvs.clearCache();
        mGvs.invalidate();
        mGvs.requestLayout();
        mGvs.start();
        mNoImagesView.setVisibility(mAllImages.getCount() > 0 ? View.GONE : View.VISIBLE);
      }
    }
);
    if (r != null) {
      r.gettingReadyToOpen(menu,getCurrentImage());
    }
    if (isImage) {
      addSlideShowMenu(menu,1000);
    }
  }
}
Program: 184678
Project: 184678
Buggy source:
public boolean onMenuItemClick(MenuItem item){
  onSelect(mGvs.mCurrentSelection);
  return true;
}

Fixed version (ground truth):
public boolean onMenuItemClick(MenuItem item){
  onImageClicked(mGvs.mCurrentSelection);
  return true;
}
Program: 184679
Project: 184679
Buggy source:
private void setStart(final int blockNumber){
synchronized (ImageBlock.this) {
    if (blockNumber == mBlockNumber) {
      return;
    }
    cancelExistingRequests();
    mBlockNumber=blockNumber;
    mRequestedMask=0;
    mCompletedMask=0;
    int imageNumber=blockNumber * mCurrentSpec.mColumns;
    int lastImageNumber=mAllImages.getCount() - 1;
    int spacing=mCurrentSpec.mCellSpacing;
    int leftSpacing=mCurrentSpec.mLeftEdgePadding;
    final int yPos=spacing;
    for (int col=0; col < mCurrentSpec.mColumns; col++) {
      if (imageNumber++ >= lastImageNumber) {
        break;
      }
      final int xPos=leftSpacing + (col * (mCurrentSpec.mCellWidth + spacing));
      mCanvas.drawRect(xPos,yPos,xPos + mCurrentSpec.mCellWidth,yPos + mCurrentSpec.mCellHeight,mPaint);
      paintSel(0,xPos,yPos);
    }
  }
}

Fixed version (ground truth):
private synchronized void setStart(final int blockNumber){
  if (blockNumber == mBlockNumber) {
    return;
  }
  cancelExistingRequests();
  mBlockNumber=blockNumber;
  mRequestedMask=0;
  mCompletedMask=0;
  mCanvas.drawColor(0xFF000000);
  mPaint.setColor(0xFFDDDDDD);
  LayoutSpec spec=GridViewSpecial.this.mCurrentSpec;
  int columnCount=spec.mColumns;
  int imageIndex=blockNumber * columnCount;
  int imageCount=mAllImages.getCount();
  int yPos=spec.mCellSpacing;
  int xPos=spec.mLeftEdgePadding;
  for (int i=0; i < columnCount && imageIndex < imageCount; ++i, ++imageIndex) {
    mCanvas.drawRect(xPos,yPos,xPos + spec.mCellWidth,yPos + spec.mCellHeight,mPaint);
    paintSel(0,xPos,yPos);
    xPos+=(spec.mCellWidth + spec.mCellSpacing);
  }
}
Program: 184680
Project: 184680
Buggy source:
public static void debugWhere(String tag,String msg){
  Exception ex=new Exception();
  Log.d(tag,msg,ex);
}

Fixed version (ground truth):
public static void debugWhere(String tag,String msg){
  Log.d(tag,msg + "String_Node_Str");
  StackTraceElement elements[]=Thread.currentThread().getStackTrace();
  for (int i=3, n=elements.length; i < n; ++i) {
    StackTraceElement st=elements[i];
    String message=String.format("String_Node_Str",st.getClassName(),st.getMethodName(),st.getFileName(),st.getLineNumber());
    Log.d(tag,message);
  }
  Log.d(tag,msg + "String_Node_Str");
}
Program: 184682
Project: 184682
Buggy source:
@Override public boolean onCreateOptionsMenu(Menu menu){
  MenuItem item;
  if (isPickIntent()) {
    MenuHelper.addCapturePictureMenuItems(menu,this);
  }
 else {
    MenuHelper.addCaptureMenuItems(menu,this);
    if ((mInclusion & ImageManager.INCLUDE_IMAGES) != 0) {
      mSlideShowItem=addSlideShowMenu(menu,5);
    }
  }
  item=menu.add(0,0,1000,R.string.camerasettings);
  item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
    public boolean onMenuItemClick(    MenuItem item){
      Intent preferences=new Intent();
      preferences.setClass(ImageGallery2.this,GallerySettings.class);
      startActivity(preferences);
      return true;
    }
  }
);
  item.setAlphabeticShortcut('p');
  item.setIcon(android.R.drawable.ic_menu_preferences);
  return true;
}

Fixed version (ground truth):
@Override public boolean onCreateOptionsMenu(Menu menu){
  if (isPickIntent()) {
    String type=getIntent().resolveType(this);
    if (type != null) {
      if (isImageType(type)) {
        MenuHelper.addCapturePictureMenuItems(menu,this);
      }
 else       if (isVideoType(type)) {
        MenuHelper.addCaptureVideoMenuItems(menu,this);
      }
    }
  }
 else {
    MenuHelper.addCaptureMenuItems(menu,this);
    if ((mInclusion & ImageManager.INCLUDE_IMAGES) != 0) {
      mSlideShowItem=addSlideShowMenu(menu,5);
    }
    MenuItem item=menu.add(0,0,1000,R.string.camerasettings);
    item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
      public boolean onMenuItemClick(      MenuItem item){
        Intent preferences=new Intent();
        preferences.setClass(ImageGallery2.this,GallerySettings.class);
        startActivity(preferences);
        return true;
      }
    }
);
    item.setAlphabeticShortcut('p');
    item.setIcon(android.R.drawable.ic_menu_preferences);
  }
  return true;
}
Program: 184683
Project: 184683
Buggy source:
public Uri addImage(Context ctx,ContentResolver cr,String title,long dateTaken,Location location,int orientation,String directory,String filename){
  ContentValues values=new ContentValues(7);
  values.put(Images.Media.TITLE,title);
  values.put(Images.Media.DISPLAY_NAME,title);
  values.put(Images.Media.DATE_TAKEN,dateTaken);
  values.put(Images.Media.MIME_TYPE,"String_Node_Str");
  values.put(Images.Media.ORIENTATION,orientation);
  File parentFile=new File(directory);
  String path=parentFile.toString().toLowerCase();
  String name=parentFile.getName();
  if (location != null) {
    values.put(Images.Media.LATITUDE,location.getLatitude());
    values.put(Images.Media.LONGITUDE,location.getLongitude());
  }
  if (directory != null && filename != null) {
    String value=directory + "String_Node_Str" + filename;
    values.put(Images.Media.DATA,value);
  }
  Uri uri=cr.insert(sStorageURI,values);
  String projection[]=new String[]{ImageColumns._ID,Images.Media.DISPLAY_NAME,Images.Media.DATA};
  Cursor c=cr.query(uri,projection,null,null,null);
  if (c.moveToFirst()) {
    String filePath=c.getString(2);
    if (filePath != null) {
      int pos=filePath.lastIndexOf("String_Node_Str");
      if (pos >= 0) {
        filePath=filePath.substring(pos + 1);
        c.updateString(1,filePath);
        c.commitUpdates();
      }
    }
  }
  c.close();
  return uri;
}

Fixed version (ground truth):
public Uri addImage(Context ctx,ContentResolver cr,String title,long dateTaken,Location location,int orientation,String directory,String filename){
  ContentValues values=new ContentValues(7);
  values.put(Images.Media.TITLE,title);
  values.put(Images.Media.DISPLAY_NAME,filename);
  values.put(Images.Media.DATE_TAKEN,dateTaken);
  values.put(Images.Media.MIME_TYPE,"String_Node_Str");
  values.put(Images.Media.ORIENTATION,orientation);
  File parentFile=new File(directory);
  String path=parentFile.toString().toLowerCase();
  String name=parentFile.getName();
  if (location != null) {
    values.put(Images.Media.LATITUDE,location.getLatitude());
    values.put(Images.Media.LONGITUDE,location.getLongitude());
  }
  if (directory != null && filename != null) {
    String value=directory + "String_Node_Str" + filename;
    values.put(Images.Media.DATA,value);
  }
  return cr.insert(sStorageURI,values);
}
Program: 184684
Project: 184684
Buggy source:
public void run(){
  mLayoutComplete=true;
  setImage(mCurrentPosition);
}

Fixed version (ground truth):
public void run(){
  if (mMode == MODE_NORMAL)   return;
  ImageViewTouchBase oldView=mSlideShowImageViews[mSlideShowImageCurrent];
  if (++mSlideShowImageCurrent == mSlideShowImageViews.length) {
    mSlideShowImageCurrent=0;
  }
  ImageViewTouchBase newView=mSlideShowImageViews[mSlideShowImageCurrent];
  newView.setVisibility(View.VISIBLE);
  newView.setImageBitmapResetBase(bitmap,isThumb,isThumb);
  newView.bringToFront();
  int animation=0;
  if (mAnimationIndex == -1) {
    int n=mRandom.nextInt(mSlideShowInAnimation.length);
    animation=n;
  }
 else {
    animation=mAnimationIndex;
  }
  Animation aIn=mSlideShowInAnimation[animation];
  newView.setAnimation(aIn);
  newView.setVisibility(View.VISIBLE);
  aIn.startNow();
  Animation aOut=mSlideShowOutAnimation[animation];
  oldView.setVisibility(View.INVISIBLE);
  oldView.setAnimation(aOut);
  aOut.startNow();
  mCurrentPosition=requestedPos;
  if (mCurrentPosition == mLastSlideShowImage && !firstCall) {
    if (mSlideShowLoop) {
      if (mUseShuffleOrder) {
        generateShuffleOrder();
      }
    }
 else {
      setMode(MODE_NORMAL);
      return;
    }
  }
  if (Config.LOGV)   Log.v(TAG,"String_Node_Str" + mCurrentPosition);
  loadNextImage((mCurrentPosition + 1) % mAllImages.getCount(),mSlideShowInterval,false);
}
Program: 184685
Project: 184685
Buggy source:
public ScrollHandler(Context context,AttributeSet attrs){
  super(context,attrs);
  mScrollerHelper=new Scroller(context);
}

Fixed version (ground truth):
public ScrollHandler(Context context,AttributeSet attrs){
  super(context,attrs);
  mScrollerHelper=new Scroller(context);
  mViewImage=(ViewImage)context;
}
Program: 184686
Project: 184686
Buggy source:
@Override protected void onLayout(boolean changed,int left,int top,int right,int bottom){
  int width=right - left;
  int x=0;
  for (  View v : new View[]{findViewById(R.id.image1),findViewById(R.id.image2),findViewById(R.id.image3)}) {
    v.layout(x,0,x + width,bottom);
    x+=(width + sPadding);
  }
  findViewById(R.id.padding1).layout(width,0,width + sPadding,bottom);
  findViewById(R.id.padding2).layout(width + sPadding + width,0,width + sPadding + width+ sPadding,bottom);
  if (changed) {
    if (mFirstLayoutCompletedCallback != null) {
      mFirstLayoutCompletedCallback.run();
    }
  }
}

Fixed version (ground truth):
@Override protected void onLayout(boolean changed,int left,int top,int right,int bottom){
  int width=right - left;
  int x=0;
  for (  View v : new View[]{findViewById(R.id.image1),findViewById(R.id.image2),findViewById(R.id.image3)}) {
    v.layout(x,0,x + width,bottom);
    x+=(width + sPadding);
  }
  findViewById(R.id.padding1).layout(width,0,width + sPadding,bottom);
  findViewById(R.id.padding2).layout(width + sPadding + width,0,width + sPadding + width+ sPadding,bottom);
  if (changed) {
    mViewImage.mLayoutComplete=true;
    mViewImage.onLayoutChanged();
  }
}
Program: 184687
Project: 184687
Buggy source:
@Override public void onResume(){
  super.onResume();
  init(mSavedUri);
  int count=mAllImages.getCount();
  if (count == 0) {
    finish();
  }
 else   if (count <= mCurrentPosition) {
    mCurrentPosition=count - 1;
  }
  ImageManager.IImage image=mAllImages.getImageAt(mCurrentPosition);
  if (mGetter == null) {
    makeGetter();
  }
  mFirst=true;
  mScroller.setLayoutCompletedCallback(new Runnable(){
    public void run(){
      mLayoutComplete=true;
      setImage(mCurrentPosition);
    }
  }
);
  setImage(mCurrentPosition);
  setOrientation();
}

Fixed version (ground truth):
@Override public void onResume(){
  super.onResume();
  init(mSavedUri);
  int count=mAllImages.getCount();
  if (count == 0) {
    finish();
  }
 else   if (count <= mCurrentPosition) {
    mCurrentPosition=count - 1;
  }
  ImageManager.IImage image=mAllImages.getImageAt(mCurrentPosition);
  if (mGetter == null) {
    makeGetter();
  }
  mFirst=true;
  setImage(mCurrentPosition);
}