nus-yam/ex-repair huggingface dataset:
Program: 184489
Project: 184489
Buggy source:
public void stop(){
  mHandler.removeCallbacks(mLongPressCallback);
  mScroller=null;
  if (mImageBlockManager != null) {
    mImageBlockManager.recycle();
    mImageBlockManager=null;
  }
  mRunning=false;
  mCurrentSelection=SELECT_NONE;
}

Fixed version (ground truth):
public void stop(){
  mHandler.removeCallbacks(mLongPressCallback);
  mScroller=null;
  if (mImageBlockManager != null) {
    mImageBlockManager.recycle();
    mImageBlockManager=null;
  }
  mRunning=false;
  mCurrentSelection=INDEX_NONE;
}
Program: 184490
Project: 184490
Buggy source:
@Override public boolean onDown(MotionEvent e){
  if (!canHandleEvent())   return false;
  if (mScroller != null && !mScroller.isFinished()) {
    mScroller.forceFinished(true);
    return false;
  }
  int pos=computeSelectedIndex(e.getX(),e.getY());
  if (pos >= 0 && pos < mCount) {
    select(pos,true);
  }
 else {
    select(SELECT_NONE,false);
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean onDown(MotionEvent e){
  if (!canHandleEvent())   return false;
  if (mScroller != null && !mScroller.isFinished()) {
    mScroller.forceFinished(true);
    return false;
  }
  int index=computeSelectedIndex(e.getX(),e.getY());
  if (index >= 0 && index < mCount) {
    setSelectedIndex(index);
  }
 else {
    setSelectedIndex(INDEX_NONE);
  }
  return true;
}
Program: 184491
Project: 184491
Buggy source:
@Override public boolean onKeyDown(int keyCode,KeyEvent event){
  if (!canHandleEvent())   return false;
  boolean handled=true;
  int sel=mCurrentSelection;
  boolean pressed=false;
  if (mShowSelection) {
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_RIGHT:
      if (sel != mCount - 1 && (sel % mColumns < mColumns - 1)) {
        sel+=1;
      }
    break;
case KeyEvent.KEYCODE_DPAD_LEFT:
  if (sel > 0 && (sel % mColumns != 0)) {
    sel-=1;
  }
break;
case KeyEvent.KEYCODE_DPAD_UP:
if (sel >= mColumns) {
sel-=mColumns;
}
break;
case KeyEvent.KEYCODE_DPAD_DOWN:
sel=Math.min(mCount - 1,sel + mColumns);
break;
case KeyEvent.KEYCODE_DPAD_CENTER:
pressed=true;
mHandler.postDelayed(mLongPressCallback,ViewConfiguration.getLongPressTimeout());
break;
default :
handled=false;
break;
}
}
 else {
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_RIGHT:
case KeyEvent.KEYCODE_DPAD_LEFT:
case KeyEvent.KEYCODE_DPAD_UP:
case KeyEvent.KEYCODE_DPAD_DOWN:
int startRow=(mScrollY - mSpec.mCellSpacing) / mBlockHeight;
int topPos=startRow * mColumns;
Rect r=getRectForPosition(topPos);
if (r.top < getScrollY()) {
topPos+=mColumns;
}
topPos=Math.min(mCount - 1,topPos);
sel=topPos;
break;
default :
handled=false;
break;
}
}
if (handled) {
select(sel,pressed);
return true;
}
 else {
return super.onKeyDown(keyCode,event);
}
}

Fixed version (ground truth):
@Override public boolean onKeyDown(int keyCode,KeyEvent event){
  if (!canHandleEvent())   return false;
  int sel=mCurrentSelection;
  if (sel != INDEX_NONE) {
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_RIGHT:
      if (sel != mCount - 1 && (sel % mColumns < mColumns - 1)) {
        sel+=1;
      }
    break;
case KeyEvent.KEYCODE_DPAD_LEFT:
  if (sel > 0 && (sel % mColumns != 0)) {
    sel-=1;
  }
break;
case KeyEvent.KEYCODE_DPAD_UP:
if (sel >= mColumns) {
sel-=mColumns;
}
break;
case KeyEvent.KEYCODE_DPAD_DOWN:
sel=Math.min(mCount - 1,sel + mColumns);
break;
case KeyEvent.KEYCODE_DPAD_CENTER:
mCurrentPressState|=CLICKING_FLAG;
mHandler.postDelayed(mLongPressCallback,ViewConfiguration.getLongPressTimeout());
break;
default :
return super.onKeyDown(keyCode,event);
}
}
 else {
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_RIGHT:
case KeyEvent.KEYCODE_DPAD_LEFT:
case KeyEvent.KEYCODE_DPAD_UP:
case KeyEvent.KEYCODE_DPAD_DOWN:
int startRow=(mScrollY - mSpec.mCellSpacing) / mBlockHeight;
int topPos=startRow * mColumns;
Rect r=getRectForPosition(topPos);
if (r.top < getScrollY()) {
topPos+=mColumns;
}
topPos=Math.min(mCount - 1,topPos);
sel=topPos;
break;
default :
return super.onKeyDown(keyCode,event);
}
}
setSelectedIndex(sel);
return true;
}
Program: 184492
Project: 184492
Buggy source:
@Override public boolean onScroll(MotionEvent e1,MotionEvent e2,float distanceX,float distanceY){
  if (!canHandleEvent())   return false;
  select(SELECT_NONE,false);
  scrollBy(0,(int)distanceY);
  invalidate();
  return true;
}

Fixed version (ground truth):
@Override public boolean onScroll(MotionEvent e1,MotionEvent e2,float distanceX,float distanceY){
  if (!canHandleEvent())   return false;
  setSelectedIndex(INDEX_NONE);
  scrollBy(0,(int)distanceY);
  invalidate();
  return true;
}
Program: 184493
Project: 184493
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);
    mListener.onImageClicked(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) {
    mCurrentPressState&=~CLICKING_FLAG;
    invalidate();
    mHandler.removeCallbacks(mLongPressCallback);
    mListener.onImageClicked(mCurrentSelection);
    return true;
  }
  return super.onKeyUp(keyCode,event);
}
Program: 184494
Project: 184494
Buggy source:
private void updateItem(Item item){
  if (item != null) {
    mAdapter.addItem(item);
    mAdapter.updateDisplay();
  }
}

Fixed version (ground truth):
private void updateItem(Item item){
  if (mAdapter.getCount() == 0) {
    hideNoImagesView();
  }
  mAdapter.addItem(item);
  mAdapter.updateDisplay();
}
Program: 184495
Project: 184495
Buggy source:
public void onCreateContextMenu(ContextMenu menu,View v,ContextMenu.ContextMenuInfo menuInfo){
  if (!canHandleEvent())   return;
  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){
        if (!canHandleEvent())         return false;
        onImageClicked(mGvs.getCurrentSelection());
        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,ImageGallery.this,mHandler,mDeletePhotoRunnable,new MenuHelper.MenuInvoker(){
      public void run(      MenuHelper.MenuCallback cb){
        if (!canHandleEvent()) {
          return;
        }
        cb.run(getCurrentImageUri(),getCurrentImage());
      }
    }
);
    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 (!canHandleEvent())   return;
  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){
        if (!canHandleEvent())         return false;
        onImageClicked(mGvs.getCurrentSelection());
        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,ImageGallery.this,mHandler,mDeletePhotoRunnable,new MenuHelper.MenuInvoker(){
      public void run(      MenuHelper.MenuCallback cb){
        if (!canHandleEvent()) {
          return;
        }
        cb.run(getCurrentImageUri(),getCurrentImage());
        rebake(false,ImageManager.isMediaScannerScanning(getContentResolver()));
      }
    }
);
    if (r != null) {
      r.gettingReadyToOpen(menu,getCurrentImage());
    }
    if (isImage) {
      addSlideShowMenu(menu,1000);
    }
  }
}
Program: 184496
Project: 184496
Buggy source:
public void onCreateContextMenu(ContextMenu menu,View v,ContextMenu.ContextMenuInfo menuInfo){
  if (!canHandleEvent())   return;
  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){
        if (!canHandleEvent())         return false;
        onImageClicked(mGvs.getCurrentSelection());
        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,ImageGallery.this,mHandler,mDeletePhotoRunnable,new MenuHelper.MenuInvoker(){
      public void run(      MenuHelper.MenuCallback cb){
        if (!canHandleEvent()) {
          return;
        }
        cb.run(getCurrentImageUri(),getCurrentImage());
      }
    }
);
    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 (!canHandleEvent())   return;
  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){
        if (!canHandleEvent())         return false;
        onImageClicked(mGvs.getCurrentSelection());
        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,ImageGallery.this,mHandler,mDeletePhotoRunnable,new MenuHelper.MenuInvoker(){
      public void run(      MenuHelper.MenuCallback cb){
        if (!canHandleEvent()) {
          return;
        }
        cb.run(getCurrentImageUri(),getCurrentImage());
        rebake(false,ImageManager.isMediaScannerScanning(getContentResolver()));
      }
    }
);
    if (r != null) {
      r.gettingReadyToOpen(menu,getCurrentImage());
    }
    if (isImage) {
      addSlideShowMenu(menu,1000);
    }
  }
}
Program: 184497
Project: 184497
Buggy source:
public void run(){
  mActivity.removeLifeCycleListener(BackgroundJob.this);
  mDialog.dismiss();
}

Fixed version (ground truth):
public void run(){
  try {
    mJob.run();
  }
  finally {
    mHandler.post(mCleanupRunner);
  }
}
Program: 184498
Project: 184498
Buggy source:
public void run(){
  while (true) {
    WorkItem workItem=null;
synchronized (mQueue) {
      if (mDone) {
        break;
      }
      if (!mQueue.isEmpty()) {
        workItem=mQueue.remove(0);
      }
 else {
        long t=IDLE_TIME - (System.nanoTime() - lastWorkTime);
        if (t > 0) {
          try {
            mQueue.wait(t / 1000000);
          }
 catch (          InterruptedException ex) {
          }
          continue;
        }
        if (!mThumbnailChecker.hasMoreThumbnailsToCheck()) {
          try {
            mQueue.wait();
          }
 catch (          InterruptedException ex) {
          }
          continue;
        }
      }
    }
    if (workItem == null) {
      mThumbnailChecker.checkNextThumbnail();
      continue;
    }
    final Bitmap b=workItem.mImage.miniThumbBitmap();
    if (workItem.mOnLoadedRunnable != null) {
      workItem.mOnLoadedRunnable.run(b);
    }
    lastWorkTime=System.nanoTime();
  }
}

Fixed version (ground truth):
public void run(){
  while (true) {
    WorkItem workItem=null;
synchronized (mQueue) {
      if (mDone) {
        break;
      }
      if (!mQueue.isEmpty()) {
        workItem=mQueue.remove(0);
      }
 else {
        if (!mThumbnailChecker.hasMoreThumbnailsToCheck()) {
          try {
            mQueue.wait();
          }
 catch (          InterruptedException ex) {
          }
          continue;
        }
 else {
          long t=IDLE_TIME - (System.nanoTime() - lastWorkTime);
          t=t / 1000000;
          if (t > 0) {
            try {
              mQueue.wait(t);
            }
 catch (            InterruptedException ex) {
            }
            continue;
          }
        }
      }
    }
    if (workItem == null) {
      mThumbnailChecker.checkNextThumbnail();
      continue;
    }
    final Bitmap b=workItem.mImage.miniThumbBitmap();
    if (workItem.mOnLoadedRunnable != null) {
      workItem.mOnLoadedRunnable.run(b);
    }
    lastWorkTime=System.nanoTime();
  }
}
Program: 184499
Project: 184499
Buggy source:
private Uri getCurrentUri(){
  IImage image=mAllImages.getImageAt(mCurrentPosition);
  return image.fullSizeImageUri();
}

Fixed version (ground truth):
private Uri getCurrentUri(){
  if (mAllImages.getCount() == 0)   return null;
  IImage image=mAllImages.getImageAt(mCurrentPosition);
  return image.fullSizeImageUri();
}
Program: 184500
Project: 184500
Buggy source:
private Uri getCurrentUri(){
  IImage image=mAllImages.getImageAt(mCurrentPosition);
  return image.fullSizeImageUri();
}

Fixed version (ground truth):
private Uri getCurrentUri(){
  if (mAllImages.getCount() == 0)   return null;
  IImage image=mAllImages.getImageAt(mCurrentPosition);
  return image.fullSizeImageUri();
}
Program: 184501
Project: 184501
Buggy source:
public void run(){
  while (true) {
    WorkItem workItem=null;
synchronized (mQueue) {
      if (mDone) {
        break;
      }
      if (!mQueue.isEmpty()) {
        workItem=mQueue.remove(0);
      }
 else {
        long t=IDLE_TIME - (System.nanoTime() - lastWorkTime);
        if (t > 0) {
          try {
            mQueue.wait(t / 1000000);
          }
 catch (          InterruptedException ex) {
          }
          continue;
        }
        if (!mThumbnailChecker.hasMoreThumbnailsToCheck()) {
          try {
            mQueue.wait();
          }
 catch (          InterruptedException ex) {
          }
          continue;
        }
      }
    }
    if (workItem == null) {
      mThumbnailChecker.checkNextThumbnail();
      continue;
    }
    final Bitmap b=workItem.mImage.miniThumbBitmap();
    if (workItem.mOnLoadedRunnable != null) {
      workItem.mOnLoadedRunnable.run(b);
    }
    lastWorkTime=System.nanoTime();
  }
}

Fixed version (ground truth):
public void run(){
  while (true) {
    WorkItem workItem=null;
synchronized (mQueue) {
      if (mDone) {
        break;
      }
      if (!mQueue.isEmpty()) {
        workItem=mQueue.remove(0);
      }
 else {
        if (!mThumbnailChecker.hasMoreThumbnailsToCheck()) {
          try {
            mQueue.wait();
          }
 catch (          InterruptedException ex) {
          }
          continue;
        }
 else {
          long t=IDLE_TIME - (System.nanoTime() - lastWorkTime);
          t=t / 1000000;
          if (t > 0) {
            try {
              mQueue.wait(t);
            }
 catch (            InterruptedException ex) {
            }
            continue;
          }
        }
      }
    }
    if (workItem == null) {
      mThumbnailChecker.checkNextThumbnail();
      continue;
    }
    final Bitmap b=workItem.mImage.miniThumbBitmap();
    if (workItem.mOnLoadedRunnable != null) {
      workItem.mOnLoadedRunnable.run(b);
    }
    lastWorkTime=System.nanoTime();
  }
}
Program: 184502
Project: 184502
Buggy source:
private Uri getCurrentUri(){
  IImage image=mAllImages.getImageAt(mCurrentPosition);
  return image.fullSizeImageUri();
}

Fixed version (ground truth):
private Uri getCurrentUri(){
  if (mAllImages.getCount() == 0)   return null;
  IImage image=mAllImages.getImageAt(mCurrentPosition);
  return image.fullSizeImageUri();
}
Program: 184503
Project: 184503
Buggy source:
private Uri getCurrentUri(){
  IImage image=mAllImages.getImageAt(mCurrentPosition);
  return image.fullSizeImageUri();
}

Fixed version (ground truth):
private Uri getCurrentUri(){
  if (mAllImages.getCount() == 0)   return null;
  IImage image=mAllImages.getImageAt(mCurrentPosition);
  return image.fullSizeImageUri();
}
Program: 184504
Project: 184504
Buggy source:
@Override protected void onActivityResult(int requestCode,int resultCode,Intent data){
switch (requestCode) {
case MenuHelper.RESULT_COMMON_MENU_CROP:
    if (resultCode == RESULT_OK) {
      mSavedUri=Uri.parse(data.getAction());
      mAllImages=null;
    }
  break;
}
}

Fixed version (ground truth):
@Override protected void onActivityResult(int requestCode,int resultCode,Intent data){
switch (requestCode) {
case MenuHelper.RESULT_COMMON_MENU_CROP:
    if (resultCode == RESULT_OK) {
      mSavedUri=Uri.parse(data.getAction());
    }
  break;
}
}
Program: 184505
Project: 184505
Buggy source:
@Override public void onStart(){
  super.onStart();
  init(mSavedUri,mAllImages);
  if (mCameraReviewMode) {
    updateLastImage();
  }
  int count=mAllImages.getCount();
  if (count == 0) {
    finish();
  }
 else   if (count <= mCurrentPosition) {
    mCurrentPosition=count - 1;
  }
  if (mGetter == null) {
    makeGetter();
  }
  if (mMode == MODE_SLIDESHOW) {
    loadNextImage(mCurrentPosition,0,true);
  }
 else {
    setImage(mCurrentPosition);
  }
}

Fixed version (ground truth):
@Override public void onStart(){
  super.onStart();
  mPaused=false;
  init(mSavedUri,mAllImagesState);
  if (mCameraReviewMode) {
    updateLastImage();
  }
  int count=mAllImages.getCount();
  if (count == 0) {
    finish();
  }
 else   if (count <= mCurrentPosition) {
    mCurrentPosition=count - 1;
  }
  if (mGetter == null) {
    makeGetter();
  }
  if (mMode == MODE_SLIDESHOW) {
    loadNextImage(mCurrentPosition,0,true);
  }
 else {
    setImage(mCurrentPosition);
  }
}
Program: 184506
Project: 184506
Buggy source:
@Override public void onStop(){
  super.onStop();
  mGetter.cancelCurrent();
  mGetter.stop();
  mGetter=null;
  setMode(MODE_NORMAL);
  mHandler.removeAllGetterCallbacks();
  mSavedUri=getCurrentUri();
  mAllImages.deactivate();
  mDismissOnScreenControlsRunnable.run();
  if (mDismissOnScreenControlsRunnable != null) {
    mHandler.removeCallbacks(mDismissOnScreenControlsRunnable);
  }
  mImageView.clear();
  mCache.clear();
  for (  ImageViewTouchBase iv : mSlideShowImageViews) {
    iv.clear();
  }
}

Fixed version (ground truth):
@Override public void onStop(){
  super.onStop();
  mPaused=true;
  mGetter.cancelCurrent();
  mGetter.stop();
  mGetter=null;
  setMode(MODE_NORMAL);
  mHandler.removeAllGetterCallbacks();
  mSavedUri=getCurrentUri();
  mAllImages.deactivate();
  mAllImages.close();
  mAllImages=null;
  mDismissOnScreenControlsRunnable.run();
  if (mDismissOnScreenControlsRunnable != null) {
    mHandler.removeCallbacks(mDismissOnScreenControlsRunnable);
  }
  mImageView.clear();
  mCache.clear();
  for (  ImageViewTouchBase iv : mSlideShowImageViews) {
    iv.clear();
  }
}
Program: 184507
Project: 184507
Buggy source:
private boolean init(Uri uri,IImageList imageList){
  if (uri == null)   return false;
  mAllImages=(imageList == null) ? buildImageListFromUri(uri) : imageList;
  mAllImages.open(getContentResolver());
  IImage image=mAllImages.getImageForUri(uri);
  if (image == null)   return false;
  mCurrentPosition=mAllImages.getImageIndex(image);
  mLastSlideShowImage=mCurrentPosition;
  return true;
}

Fixed version (ground truth):
private boolean init(Uri uri,IImageList imageList){
  if (uri == null)   return false;
  mAllImagesState=(imageList == null) ? buildImageListFromUri(uri) : imageList;
  mAllImages=mAllImagesState;
  mAllImages.open(getContentResolver());
  IImage image=mAllImages.getImageForUri(uri);
  if (image == null)   return false;
  mCurrentPosition=mAllImages.getImageIndex(image);
  mLastSlideShowImage=mCurrentPosition;
  return true;
}
Program: 184508
Project: 184508
Buggy source:
@Override public boolean onPrepareOptionsMenu(Menu menu){
  super.onPrepareOptionsMenu(menu);
  setMode(MODE_NORMAL);
  if (mImageMenuRunnable != null) {
    mImageMenuRunnable.gettingReadyToOpen(menu,mAllImages.getImageAt(mCurrentPosition));
  }
  Uri uri=mAllImages.getImageAt(mCurrentPosition).fullSizeImageUri();
  MenuHelper.enableShareMenuItem(menu,!MenuHelper.isMMSUri(uri));
  return true;
}

Fixed version (ground truth):
@Override public boolean onPrepareOptionsMenu(Menu menu){
  super.onPrepareOptionsMenu(menu);
  if (mPaused)   return false;
  setMode(MODE_NORMAL);
  if (mImageMenuRunnable != null) {
    mImageMenuRunnable.gettingReadyToOpen(menu,mAllImages.getImageAt(mCurrentPosition));
  }
  Uri uri=mAllImages.getImageAt(mCurrentPosition).fullSizeImageUri();
  MenuHelper.enableShareMenuItem(menu,!MenuHelper.isMMSUri(uri));
  return true;
}
Program: 184509
Project: 184509
Buggy source:
public IImage getImageForUri(Uri uri){
  long matchId;
  try {
    matchId=ContentUris.parseId(uri);
  }
 catch (  NumberFormatException ex) {
    Log.i(TAG,"String_Node_Str" + uri,ex);
    return null;
  }
  Cursor cursor=getCursor();
synchronized (cursor) {
    cursor.moveToPosition(-1);
    for (int i=0; cursor.moveToNext(); ++i) {
      if (getImageId(cursor) == matchId) {
        BaseImage image=mCache.get(i);
        if (image == null) {
          image=loadImageFromCursor(cursor);
          mCache.put(i,image);
        }
        return image;
      }
    }
    return null;
  }
}

Fixed version (ground truth):
public IImage getImageForUri(Uri uri){
  if (!isChildImageUri(uri))   return null;
  long matchId;
  try {
    matchId=ContentUris.parseId(uri);
  }
 catch (  NumberFormatException ex) {
    Log.i(TAG,"String_Node_Str" + uri,ex);
    return null;
  }
  Cursor cursor=getCursor();
synchronized (cursor) {
    cursor.moveToPosition(-1);
    for (int i=0; cursor.moveToNext(); ++i) {
      if (getImageId(cursor) == matchId) {
        BaseImage image=mCache.get(i);
        if (image == null) {
          image=loadImageFromCursor(cursor);
          mCache.put(i,image);
        }
        return image;
      }
    }
    return null;
  }
}
Program: 184510
Project: 184510
Buggy source:
public void open(ContentResolver resolver){
  mContentResolver=resolver;
  mCursor=createCursor();
}

Fixed version (ground truth):
public void open(ContentResolver resolver){
  mContentResolver=resolver;
  mCursor=createCursor();
  mCache.clear();
}
Program: 184511
Project: 184511
Buggy source:
public void open(ContentResolver cr){
  for (int i=0, n=mSubList.length; i < n; ++i) {
    IImageList list=mSubList[i];
    if (list instanceof BaseImageList) {
      ((BaseImageList)list).open(cr);
    }
    MergeSlot slot=new MergeSlot(list,i);
    if (slot.next())     mQueue.add(slot);
  }
}

Fixed version (ground truth):
public void open(ContentResolver cr){
  mSkipList=new long[16];
  mSkipListSize=0;
  mSkipCounts=new int[mSubList.length];
  mLastListIndex=-1;
  mQueue.clear();
  for (int i=0, n=mSubList.length; i < n; ++i) {
    IImageList list=mSubList[i];
    if (list instanceof BaseImageList) {
      ((BaseImageList)list).open(cr);
    }
    MergeSlot slot=new MergeSlot(list,i);
    if (slot.next())     mQueue.add(slot);
  }
}
Program: 184512
Project: 184512
Buggy source:
public void onClick(View v){
switch (v.getId()) {
case R.id.btn_delete:
    MenuHelper.deletePhoto(this,mDeletePhotoRunnable);
  break;
case R.id.btn_play:
startPlayVideoActivity();
break;
case R.id.btn_share:
{
IImage image=mAllImages.getImageAt(mCurrentPosition);
if (MenuHelper.isMMSUri(image.fullSizeImageUri())) {
return;
}
startShareMediaActivity(image);
break;
}
case R.id.btn_set_as:
{
Uri u=mAllImages.getImageAt(mCurrentPosition).fullSizeImageUri();
Intent intent=new Intent(Intent.ACTION_ATTACH_DATA,u);
try {
startActivity(Intent.createChooser(intent,getText(R.string.setImage)));
}
 catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this,R.string.no_way_to_share_video,Toast.LENGTH_SHORT).show();
}
break;
}
case R.id.btn_done:
finish();
break;
case R.id.next_image:
moveNextOrPrevious(1);
break;
case R.id.prev_image:
moveNextOrPrevious(-1);
break;
}
}

Fixed version (ground truth):
public void onClick(View v){
switch (v.getId()) {
case R.id.btn_delete:
    MenuHelper.deleteImage(this,mDeletePhotoRunnable,mAllImages.getImageAt(mCurrentPosition));
  break;
case R.id.btn_play:
startPlayVideoActivity();
break;
case R.id.btn_share:
{
IImage image=mAllImages.getImageAt(mCurrentPosition);
if (MenuHelper.isMMSUri(image.fullSizeImageUri())) {
return;
}
startShareMediaActivity(image);
break;
}
case R.id.btn_set_as:
{
Uri u=mAllImages.getImageAt(mCurrentPosition).fullSizeImageUri();
Intent intent=new Intent(Intent.ACTION_ATTACH_DATA,u);
try {
startActivity(Intent.createChooser(intent,getText(R.string.setImage)));
}
 catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this,R.string.no_way_to_share_video,Toast.LENGTH_SHORT).show();
}
break;
}
case R.id.btn_done:
finish();
break;
case R.id.next_image:
moveNextOrPrevious(1);
break;
case R.id.prev_image:
moveNextOrPrevious(-1);
break;
}
}
Program: 184513
Project: 184513
Buggy source:
public void onClick(View v){
switch (v.getId()) {
case R.id.btn_delete:
    MenuHelper.deletePhoto(this,mDeletePhotoRunnable);
  break;
case R.id.btn_play:
startPlayVideoActivity();
break;
case R.id.btn_share:
{
IImage image=mAllImages.getImageAt(mCurrentPosition);
if (MenuHelper.isMMSUri(image.fullSizeImageUri())) {
return;
}
startShareMediaActivity(image);
break;
}
case R.id.btn_set_as:
{
Uri u=mAllImages.getImageAt(mCurrentPosition).fullSizeImageUri();
Intent intent=new Intent(Intent.ACTION_ATTACH_DATA,u);
try {
startActivity(Intent.createChooser(intent,getText(R.string.setImage)));
}
 catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this,R.string.no_way_to_share_video,Toast.LENGTH_SHORT).show();
}
break;
}
case R.id.btn_done:
finish();
break;
case R.id.next_image:
moveNextOrPrevious(1);
break;
case R.id.prev_image:
moveNextOrPrevious(-1);
break;
}
}

Fixed version (ground truth):
public void onClick(View v){
switch (v.getId()) {
case R.id.btn_delete:
    MenuHelper.deleteImage(this,mDeletePhotoRunnable,mAllImages.getImageAt(mCurrentPosition));
  break;
case R.id.btn_play:
startPlayVideoActivity();
break;
case R.id.btn_share:
{
IImage image=mAllImages.getImageAt(mCurrentPosition);
if (MenuHelper.isMMSUri(image.fullSizeImageUri())) {
return;
}
startShareMediaActivity(image);
break;
}
case R.id.btn_set_as:
{
Uri u=mAllImages.getImageAt(mCurrentPosition).fullSizeImageUri();
Intent intent=new Intent(Intent.ACTION_ATTACH_DATA,u);
try {
startActivity(Intent.createChooser(intent,getText(R.string.setImage)));
}
 catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this,R.string.no_way_to_share_video,Toast.LENGTH_SHORT).show();
}
break;
}
case R.id.btn_done:
finish();
break;
case R.id.next_image:
moveNextOrPrevious(1);
break;
case R.id.prev_image:
moveNextOrPrevious(-1);
break;
}
}
Program: 184514
Project: 184514
Buggy source:
@Override protected void onActivityResult(int requestCode,int resultCode,Intent data){
switch (requestCode) {
case MenuHelper.RESULT_COMMON_MENU_CROP:
    if (resultCode == RESULT_OK) {
      mSavedUri=Uri.parse(data.getAction());
    }
  break;
}
}

Fixed version (ground truth):
@Override protected void onActivityResult(int requestCode,int resultCode,Intent data){
switch (requestCode) {
case MenuHelper.RESULT_COMMON_MENU_CROP:
    if (resultCode == RESULT_OK) {
      mSavedUri=Uri.parse(data.getAction());
      mAllImages=null;
    }
  break;
}
}
Program: 184516
Project: 184516
Buggy source:
void initializeSecondTime(){
  mOrientationListener.enable();
  readPreference();
  if (mRecordLocation)   startReceivingLocationUpdates();
  installIntentFilter();
  initializeFocusTone();
}

Fixed version (ground truth):
void initializeSecondTime(){
  mOrientationListener.enable();
  readPreference();
  if (mRecordLocation)   startReceivingLocationUpdates();
  installIntentFilter();
  initializeFocusTone();
  if (!mIsImageCaptureIntent) {
    updateThumbnailButton();
  }
}
Program: 184517
Project: 184517
Buggy source:
public void surfaceChanged(SurfaceHolder holder,int format,int w,int h){
  mSurfaceHolder=holder;
  mViewFinderWidth=w;
  mViewFinderHeight=h;
  if (mPausing)   return;
  mSurfaceView.setVisibility(View.VISIBLE);
  if (mStatus == SNAPSHOT_IN_PROGRESS)   return;
  startPreview();
  if (!mFirstTimeInitialized) {
    mHandler.sendEmptyMessage(FIRST_TIME_INIT);
  }
}

Fixed version (ground truth):
public void surfaceChanged(SurfaceHolder holder,int format,int w,int h){
  mSurfaceHolder=holder;
  mViewFinderWidth=w;
  mViewFinderHeight=h;
  if (mPausing)   return;
  mSurfaceView.setVisibility(View.VISIBLE);
  if (mStatus == SNAPSHOT_IN_PROGRESS)   return;
  startPreview();
  if (!mFirstTimeInitialized) {
    mHandler.sendEmptyMessage(FIRST_TIME_INIT);
  }
 else {
    initializeSecondTime();
  }
}
Program: 184518
Project: 184518
Buggy source:
@Override public void handleMessage(Message msg){
switch (msg.what) {
case RESTART_PREVIEW:
{
      restartPreview();
      break;
    }
case STORE_IMAGE_DONE:
{
    if (!mIsImageCaptureIntent) {
      setLastPictureThumb((byte[])msg.obj,mImageCapture.getLastCaptureUri());
      if (!mThumbController.isUriValid()) {
        updateLastImage();
      }
      mThumbController.updateDisplayIfNeeded();
    }
 else {
      showPostCaptureAlert();
    }
    mStoreImageThread=null;
    break;
  }
case CLEAR_SCREEN_DELAY:
{
  getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
  break;
}
case FIRST_TIME_INIT:
{
initializeFirstTime();
break;
}
}
}

Fixed version (ground truth):
@Override public void handleMessage(Message msg){
switch (msg.what) {
case RESTART_PREVIEW:
{
      restartPreview();
      break;
    }
case STORE_IMAGE_DONE:
{
    if (!mIsImageCaptureIntent) {
      setLastPictureThumb((byte[])msg.obj,mImageCapture.getLastCaptureUri());
      updateThumbnailButton();
    }
 else {
      showPostCaptureAlert();
    }
    mStoreImageThread=null;
    break;
  }
case CLEAR_SCREEN_DELAY:
{
  getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
  break;
}
case FIRST_TIME_INIT:
{
initializeFirstTime();
break;
}
}
}
Program: 184519
Project: 184519
Buggy source:
public V get(K key){
  V value=mLruMap.get(key);
  if (value != null)   return value;
  WeakReference<V> ref=mWeakMap.get(key);
  value=ref == null ? null : ref.get();
  if (value == null && ref != null) {
    mWeakMap.remove(key);
  }
  return value;
}

Fixed version (ground truth):
public synchronized V get(K key){
  V value=mLruMap.get(key);
  if (value != null)   return value;
  WeakReference<V> ref=mWeakMap.get(key);
  value=ref == null ? null : ref.get();
  if (value == null && ref != null) {
    mWeakMap.remove(key);
  }
  return value;
}
Program: 184520
Project: 184520
Buggy source:
public void clear(){
  mLruMap.clear();
  mWeakMap.clear();
}

Fixed version (ground truth):
public synchronized void clear(){
  mLruMap.clear();
  mWeakMap.clear();
}
Program: 184521
Project: 184521
Buggy source:
public V put(K key,V value){
  if (++mAddBeforeSweep > MAXIMUM_ADD_BEFORE_SWEEP) {
    mAddBeforeSweep=0;
    Iterator<Map.Entry<K,WeakReference<V>>> iter=mWeakMap.entrySet().iterator();
    while (iter.hasNext()) {
      Map.Entry<K,WeakReference<V>> entry=iter.next();
      if (entry.getValue().get() == null)       iter.remove();
    }
  }
  mLruMap.put(key,value);
  WeakReference<V> ref=mWeakMap.put(key,new WeakReference<V>(value));
  return ref == null ? null : ref.get();
}

Fixed version (ground truth):
public synchronized V put(K key,V value){
  if (++mAddBeforeSweep > MAXIMUM_ADD_BEFORE_SWEEP) {
    mAddBeforeSweep=0;
    Iterator<Map.Entry<K,WeakReference<V>>> iter=mWeakMap.entrySet().iterator();
    while (iter.hasNext()) {
      Map.Entry<K,WeakReference<V>> entry=iter.next();
      if (entry.getValue().get() == null)       iter.remove();
    }
  }
  mLruMap.put(key,value);
  WeakReference<V> ref=mWeakMap.put(key,new WeakReference<V>(value));
  return ref == null ? null : ref.get();
}
Program: 184522
Project: 184522
Buggy source:
public void onShutterButtonClick(ShutterButton button){
  if (mPausing) {
    return;
  }
switch (button.getId()) {
case R.id.camera_button:
    if (mStoreImageThread == null) {
      doSnap();
    }
 else {
      Toast.makeText(Camera.this,getResources().getString(R.string.wait),Toast.LENGTH_SHORT);
    }
  break;
}
}

Fixed version (ground truth):
public void onShutterButtonClick(ShutterButton button){
  if (mPausing) {
    return;
  }
switch (button.getId()) {
case R.id.camera_button:
    if (mIsImageCaptureIntent && mPostCaptureAlert.getVisibility() == View.VISIBLE) {
      hidePostCaptureAlert();
      restartPreview();
    }
 else     if (mStoreImageThread == null) {
      doSnap();
    }
 else {
      Toast.makeText(Camera.this,getResources().getString(R.string.wait),Toast.LENGTH_SHORT);
    }
  break;
}
}
Program: 184523
Project: 184523
Buggy source:
public void surfaceCreated(SurfaceHolder holder){
  mSurfaceHolder=holder;
}

Fixed version (ground truth):
public void surfaceCreated(SurfaceHolder holder){
}
Program: 184524
Project: 184524
Buggy source:
public void onPictureTaken(final byte[] jpegData,final android.hardware.Camera camera){
  if (mPausing) {
    return;
  }
  mJpegPictureCallbackTime=System.currentTimeMillis();
  mRawPictureAndJpegPictureCallbackTime=mJpegPictureCallbackTime - mRawPictureCallbackTime;
  Log.v(TAG,"String_Node_Str" + mRawPictureAndJpegPictureCallbackTime + "String_Node_Str");
  if (jpegData != null) {
    mStoreImageThread=new Thread(){
      public void run(){
        mImageCapture.storeImage(jpegData,camera,mLocation);
      }
    }
;
    mStoreImageThread.start();
  }
  mStatus=SNAPSHOT_COMPLETED;
  if (mKeepAndRestartPreview) {
    long delay=1500 - (System.currentTimeMillis() - mRawPictureCallbackTime);
    mHandler.sendEmptyMessageDelayed(RESTART_PREVIEW,Math.max(delay,0));
  }
}

Fixed version (ground truth):
public void onPictureTaken(final byte[] jpegData,final android.hardware.Camera camera){
  if (mPausing) {
    return;
  }
  mJpegPictureCallbackTime=System.currentTimeMillis();
  mRawPictureAndJpegPictureCallbackTime=mJpegPictureCallbackTime - mRawPictureCallbackTime;
  Log.v(TAG,"String_Node_Str" + mRawPictureAndJpegPictureCallbackTime + "String_Node_Str");
  if (jpegData != null) {
    mStoreImageThread=new Thread(){
      public void run(){
        mImageCapture.storeImage(jpegData,camera,mLocation);
      }
    }
;
    mStoreImageThread.start();
  }
  if (!mIsImageCaptureIntent) {
    long delay=1500 - (System.currentTimeMillis() - mRawPictureCallbackTime);
    mHandler.sendEmptyMessageDelayed(RESTART_PREVIEW,Math.max(delay,0));
  }
}
Program: 184525
Project: 184525
Buggy source:
@Override public void onResume(){
  super.onResume();
  mPausing=false;
  mJpegPictureCallbackTime=0;
  mImageCapture=new ImageCapture();
  if (mPendingFirstTimeInit) {
    mHandler.sendEmptyMessage(FIRST_TIME_INIT);
    mPendingFirstTimeInit=false;
  }
 else   if (mFirstTimeInitialized) {
    mSurfaceView.setAspectRatio(VideoPreview.DONT_CARE);
    setViewFinder(mOriginalViewFinderWidth,mOriginalViewFinderHeight);
    mStatus=IDLE;
    initializeSecondTime();
  }
  mHandler.sendEmptyMessageDelayed(CLEAR_SCREEN_DELAY,SCREEN_DELAY);
}

Fixed version (ground truth):
@Override public void onResume(){
  super.onResume();
  mPausing=false;
  mJpegPictureCallbackTime=0;
  mImageCapture=new ImageCapture();
  if (mSurfaceHolder != null) {
    mSurfaceView.setAspectRatio(VideoPreview.DONT_CARE);
    startPreview();
    if (!mFirstTimeInitialized) {
      mHandler.sendEmptyMessage(FIRST_TIME_INIT);
    }
 else {
      initializeSecondTime();
    }
  }
  mHandler.sendEmptyMessageDelayed(CLEAR_SCREEN_DELAY,SCREEN_DELAY);
}
Program: 184526
Project: 184526
Buggy source:
public void storeImage(final byte[] data,android.hardware.Camera camera,Location loc){
  boolean captureOnly=mIsImageCaptureIntent;
  Message msg=mHandler.obtainMessage(STORE_IMAGE_DONE);
  if (!captureOnly) {
    storeImage(data,loc);
    sendBroadcast(new Intent("String_Node_Str",mLastContentUri));
    msg.obj=data;
  }
 else {
    BitmapFactory.Options options=new BitmapFactory.Options();
    options.inSampleSize=4;
    mCaptureOnlyBitmap=BitmapFactory.decodeByteArray(data,0,data.length,options);
    cancelAutomaticPreviewRestart();
  }
  mHandler.sendMessage(msg);
}

Fixed version (ground truth):
public void storeImage(final byte[] data,android.hardware.Camera camera,Location loc){
  Message msg=mHandler.obtainMessage(STORE_IMAGE_DONE);
  if (!mIsImageCaptureIntent) {
    storeImage(data,loc);
    sendBroadcast(new Intent("String_Node_Str",mLastContentUri));
    msg.obj=data;
  }
 else {
    BitmapFactory.Options options=new BitmapFactory.Options();
    options.inSampleSize=4;
    mCaptureOnlyBitmap=BitmapFactory.decodeByteArray(data,0,data.length,options);
  }
  mHandler.sendMessage(msg);
}
Program: 184527
Project: 184527
Buggy source:
private void restartPreview(){
  VideoPreview surfaceView=mSurfaceView;
  surfaceView.setAspectRatio(VideoPreview.DONT_CARE);
  setViewFinder(mOriginalViewFinderWidth,mOriginalViewFinderHeight);
  mStatus=IDLE;
  calculatePicturesRemaining();
}

Fixed version (ground truth):
private void restartPreview(){
  mSurfaceView.setAspectRatio(VideoPreview.DONT_CARE);
  startPreview();
  calculatePicturesRemaining();
}
Program: 184528
Project: 184528
Buggy source:
@Override protected void onPause(){
  mPausing=true;
  stopPreview();
  closeCamera();
  waitForStoreImageThread();
  if (mFirstTimeInitialized) {
    mOrientationListener.disable();
    mGpsIndicator.setVisibility(View.INVISIBLE);
    if (!mIsImageCaptureIntent) {
      mThumbController.storeData(ImageManager.getLastImageThumbPath());
    }
    hidePostCaptureAlert();
  }
  if (mDidRegister) {
    unregisterReceiver(mReceiver);
    mDidRegister=false;
  }
  stopReceivingLocationUpdates();
  if (mFocusToneGenerator != null) {
    mFocusToneGenerator.release();
    mFocusToneGenerator=null;
  }
  if (mStorageHint != null) {
    mStorageHint.cancel();
    mStorageHint=null;
  }
  mImageCapture.clearLastBitmap();
  mImageCapture=null;
  if (mZoomButtons != null) {
    mZoomButtons.setVisible(false);
  }
  mHandler.removeMessages(CLEAR_SCREEN_DELAY);
  mHandler.removeMessages(RESTART_PREVIEW);
  mHandler.removeMessages(STORE_IMAGE_DONE);
  if (mHandler.hasMessages(FIRST_TIME_INIT)) {
    mHandler.removeMessages(FIRST_TIME_INIT);
    mPendingFirstTimeInit=true;
  }
  super.onPause();
}

Fixed version (ground truth):
@Override protected void onPause(){
  mPausing=true;
  stopPreview();
  closeCamera();
  waitForStoreImageThread();
  if (mFirstTimeInitialized) {
    mOrientationListener.disable();
    mGpsIndicator.setVisibility(View.INVISIBLE);
    if (!mIsImageCaptureIntent) {
      mThumbController.storeData(ImageManager.getLastImageThumbPath());
    }
    hidePostCaptureAlert();
  }
  if (mDidRegister) {
    unregisterReceiver(mReceiver);
    mDidRegister=false;
  }
  stopReceivingLocationUpdates();
  if (mFocusToneGenerator != null) {
    mFocusToneGenerator.release();
    mFocusToneGenerator=null;
  }
  if (mStorageHint != null) {
    mStorageHint.cancel();
    mStorageHint=null;
  }
  mImageCapture.clearLastBitmap();
  mImageCapture=null;
  if (mZoomButtons != null) {
    mZoomButtons.setVisible(false);
  }
  mHandler.removeMessages(CLEAR_SCREEN_DELAY);
  mHandler.removeMessages(RESTART_PREVIEW);
  mHandler.removeMessages(FIRST_TIME_INIT);
  mHandler.removeMessages(STORE_IMAGE_DONE);
  super.onPause();
}
Program: 184529
Project: 184529
Buggy source:
public void onSnap(){
  if (mPausing) {
    return;
  }
  mCaptureStartTime=System.currentTimeMillis();
  if (mStatus == SNAPSHOT_IN_PROGRESS || mStatus == SNAPSHOT_COMPLETED) {
    mKeepAndRestartPreview=true;
    mHandler.sendEmptyMessage(RESTART_PREVIEW);
    return;
  }
  if (mPicturesRemaining < 1) {
    updateStorageHint(mPicturesRemaining);
    return;
  }
  mStatus=SNAPSHOT_IN_PROGRESS;
  mKeepAndRestartPreview=true;
  mImageCapture.initiate();
}

Fixed version (ground truth):
public void onSnap(){
  if (mPausing || mStatus == SNAPSHOT_IN_PROGRESS) {
    return;
  }
  mCaptureStartTime=System.currentTimeMillis();
  if (mPicturesRemaining < 1) {
    updateStorageHint(mPicturesRemaining);
    return;
  }
  mStatus=SNAPSHOT_IN_PROGRESS;
  mImageCapture.initiate();
}
Program: 184530
Project: 184530
Buggy source:
@Override public boolean onPrepareOptionsMenu(Menu menu){
  super.onPrepareOptionsMenu(menu);
  for (int i=1; i <= MenuHelper.MENU_ITEM_MAX; i++) {
    if (i != MenuHelper.GENERIC_ITEM) {
      menu.setGroupVisible(i,false);
    }
  }
  if (mStatus == SNAPSHOT_IN_PROGRESS || mStatus == SNAPSHOT_COMPLETED) {
    menu.setGroupVisible(MenuHelper.IMAGE_SAVING_ITEM,true);
    mImageSavingItem=true;
  }
 else {
    menu.setGroupVisible(MenuHelper.IMAGE_MODE_ITEM,true);
    mImageSavingItem=false;
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean onPrepareOptionsMenu(Menu menu){
  super.onPrepareOptionsMenu(menu);
  for (int i=1; i <= MenuHelper.MENU_ITEM_MAX; i++) {
    if (i != MenuHelper.GENERIC_ITEM) {
      menu.setGroupVisible(i,false);
    }
  }
  if (mStatus == SNAPSHOT_IN_PROGRESS) {
    menu.setGroupVisible(MenuHelper.IMAGE_SAVING_ITEM,true);
    mImageSavingItem=true;
  }
 else {
    menu.setGroupVisible(MenuHelper.IMAGE_MODE_ITEM,true);
    mImageSavingItem=false;
  }
  return true;
}
Program: 184531
Project: 184531
Buggy source:
public void surfaceChanged(SurfaceHolder holder,int format,int w,int h){
  mSurfaceView.setVisibility(View.VISIBLE);
  setViewFinder(w,h);
  boolean creating=holder.isCreating();
  if (creating && !mFirstTimeInitialized) {
    mHandler.sendEmptyMessage(FIRST_TIME_INIT);
  }
}

Fixed version (ground truth):
public void surfaceChanged(SurfaceHolder holder,int format,int w,int h){
  mSurfaceHolder=holder;
  mViewFinderWidth=w;
  mViewFinderHeight=h;
  if (mPausing)   return;
  mSurfaceView.setVisibility(View.VISIBLE);
  if (mStatus == SNAPSHOT_IN_PROGRESS)   return;
  startPreview();
  if (!mFirstTimeInitialized) {
    mHandler.sendEmptyMessage(FIRST_TIME_INIT);
  }
}
Program: 184532
Project: 184532
Buggy source:
@Override public void handleMessage(Message msg){
switch (msg.what) {
case RESTART_PREVIEW:
{
      if (mStatus == SNAPSHOT_IN_PROGRESS) {
        mHandler.sendEmptyMessageDelayed(RESTART_PREVIEW,100);
      }
 else       if (mStatus == SNAPSHOT_COMPLETED) {
        mImageCapture.dismissFreezeFrame();
        hidePostCaptureAlert();
      }
      break;
    }
case STORE_IMAGE_DONE:
{
    if (!mIsImageCaptureIntent) {
      setLastPictureThumb((byte[])msg.obj,mImageCapture.getLastCaptureUri());
      if (!mThumbController.isUriValid()) {
        updateLastImage();
      }
      mThumbController.updateDisplayIfNeeded();
    }
 else {
      showPostCaptureAlert();
    }
    mStoreImageThread=null;
    break;
  }
case CLEAR_SCREEN_DELAY:
{
  getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
  break;
}
case FIRST_TIME_INIT:
{
initializeFirstTime();
break;
}
}
}

Fixed version (ground truth):
@Override public void handleMessage(Message msg){
switch (msg.what) {
case RESTART_PREVIEW:
{
      restartPreview();
      break;
    }
case STORE_IMAGE_DONE:
{
    if (!mIsImageCaptureIntent) {
      setLastPictureThumb((byte[])msg.obj,mImageCapture.getLastCaptureUri());
      if (!mThumbController.isUriValid()) {
        updateLastImage();
      }
      mThumbController.updateDisplayIfNeeded();
    }
 else {
      showPostCaptureAlert();
    }
    mStoreImageThread=null;
    break;
  }
case CLEAR_SCREEN_DELAY:
{
  getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
  break;
}
case FIRST_TIME_INIT:
{
initializeFirstTime();
break;
}
}
}
Program: 184533
Project: 184533
Buggy source:
public IImage getImageForUri(Uri uri){
  long matchId;
  try {
    matchId=ContentUris.parseId(uri);
  }
 catch (  NumberFormatException ex) {
    Log.i(TAG,"String_Node_Str" + uri,ex);
    return null;
  }
  if (!ContentUris.withAppendedId(mBaseUri,matchId).equals(uri)) {
    return null;
  }
  Cursor cursor=getCursor();
synchronized (cursor) {
    cursor.moveToPosition(-1);
    for (int i=0; cursor.moveToNext(); ++i) {
      if (getImageId(cursor) == matchId) {
        BaseImage image=mCache.get(i);
        if (image == null) {
          image=loadImageFromCursor(cursor);
          mCache.put(i,image);
        }
        return image;
      }
    }
    return null;
  }
}

Fixed version (ground truth):
public IImage getImageForUri(Uri uri){
  long matchId;
  try {
    matchId=ContentUris.parseId(uri);
  }
 catch (  NumberFormatException ex) {
    Log.i(TAG,"String_Node_Str" + uri,ex);
    return null;
  }
  Cursor cursor=getCursor();
synchronized (cursor) {
    cursor.moveToPosition(-1);
    for (int i=0; cursor.moveToNext(); ++i) {
      if (getImageId(cursor) == matchId) {
        BaseImage image=mCache.get(i);
        if (image == null) {
          image=loadImageFromCursor(cursor);
          mCache.put(i,image);
        }
        return image;
      }
    }
    return null;
  }
}
Program: 184535
Project: 184535
Buggy source:
void initializeSecondTime(){
  mOrientationListener.enable();
  readPreference();
  if (mRecordLocation)   startReceivingLocationUpdates();
  installIntentFilter();
  initializeFocusTone();
}

Fixed version (ground truth):
void initializeSecondTime(){
  mOrientationListener.enable();
  readPreference();
  if (mRecordLocation)   startReceivingLocationUpdates();
  installIntentFilter();
  initializeFocusTone();
  if (!mIsImageCaptureIntent) {
    updateThumbnailButton();
  }
}
Program: 184536
Project: 184536
Buggy source:
public void surfaceChanged(SurfaceHolder holder,int format,int w,int h){
  mSurfaceHolder=holder;
  mViewFinderWidth=w;
  mViewFinderHeight=h;
  if (mPausing)   return;
  mSurfaceView.setVisibility(View.VISIBLE);
  if (mStatus == SNAPSHOT_IN_PROGRESS)   return;
  startPreview();
  if (!mFirstTimeInitialized) {
    mHandler.sendEmptyMessage(FIRST_TIME_INIT);
  }
}

Fixed version (ground truth):
public void surfaceChanged(SurfaceHolder holder,int format,int w,int h){
  mSurfaceHolder=holder;
  mViewFinderWidth=w;
  mViewFinderHeight=h;
  if (mPausing)   return;
  mSurfaceView.setVisibility(View.VISIBLE);
  if (mStatus == SNAPSHOT_IN_PROGRESS)   return;
  startPreview();
  if (!mFirstTimeInitialized) {
    mHandler.sendEmptyMessage(FIRST_TIME_INIT);
  }
 else {
    initializeSecondTime();
  }
}
Program: 184537
Project: 184537
Buggy source:
@Override public void handleMessage(Message msg){
switch (msg.what) {
case RESTART_PREVIEW:
{
      restartPreview();
      break;
    }
case STORE_IMAGE_DONE:
{
    if (!mIsImageCaptureIntent) {
      setLastPictureThumb((byte[])msg.obj,mImageCapture.getLastCaptureUri());
      if (!mThumbController.isUriValid()) {
        updateLastImage();
      }
      mThumbController.updateDisplayIfNeeded();
    }
 else {
      showPostCaptureAlert();
    }
    mStoreImageThread=null;
    break;
  }
case CLEAR_SCREEN_DELAY:
{
  getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
  break;
}
case FIRST_TIME_INIT:
{
initializeFirstTime();
break;
}
}
}

Fixed version (ground truth):
@Override public void handleMessage(Message msg){
switch (msg.what) {
case RESTART_PREVIEW:
{
      restartPreview();
      break;
    }
case STORE_IMAGE_DONE:
{
    if (!mIsImageCaptureIntent) {
      setLastPictureThumb((byte[])msg.obj,mImageCapture.getLastCaptureUri());
      updateThumbnailButton();
    }
 else {
      showPostCaptureAlert();
    }
    mStoreImageThread=null;
    break;
  }
case CLEAR_SCREEN_DELAY:
{
  getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
  break;
}
case FIRST_TIME_INIT:
{
initializeFirstTime();
break;
}
}
}