nus-yam/ex-repair huggingface dataset:
Program: 184538
Project: 184538
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: 184539
Project: 184539
Buggy source:
public void surfaceCreated(SurfaceHolder holder){
  mSurfaceHolder=holder;
}

Fixed version (ground truth):
public void surfaceCreated(SurfaceHolder holder){
}
Program: 184540
Project: 184540
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: 184541
Project: 184541
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: 184542
Project: 184542
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: 184543
Project: 184543
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: 184544
Project: 184544
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: 184545
Project: 184545
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: 184546
Project: 184546
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: 184547
Project: 184547
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: 184548
Project: 184548
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: 184549
Project: 184549
Buggy source:
private boolean init(Uri uri,IImageList imageList){
  if (uri == null)   return false;
  mAllImages=imageList == null ? new SingleImageList(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;
  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;
}
Program: 184550
Project: 184550
Buggy source:
private boolean init(Uri uri,IImageList imageList){
  if (uri == null)   return false;
  mAllImages=imageList == null ? new SingleImageList(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;
  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;
}
Program: 184551
Project: 184551
Buggy source:
public int compare(MergeSlot m1,MergeSlot m2){
  if (m1.mDateTaken != m2.mDateTaken) {
    return m1.mDateTaken < m2.mDateTaken ? -1 : 1;
  }
  return m1.mListIndex - m2.mListIndex;
}

Fixed version (ground truth):
public int compare(MergeSlot m1,MergeSlot m2){
  Log.v(TAG,String.format("String_Node_Str",m1.mDateTaken,m2.mDateTaken));
  if (m1.mDateTaken != m2.mDateTaken) {
    return m1.mDateTaken < m2.mDateTaken ? -1 : 1;
  }
  return m1.mListIndex - m2.mListIndex;
}
Program: 184552
Project: 184552
Buggy source:
public void run(MenuHelper.MenuCallback cb){
  cb.run(getCurrentImageUri(),getCurrentImage());
  mGvs.stop();
  mGvs.setImageList(mAllImages);
  mGvs.start();
  mNoImagesView.setVisibility(mAllImages.getCount() > 0 ? View.GONE : View.VISIBLE);
}

Fixed version (ground truth):
public void run(MenuHelper.MenuCallback cb){
  if (!canHandleEvent()) {
    return;
  }
  cb.run(getCurrentImageUri(),getCurrentImage());
  mGvs.stop();
  mGvs.setImageList(mAllImages);
  mGvs.start();
  mNoImagesView.setVisibility(mAllImages.getCount() > 0 ? View.GONE : View.VISIBLE);
}
Program: 184553
Project: 184553
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){
        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,isImage,ImageGallery.this,mHandler,mDeletePhotoRunnable,new MenuHelper.MenuInvoker(){
      public void run(      MenuHelper.MenuCallback cb){
        cb.run(getCurrentImageUri(),getCurrentImage());
        mGvs.stop();
        mGvs.setImageList(mAllImages);
        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 (!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){
        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,isImage,ImageGallery.this,mHandler,mDeletePhotoRunnable,new MenuHelper.MenuInvoker(){
      public void run(      MenuHelper.MenuCallback cb){
        if (!canHandleEvent()) {
          return;
        }
        cb.run(getCurrentImageUri(),getCurrentImage());
        mGvs.stop();
        mGvs.setImageList(mAllImages);
        mGvs.start();
        mNoImagesView.setVisibility(mAllImages.getCount() > 0 ? View.GONE : View.VISIBLE);
      }
    }
);
    if (r != null) {
      r.gettingReadyToOpen(menu,getCurrentImage());
    }
    if (isImage) {
      addSlideShowMenu(menu,1000);
    }
  }
}
Program: 184554
Project: 184554
Buggy source:
public boolean onSlideShowClicked(){
  IImage img=getCurrentImage();
  if (img == null) {
    img=mAllImages.getImageAt(0);
    if (img == null) {
      return true;
    }
  }
  Uri targetUri=img.fullSizeImageUri();
  Uri thisUri=getIntent().getData();
  if (thisUri != null) {
    String bucket=thisUri.getQueryParameter("String_Node_Str");
    if (bucket != null) {
      targetUri=targetUri.buildUpon().appendQueryParameter("String_Node_Str",bucket).build();
    }
  }
  Intent intent=new Intent(Intent.ACTION_VIEW,targetUri);
  intent.putExtra("String_Node_Str",true);
  startActivity(intent);
  return true;
}

Fixed version (ground truth):
public boolean onSlideShowClicked(){
  if (!canHandleEvent()) {
    return false;
  }
  IImage img=getCurrentImage();
  if (img == null) {
    img=mAllImages.getImageAt(0);
    if (img == null) {
      return true;
    }
  }
  Uri targetUri=img.fullSizeImageUri();
  Uri thisUri=getIntent().getData();
  if (thisUri != null) {
    String bucket=thisUri.getQueryParameter("String_Node_Str");
    if (bucket != null) {
      targetUri=targetUri.buildUpon().appendQueryParameter("String_Node_Str",bucket).build();
    }
  }
  Intent intent=new Intent(Intent.ACTION_VIEW,targetUri);
  intent.putExtra("String_Node_Str",true);
  startActivity(intent);
  return true;
}
Program: 184555
Project: 184555
Buggy source:
@Override public boolean onSingleTapConfirmed(MotionEvent e){
  select(mCurrentSelection,false);
  int index=computeSelectedIndex(e.getX(),e.getY());
  if (index >= 0 && index < mCount) {
    mListener.onImageClicked(index);
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean onSingleTapConfirmed(MotionEvent e){
  if (!canHandleEvent())   return false;
  select(mCurrentSelection,false);
  int index=computeSelectedIndex(e.getX(),e.getY());
  if (index >= 0 && index < mCount) {
    mListener.onImageClicked(index);
    return true;
  }
  return false;
}
Program: 184556
Project: 184556
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(SELECT_NONE,false);
  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){
  if (!canHandleEvent())   return false;
  final float maxVelocity=2500;
  if (velocityY > maxVelocity) {
    velocityY=maxVelocity;
  }
 else   if (velocityY < -maxVelocity) {
    velocityY=-maxVelocity;
  }
  select(SELECT_NONE,false);
  mScroller=new Scroller(getContext());
  mScroller.fling(0,mScrollY,0,-(int)velocityY,0,0,0,mMaxScrollY);
  computeScroll();
  return true;
}
Program: 184557
Project: 184557
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 < 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 pos=computeSelectedIndex(e.getX(),e.getY());
  if (pos >= 0 && pos < mCount) {
    select(pos,true);
  }
 else {
    select(SELECT_NONE,false);
  }
  return true;
}
Program: 184558
Project: 184558
Buggy source:
@Override public boolean onScroll(MotionEvent e1,MotionEvent e2,float distanceX,float distanceY){
  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;
  select(SELECT_NONE,false);
  scrollBy(0,(int)distanceY);
  invalidate();
  return true;
}
Program: 184559
Project: 184559
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){
        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,isImage,ImageGallery.this,mHandler,mDeletePhotoRunnable,new MenuHelper.MenuInvoker(){
      public void run(      MenuHelper.MenuCallback cb){
        cb.run(getCurrentImageUri(),getCurrentImage());
        mGvs.stop();
        mGvs.setImageList(mAllImages);
        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 (!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){
        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,isImage,ImageGallery.this,mHandler,mDeletePhotoRunnable,new MenuHelper.MenuInvoker(){
      public void run(      MenuHelper.MenuCallback cb){
        cb.run(getCurrentImageUri(),getCurrentImage());
        mGvs.stop();
        mGvs.setImageList(mAllImages);
        mGvs.start();
        mNoImagesView.setVisibility(mAllImages.getCount() > 0 ? View.GONE : View.VISIBLE);
      }
    }
);
    if (r != null) {
      r.gettingReadyToOpen(menu,getCurrentImage());
    }
    if (isImage) {
      addSlideShowMenu(menu,1000);
    }
  }
}
Program: 184560
Project: 184560
Buggy source:
@Override public boolean onPrepareOptionsMenu(Menu menu){
  if ((mInclusion & ImageManager.INCLUDE_IMAGES) != 0) {
    boolean videoSelected=isVideoSelected();
    if (mSlideShowItem != null) {
      mSlideShowItem.setEnabled(!videoSelected);
    }
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean onPrepareOptionsMenu(Menu menu){
  if (!canHandleEvent())   return false;
  if ((mInclusion & ImageManager.INCLUDE_IMAGES) != 0) {
    boolean videoSelected=isVideoSelected();
    if (mSlideShowItem != null) {
      mSlideShowItem.setEnabled(!videoSelected);
    }
  }
  return true;
}
Program: 184562
Project: 184562
Buggy source:
@Override public boolean onSingleTapConfirmed(MotionEvent e){
  select(mCurrentSelection,false);
  int index=computeSelectedIndex(e.getX(),e.getY());
  if (index >= 0 && index < mCount) {
    mListener.onImageClicked(index);
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean onSingleTapConfirmed(MotionEvent e){
  if (!canHandleEvent())   return false;
  select(mCurrentSelection,false);
  int index=computeSelectedIndex(e.getX(),e.getY());
  if (index >= 0 && index < mCount) {
    mListener.onImageClicked(index);
    return true;
  }
  return false;
}
Program: 184563
Project: 184563
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(SELECT_NONE,false);
  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){
  if (!canHandleEvent())   return false;
  final float maxVelocity=2500;
  if (velocityY > maxVelocity) {
    velocityY=maxVelocity;
  }
 else   if (velocityY < -maxVelocity) {
    velocityY=-maxVelocity;
  }
  select(SELECT_NONE,false);
  mScroller=new Scroller(getContext());
  mScroller.fling(0,mScrollY,0,-(int)velocityY,0,0,0,mMaxScrollY);
  computeScroll();
  return true;
}
Program: 184564
Project: 184564
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 < 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 pos=computeSelectedIndex(e.getX(),e.getY());
  if (pos >= 0 && pos < mCount) {
    select(pos,true);
  }
 else {
    select(SELECT_NONE,false);
  }
  return true;
}
Program: 184565
Project: 184565
Buggy source:
@Override public boolean onScroll(MotionEvent e1,MotionEvent e2,float distanceX,float distanceY){
  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;
  select(SELECT_NONE,false);
  scrollBy(0,(int)distanceY);
  invalidate();
  return true;
}
Program: 184566
Project: 184566
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){
        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,isImage,ImageGallery.this,mHandler,mDeletePhotoRunnable,new MenuHelper.MenuInvoker(){
      public void run(      MenuHelper.MenuCallback cb){
        cb.run(getCurrentImageUri(),getCurrentImage());
        mGvs.stop();
        mGvs.setImageList(mAllImages);
        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 (!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){
        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,isImage,ImageGallery.this,mHandler,mDeletePhotoRunnable,new MenuHelper.MenuInvoker(){
      public void run(      MenuHelper.MenuCallback cb){
        cb.run(getCurrentImageUri(),getCurrentImage());
        mGvs.stop();
        mGvs.setImageList(mAllImages);
        mGvs.start();
        mNoImagesView.setVisibility(mAllImages.getCount() > 0 ? View.GONE : View.VISIBLE);
      }
    }
);
    if (r != null) {
      r.gettingReadyToOpen(menu,getCurrentImage());
    }
    if (isImage) {
      addSlideShowMenu(menu,1000);
    }
  }
}
Program: 184567
Project: 184567
Buggy source:
@Override public boolean onPrepareOptionsMenu(Menu menu){
  if ((mInclusion & ImageManager.INCLUDE_IMAGES) != 0) {
    boolean videoSelected=isVideoSelected();
    if (mSlideShowItem != null) {
      mSlideShowItem.setEnabled(!videoSelected);
    }
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean onPrepareOptionsMenu(Menu menu){
  if (!canHandleEvent())   return false;
  if ((mInclusion & ImageManager.INCLUDE_IMAGES) != 0) {
    boolean videoSelected=isVideoSelected();
    if (mSlideShowItem != null) {
      mSlideShowItem.setEnabled(!videoSelected);
    }
  }
  return true;
}
Program: 184569
Project: 184569
Buggy source:
private void showAlert(){
  int[] pickIds={R.id.attach,R.id.cancel};
  int[] normalIds={R.id.gallery,R.id.share,R.id.discard};
  int[] alwaysOnIds={R.id.play};
  int[] hideIds=pickIds;
  int[] connectIds=normalIds;
  if (mIsVideoCaptureIntent) {
    hideIds=normalIds;
    connectIds=pickIds;
  }
  for (  int id : hideIds) {
    mPostPictureAlert.findViewById(id).setVisibility(View.GONE);
  }
  ActionMenuButton shareButton=(ActionMenuButton)mPostPictureAlert.findViewById(R.id.share);
  shareButton.setRestricted(mCurrentVideoFileLength > SHARE_FILE_LENGTH_LIMIT);
  connectAndFadeIn(connectIds);
  connectAndFadeIn(alwaysOnIds);
  hideLastPictureButton();
  mPostPictureAlert.setVisibility(View.VISIBLE);
  if (!mIsVideoCaptureIntent) {
    mCurrentVideoUri=mThumbController.getUri();
    mCurrentVideoFilename=getDataPath(mCurrentVideoUri);
  }
  String path=mCurrentVideoFilename;
  if (path != null) {
    Bitmap videoFrame=Util.createVideoThumbnail(path);
    mVideoFrame.setImageBitmap(videoFrame);
    mVideoFrame.setVisibility(View.VISIBLE);
  }
}

Fixed version (ground truth):
private void showAlert(){
  int[] pickIds={R.id.attach,R.id.cancel};
  int[] normalIds={R.id.gallery,R.id.share,R.id.discard};
  int[] alwaysOnIds={R.id.play};
  int[] hideIds=pickIds;
  int[] connectIds=normalIds;
  if (mIsVideoCaptureIntent) {
    hideIds=normalIds;
    connectIds=pickIds;
  }
  for (  int id : hideIds) {
    mPostPictureAlert.findViewById(id).setVisibility(View.GONE);
  }
  ActionMenuButton shareButton=(ActionMenuButton)mPostPictureAlert.findViewById(R.id.share);
  shareButton.setRestricted(mCurrentVideoFileLength > SHARE_FILE_LENGTH_LIMIT);
  connectAndFadeIn(connectIds);
  connectAndFadeIn(alwaysOnIds);
  hideLastPictureButton();
  mPostPictureAlert.setVisibility(View.VISIBLE);
  if (!mIsVideoCaptureIntent) {
    if (mThumbController.isUriValid()) {
      mCurrentVideoUri=mThumbController.getUri();
      mCurrentVideoFilename=getDataPath(mCurrentVideoUri);
    }
 else {
      return;
    }
  }
  String path=mCurrentVideoFilename;
  if (path != null) {
    Bitmap videoFrame=Util.createVideoThumbnail(path);
    mVideoFrame.setImageBitmap(videoFrame);
    mVideoFrame.setVisibility(View.VISIBLE);
  }
}
Program: 184570
Project: 184570
Buggy source:
/** 
 * Make sure "acquire/release" are pairing correctly
 */
public synchronized void releaseResourceLock(){
  Thread t=Thread.currentThread();
  mLocked=false;
  notifyAll();
}

Fixed version (ground truth):
/** 
 * Make sure "acquire/release" are pairing correctly
 */
public synchronized void releaseResourceLock(){
  mLocked=false;
  notifyAll();
}
Program: 184572
Project: 184572
Buggy source:
private synchronized void start(){
  if (mDecodeThread != null) {
    return;
  }
  mDone=false;
  Thread t=new Thread(new WorkerThread());
  t.setName("String_Node_Str");
  mDecodeThread=t;
  t.start();
}

Fixed version (ground truth):
private void start(){
  if (mDecodeThread != null) {
    return;
  }
  mDone=false;
  Thread t=new Thread(new WorkerThread());
  t.setName("String_Node_Str");
  mDecodeThread=t;
  t.start();
}
Program: 184573
Project: 184573
Buggy source:
public void run(){
  while (!mDone) {
    WorkItem workItem=null;
synchronized (mQueue) {
      if (!mQueue.isEmpty()) {
        workItem=mQueue.remove(0);
      }
 else {
        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);
    }
  }
}

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;
        }
      }
    }
    if (workItem == null) {
      mThumbnailChecker.checkNextThumbnail();
      continue;
    }
    final Bitmap b=workItem.mImage.miniThumbBitmap();
    if (workItem.mOnLoadedRunnable != null) {
      workItem.mOnLoadedRunnable.run(b);
    }
  }
}
Program: 184574
Project: 184574
Buggy source:
public synchronized void stop(){
  mDone=true;
synchronized (mQueue) {
    mQueue.notifyAll();
  }
  if (mDecodeThread != null) {
    try {
      Thread t=mDecodeThread;
      BitmapManager.instance().cancelThreadDecoding(t);
      t.join();
      mDecodeThread=null;
    }
 catch (    InterruptedException ex) {
    }
  }
  stopCheckingThumbnails();
}

Fixed version (ground truth):
public void stop(){
synchronized (mQueue) {
    mDone=true;
    mQueue.notifyAll();
  }
  if (mDecodeThread != null) {
    try {
      Thread t=mDecodeThread;
      BitmapManager.instance().cancelThreadDecoding(t);
      t.join();
      mDecodeThread=null;
    }
 catch (    InterruptedException ex) {
    }
  }
  stopCheckingThumbnails();
}
Program: 184575
Project: 184575
Buggy source:
public ImageLoader(Handler handler){
  mHandler=handler;
  mThumbnailChecker=new ThumbnailChecker();
  start();
}

Fixed version (ground truth):
public ImageLoader(Handler handler){
  mThumbnailChecker=new ThumbnailChecker();
  start();
}
Program: 184576
Project: 184576
Buggy source:
public static Uri addImage(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(STORAGE_URI,values);
}

Fixed version (ground truth):
public static Uri addImage(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);
  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(STORAGE_URI,values);
}
Program: 184578
Project: 184578
Buggy source:
private static void setReverseGeocodingDetails(View d,Activity context,float lat,float lng){
  String value=EMPTY_STRING;
  if (lat == INVALID_LATLNG || lng == INVALID_LATLNG) {
    hideDetailsRow(d,R.id.details_location_row);
    return;
  }
  try {
    Geocoder geocoder=new Geocoder(context);
    List<Address> address=geocoder.getFromLocation(lat,lng,1);
    Iterator<Address> iterator=address.iterator();
    while (iterator.hasNext()) {
      Address addr=iterator.next();
      value+=addr.getAddressLine(addr.getMaxAddressLineIndex());
      Log.v(TAG,addr.toString());
    }
  }
 catch (  IOException ex) {
    value=EMPTY_STRING;
    Log.e(TAG,"String_Node_Str",ex);
  }
catch (  RuntimeException ex) {
    value=EMPTY_STRING;
    Log.e(TAG,"String_Node_Str",ex);
  }
  if (value != EMPTY_STRING) {
    setDetailsValue(d,value,R.id.details_location_value);
  }
 else {
    hideDetailsRow(d,R.id.details_location_row);
  }
}

Fixed version (ground truth):
private static void setReverseGeocodingDetails(View d,Activity context,float lat,float lng){
  String value=EMPTY_STRING;
  if (lat == INVALID_LATLNG || lng == INVALID_LATLNG) {
    hideDetailsRow(d,R.id.details_location_row);
    return;
  }
  try {
    Geocoder geocoder=new Geocoder(context);
    List<Address> address=geocoder.getFromLocation(lat,lng,1);
    StringBuilder sb=new StringBuilder();
    for (    Address addr : address) {
      int index=addr.getMaxAddressLineIndex();
      sb.append(addr.getAddressLine(index));
    }
    value=sb.toString();
  }
 catch (  IOException ex) {
    value=EMPTY_STRING;
    Log.e(TAG,"String_Node_Str",ex);
  }
catch (  RuntimeException ex) {
    value=EMPTY_STRING;
    Log.e(TAG,"String_Node_Str",ex);
  }
  if (value != EMPTY_STRING) {
    setDetailsValue(d,value,R.id.details_location_value);
  }
 else {
    hideDetailsRow(d,R.id.details_location_row);
  }
}
Program: 184579
Project: 184579
Buggy source:
private void loadExifData(){
  Cursor c=getCursor();
  String filePath;
synchronized (c) {
    filePath=c.getString(mContainer.indexData());
  }
  ExifInterface mExif=new ExifInterface(filePath);
  if (mExifData == null) {
    mExifData=mExif.getAttributes();
  }
}

Fixed version (ground truth):
private void loadExifData(){
  Cursor c=getCursor();
  String filePath;
synchronized (c) {
    filePath=c.getString(mContainer.indexData());
  }
  mExif=new ExifInterface(filePath);
  if (mExifData == null) {
    mExifData=mExif.getAttributes();
  }
}
Program: 184581
Project: 184581
Buggy source:
byte[] getMiniThumbFromFile(long id,byte[] data,long magicCheck){
  RandomAccessFile r=miniThumbDataFile();
  if (r == null)   return null;
  long pos=id * BYTES_PER_MINTHUMB;
synchronized (r) {
    try {
      r.seek(pos);
      if (r.readByte() == 1) {
        long magic=r.readLong();
        if (magic != magicCheck) {
          return null;
        }
        int length=r.readInt();
        r.read(data,0,length);
        return data;
      }
 else {
        return null;
      }
    }
 catch (    IOException ex) {
      return null;
    }
  }
}

Fixed version (ground truth):
byte[] getMiniThumbFromFile(long id,byte[] data,long magicCheck){
  RandomAccessFile r=miniThumbDataFile();
  if (r == null)   return null;
  long pos=id * BYTES_PER_MINTHUMB;
synchronized (r) {
    try {
      r.seek(pos);
      if (r.readByte() == 1) {
        long magic=r.readLong();
        if (magic != magicCheck) {
          return null;
        }
        int length=r.readInt();
        int got=r.read(data,0,length);
        if (got != length)         return null;
        return data;
      }
 else {
        return null;
      }
    }
 catch (    IOException ex) {
      return null;
    }
  }
}
Program: 184582
Project: 184582
Buggy source:
private void saveOutput(){
  if (mSaveUri != null) {
    OutputStream outputStream=null;
    try {
      outputStream=mContentResolver.openOutputStream(mSaveUri);
      if (outputStream != null) {
        mCroppedImage.compress(mOutputFormat,75,outputStream);
      }
    }
 catch (    IOException ex) {
    }
 finally {
      Util.closeSilently(outputStream);
    }
    Bundle extras=new Bundle();
    setResult(RESULT_OK,new Intent(mSaveUri.toString()).putExtras(extras));
  }
 else {
    Bundle extras=new Bundle();
    extras.putString("String_Node_Str",mCrop.getCropRect().toString());
    File oldPath=new File(mImage.getDataPath());
    File directory=new File(oldPath.getParent());
    int x=0;
    String fileName=oldPath.getName();
    fileName=fileName.substring(0,fileName.lastIndexOf("String_Node_Str"));
    while (true) {
      x+=1;
      String candidate=directory.toString() + "String_Node_Str" + fileName+ "String_Node_Str"+ x+ "String_Node_Str";
      boolean exists=(new File(candidate)).exists();
      if (!exists) {
        break;
      }
    }
    try {
      Uri newUri=ImageManager.addImage(mContentResolver,mImage.getTitle(),mImage.getDateTaken(),null,0,directory.toString(),fileName + "String_Node_Str" + x+ "String_Node_Str");
      Cancelable<Void> cancelable=ImageManager.storeImage(newUri,mContentResolver,0,mCroppedImage,null);
      cancelable.get();
      setResult(RESULT_OK,new Intent().setAction(newUri.toString()).putExtras(extras));
    }
 catch (    Exception ex) {
    }
  }
  finish();
}

Fixed version (ground truth):
private void saveOutput(){
  if (mSaveUri != null) {
    OutputStream outputStream=null;
    try {
      outputStream=mContentResolver.openOutputStream(mSaveUri);
      if (outputStream != null) {
        mCroppedImage.compress(mOutputFormat,75,outputStream);
      }
    }
 catch (    IOException ex) {
      Log.e(TAG,"String_Node_Str" + mSaveUri,ex);
    }
 finally {
      Util.closeSilently(outputStream);
    }
    Bundle extras=new Bundle();
    setResult(RESULT_OK,new Intent(mSaveUri.toString()).putExtras(extras));
  }
 else {
    Bundle extras=new Bundle();
    extras.putString("String_Node_Str",mCrop.getCropRect().toString());
    File oldPath=new File(mImage.getDataPath());
    File directory=new File(oldPath.getParent());
    int x=0;
    String fileName=oldPath.getName();
    fileName=fileName.substring(0,fileName.lastIndexOf("String_Node_Str"));
    while (true) {
      x+=1;
      String candidate=directory.toString() + "String_Node_Str" + fileName+ "String_Node_Str"+ x+ "String_Node_Str";
      boolean exists=(new File(candidate)).exists();
      if (!exists) {
        break;
      }
    }
    try {
      Uri newUri=ImageManager.addImage(mContentResolver,mImage.getTitle(),mImage.getDateTaken(),null,0,directory.toString(),fileName + "String_Node_Str" + x+ "String_Node_Str");
      Cancelable<Void> cancelable=ImageManager.storeImage(newUri,mContentResolver,0,mCroppedImage,null);
      cancelable.get();
      setResult(RESULT_OK,new Intent().setAction(newUri.toString()).putExtras(extras));
    }
 catch (    Exception ex) {
    }
  }
  finish();
}
Program: 184583
Project: 184583
Buggy source:
@Override protected void onCreate(Bundle icicle){
  super.onCreate(icicle);
  if (icicle != null) {
    mDoLaunch=icicle.getBoolean(DO_LAUNCH_ICICLE);
    mTempFilePath=icicle.getString(TEMP_FILE_PATH_ICICLE);
  }
}

Fixed version (ground truth):
@Override protected void onCreate(Bundle icicle){
  super.onCreate(icicle);
  if (icicle != null) {
    mDoLaunch=icicle.getBoolean(DO_LAUNCH_ICICLE);
    mTempFile=new File(icicle.getString(TEMP_FILE_PATH_ICICLE));
  }
}
Program: 184584
Project: 184584
Buggy source:
protected void formatIntent(Intent intent){
  File f=getFileStreamPath("String_Node_Str");
  (new File(f.getParent())).mkdirs();
  mTempFilePath=f.toString();
  f.delete();
  int width=getWallpaperDesiredMinimumWidth();
  int height=getWallpaperDesiredMinimumHeight();
  intent.putExtra("String_Node_Str",width);
  intent.putExtra("String_Node_Str",height);
  intent.putExtra("String_Node_Str",width);
  intent.putExtra("String_Node_Str",height);
  intent.putExtra("String_Node_Str",true);
  intent.putExtra("String_Node_Str",true);
  intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.parse("String_Node_Str" + mTempFilePath));
  intent.putExtra("String_Node_Str",Bitmap.CompressFormat.PNG.name());
}

Fixed version (ground truth):
protected void formatIntent(Intent intent){
  mTempFile=getFileStreamPath("String_Node_Str");
  mTempFile.getParentFile().mkdirs();
  int width=getWallpaperDesiredMinimumWidth();
  int height=getWallpaperDesiredMinimumHeight();
  intent.putExtra("String_Node_Str",width);
  intent.putExtra("String_Node_Str",height);
  intent.putExtra("String_Node_Str",width);
  intent.putExtra("String_Node_Str",height);
  intent.putExtra("String_Node_Str",true);
  intent.putExtra("String_Node_Str",true);
  intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(mTempFile));
  intent.putExtra("String_Node_Str",Bitmap.CompressFormat.PNG.name());
}
Program: 184585
Project: 184585
Buggy source:
@Override protected void onSaveInstanceState(Bundle icicle){
  icicle.putBoolean(DO_LAUNCH_ICICLE,mDoLaunch);
  icicle.putString(TEMP_FILE_PATH_ICICLE,mTempFilePath);
}

Fixed version (ground truth):
@Override protected void onSaveInstanceState(Bundle icicle){
  icicle.putBoolean(DO_LAUNCH_ICICLE,mDoLaunch);
  icicle.putString(TEMP_FILE_PATH_ICICLE,mTempFile.getAbsolutePath());
}