Program: 14631
Project: 14631
Buggy source:
/** 
 * nbradbury - 21-Feb-2014 - similar to createThumbnail but more efficient since it doesn't require passing the full-size image as an array of bytes[]
 */
public static byte[] createThumbnailFromUri(Context context,Uri imageUri,int maxWidth,String fileExtension,int rotation){
  if (context == null || imageUri == null)   return null;
  String filePath=null;
  if (imageUri.toString().contains("String_Node_Str")) {
    String[] projection=new String[]{MediaStore.Images.Media.DATA};
    Cursor cur=context.getContentResolver().query(imageUri,projection,null,null,null);
    if (cur != null) {
      if (cur.moveToFirst()) {
        int dataColumn=cur.getColumnIndex(MediaStore.Images.Media.DATA);
        filePath=cur.getString(dataColumn);
      }
      cur.close();
    }
  }
  if (TextUtils.isEmpty(filePath)) {
    filePath=imageUri.toString().replace("String_Node_Str","String_Node_Str");
    filePath=filePath.replace("String_Node_Str","String_Node_Str");
  }
  BitmapFactory.Options optBounds=new BitmapFactory.Options();
  optBounds.inJustDecodeBounds=true;
  try {
    BitmapFactory.decodeFile(filePath,optBounds);
  }
 catch (  OutOfMemoryError e) {
    CrashlyticsUtils.logException(e,CrashlyticsUtils.ExceptionType.SPECIFIC,AppLog.T.UTILS);
    return null;
  }
  int scale=1;
  if (maxWidth > 0 && optBounds.outWidth > maxWidth) {
    double d=Math.pow(2,(int)Math.round(Math.log(maxWidth / (double)optBounds.outWidth) / Math.log(0.5)));
    scale=(int)d;
  }
  BitmapFactory.Options optActual=new BitmapFactory.Options();
  optActual.inSampleSize=scale;
  Bitmap bmpResized;
  try {
    bmpResized=BitmapFactory.decodeFile(filePath,optActual);
  }
 catch (  OutOfMemoryError e) {
    CrashlyticsUtils.setFloat(CrashlyticsUtils.ExtraKey.IMAGE_RESIZE_SCALE,scale);
    CrashlyticsUtils.logException(e,CrashlyticsUtils.ExceptionType.SPECIFIC,AppLog.T.UTILS);
    return null;
  }
  if (bmpResized == null)   return null;
  ByteArrayOutputStream stream=new ByteArrayOutputStream();
  float percentage=(float)maxWidth / bmpResized.getWidth();
  float proportionateHeight=bmpResized.getHeight() * percentage;
  int finalHeight=(int)Math.rint(proportionateHeight);
  float scaleWidth=((float)maxWidth) / bmpResized.getWidth();
  float scaleHeight=((float)finalHeight) / bmpResized.getHeight();
  float scaleBy=Math.min(scaleWidth,scaleHeight);
  Matrix matrix=new Matrix();
  matrix.postScale(scaleBy,scaleBy);
  if (rotation != 0) {
    matrix.setRotate(rotation);
  }
  Bitmap.CompressFormat fmt;
  if (fileExtension != null && fileExtension.equalsIgnoreCase("String_Node_Str")) {
    fmt=Bitmap.CompressFormat.PNG;
  }
 else {
    fmt=Bitmap.CompressFormat.JPEG;
  }
  final Bitmap bmpRotated;
  try {
    bmpRotated=Bitmap.createBitmap(bmpResized,0,0,bmpResized.getWidth(),bmpResized.getHeight(),matrix,true);
  }
 catch (  OutOfMemoryError e) {
    CrashlyticsUtils.setInt(CrashlyticsUtils.ExtraKey.IMAGE_ANGLE,rotation);
    CrashlyticsUtils.setInt(CrashlyticsUtils.ExtraKey.IMAGE_WIDTH,bmpResized.getWidth());
    CrashlyticsUtils.setInt(CrashlyticsUtils.ExtraKey.IMAGE_HEIGHT,bmpResized.getHeight());
    CrashlyticsUtils.setFloat(CrashlyticsUtils.ExtraKey.IMAGE_RESIZE_SCALE,scaleBy);
    CrashlyticsUtils.logException(e,CrashlyticsUtils.ExceptionType.SPECIFIC,AppLog.T.UTILS);
    return null;
  }
  bmpRotated.compress(fmt,100,stream);
  bmpResized.recycle();
  bmpRotated.recycle();
  return stream.toByteArray();
}

Fixed version (ground truth):
/** 
 * nbradbury - 21-Feb-2014 - similar to createThumbnail but more efficient since it doesn't require passing the full-size image as an array of bytes[]
 */
public static byte[] createThumbnailFromUri(Context context,Uri imageUri,int maxWidth,String fileExtension,int rotation){
  if (context == null || imageUri == null || maxWidth <= 0)   return null;
  String filePath=null;
  if (imageUri.toString().contains("String_Node_Str")) {
    String[] projection=new String[]{MediaStore.Images.Media.DATA};
    Cursor cur=context.getContentResolver().query(imageUri,projection,null,null,null);
    if (cur != null) {
      if (cur.moveToFirst()) {
        int dataColumn=cur.getColumnIndex(MediaStore.Images.Media.DATA);
        filePath=cur.getString(dataColumn);
      }
      cur.close();
    }
  }
  if (TextUtils.isEmpty(filePath)) {
    filePath=imageUri.toString().replace("String_Node_Str","String_Node_Str");
    filePath=filePath.replace("String_Node_Str","String_Node_Str");
  }
  BitmapFactory.Options optBounds=new BitmapFactory.Options();
  optBounds.inJustDecodeBounds=true;
  try {
    BitmapFactory.decodeFile(filePath,optBounds);
  }
 catch (  OutOfMemoryError e) {
    CrashlyticsUtils.logException(e,CrashlyticsUtils.ExceptionType.SPECIFIC,AppLog.T.UTILS);
    return null;
  }
  int scale=1;
  if (maxWidth > 0 && optBounds.outWidth > maxWidth) {
    double d=Math.pow(2,(int)Math.round(Math.log(maxWidth / (double)optBounds.outWidth) / Math.log(0.5)));
    scale=(int)d;
  }
  BitmapFactory.Options optActual=new BitmapFactory.Options();
  optActual.inSampleSize=scale;
  Bitmap bmpResized;
  try {
    bmpResized=BitmapFactory.decodeFile(filePath,optActual);
  }
 catch (  OutOfMemoryError e) {
    CrashlyticsUtils.setFloat(CrashlyticsUtils.ExtraKey.IMAGE_RESIZE_SCALE,scale);
    CrashlyticsUtils.logException(e,CrashlyticsUtils.ExceptionType.SPECIFIC,AppLog.T.UTILS);
    return null;
  }
  if (bmpResized == null)   return null;
  ByteArrayOutputStream stream=new ByteArrayOutputStream();
  float percentage=(float)maxWidth / bmpResized.getWidth();
  float proportionateHeight=bmpResized.getHeight() * percentage;
  int finalHeight=(int)Math.rint(proportionateHeight);
  float scaleWidth=((float)maxWidth) / bmpResized.getWidth();
  float scaleHeight=((float)finalHeight) / bmpResized.getHeight();
  float scaleBy=Math.min(scaleWidth,scaleHeight);
  Matrix matrix=new Matrix();
  matrix.postScale(scaleBy,scaleBy);
  if (rotation != 0) {
    matrix.setRotate(rotation);
  }
  Bitmap.CompressFormat fmt;
  if (fileExtension != null && fileExtension.equalsIgnoreCase("String_Node_Str")) {
    fmt=Bitmap.CompressFormat.PNG;
  }
 else {
    fmt=Bitmap.CompressFormat.JPEG;
  }
  final Bitmap bmpRotated;
  try {
    bmpRotated=Bitmap.createBitmap(bmpResized,0,0,bmpResized.getWidth(),bmpResized.getHeight(),matrix,true);
  }
 catch (  OutOfMemoryError e) {
    CrashlyticsUtils.setInt(CrashlyticsUtils.ExtraKey.IMAGE_ANGLE,rotation);
    CrashlyticsUtils.setInt(CrashlyticsUtils.ExtraKey.IMAGE_WIDTH,bmpResized.getWidth());
    CrashlyticsUtils.setInt(CrashlyticsUtils.ExtraKey.IMAGE_HEIGHT,bmpResized.getHeight());
    CrashlyticsUtils.setFloat(CrashlyticsUtils.ExtraKey.IMAGE_RESIZE_SCALE,scaleBy);
    CrashlyticsUtils.logException(e,CrashlyticsUtils.ExceptionType.SPECIFIC,AppLog.T.UTILS);
    return null;
  }
  bmpRotated.compress(fmt,100,stream);
  bmpResized.recycle();
  bmpRotated.recycle();
  return stream.toByteArray();
}