Program: 40143
Project: 40143
Buggy source:
/** 
 * Create a resized image to fill the maxWidth/maxHeight values,the quality value and the angle value
 * @param realPath
 * @param initialWidth
 * @param initialHeight
 * @return resized file
 */
private File getResizedImage(final String realPath,final int initialWidth,final int initialHeight){
  Bitmap photo=BitmapFactory.decodeFile(realPath);
  if (photo == null) {
    return null;
  }
  Bitmap scaledphoto=null;
  if (maxWidth == 0) {
    maxWidth=initialWidth;
  }
  if (maxHeight == 0) {
    maxHeight=initialHeight;
  }
  double widthRatio=(double)maxWidth / initialWidth;
  double heightRatio=(double)maxHeight / initialHeight;
  double ratio=(widthRatio < heightRatio) ? widthRatio : heightRatio;
  Matrix matrix=new Matrix();
  matrix.postRotate(angle);
  matrix.postScale((float)ratio,(float)ratio);
  ExifInterface exif;
  try {
    exif=new ExifInterface(realPath);
    int orientation=exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,0);
    if (orientation == 6) {
      matrix.postRotate(90);
    }
 else     if (orientation == 3) {
      matrix.postRotate(180);
    }
 else     if (orientation == 8) {
      matrix.postRotate(270);
    }
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
  scaledphoto=Bitmap.createBitmap(photo,0,0,photo.getWidth(),photo.getHeight(),matrix,true);
  ByteArrayOutputStream bytes=new ByteArrayOutputStream();
  scaledphoto.compress(Bitmap.CompressFormat.JPEG,quality,bytes);
  File f=createNewFile(false);
  FileOutputStream fo;
  try {
    fo=new FileOutputStream(f);
    try {
      fo.write(bytes.toByteArray());
    }
 catch (    IOException e) {
      e.printStackTrace();
    }
  }
 catch (  FileNotFoundException e) {
    e.printStackTrace();
  }
  if (photo != null) {
    scaledphoto.recycle();
    photo.recycle();
    scaledphoto=null;
    photo=null;
  }
  return f;
}

Fixed version (ground truth):
/** 
 * Create a resized image to fill the maxWidth/maxHeight values,the quality value and the angle value
 * @param realPath
 * @param initialWidth
 * @param initialHeight
 * @return resized file
 */
private File getResizedImage(final String realPath,final int initialWidth,final int initialHeight){
  Options options=new BitmapFactory.Options();
  options.inScaled=false;
  Bitmap photo=BitmapFactory.decodeFile(realPath,options);
  if (photo == null) {
    return null;
  }
  Bitmap scaledphoto=null;
  if (maxWidth == 0) {
    maxWidth=initialWidth;
  }
  if (maxHeight == 0) {
    maxHeight=initialHeight;
  }
  double widthRatio=(double)maxWidth / initialWidth;
  double heightRatio=(double)maxHeight / initialHeight;
  double ratio=(widthRatio < heightRatio) ? widthRatio : heightRatio;
  Matrix matrix=new Matrix();
  matrix.postRotate(angle);
  matrix.postScale((float)ratio,(float)ratio);
  ExifInterface exif;
  try {
    exif=new ExifInterface(realPath);
    int orientation=exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,0);
    if (orientation == 6) {
      matrix.postRotate(90);
    }
 else     if (orientation == 3) {
      matrix.postRotate(180);
    }
 else     if (orientation == 8) {
      matrix.postRotate(270);
    }
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
  scaledphoto=Bitmap.createBitmap(photo,0,0,photo.getWidth(),photo.getHeight(),matrix,true);
  ByteArrayOutputStream bytes=new ByteArrayOutputStream();
  scaledphoto.compress(Bitmap.CompressFormat.JPEG,quality,bytes);
  File f=createNewFile(false);
  FileOutputStream fo;
  try {
    fo=new FileOutputStream(f);
    try {
      fo.write(bytes.toByteArray());
    }
 catch (    IOException e) {
      e.printStackTrace();
    }
  }
 catch (  FileNotFoundException e) {
    e.printStackTrace();
  }
  if (photo != null) {
    scaledphoto.recycle();
    photo.recycle();
    scaledphoto=null;
    photo=null;
  }
  return f;
}