Program: 13866
Project: 13866
Buggy source:
private static boolean resizeImageAndWriteToStream(Context context,Uri imageUri,String fileExtension,int maxWidth,int orientation,int quality,OutputStream outStream) throws OutOfMemoryError, IOException {
  String realFilePath=getRealFilePath(context,imageUri);
  BitmapFactory.Options optBounds=new BitmapFactory.Options();
  optBounds.inJustDecodeBounds=true;
  try {
    BitmapFactory.decodeFile(realFilePath,optBounds);
  }
 catch (  OutOfMemoryError e) {
    AppLog.e(AppLog.T.UTILS,"String_Node_Str" + realFilePath,e);
    throw e;
  }
  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;
  final Bitmap bmpResized;
  try {
    bmpResized=BitmapFactory.decodeFile(realFilePath,optActual);
  }
 catch (  OutOfMemoryError e) {
    AppLog.e(AppLog.T.UTILS,"String_Node_Str" + realFilePath,e);
    throw e;
  }
  if (bmpResized == null) {
    AppLog.e(AppLog.T.UTILS,"String_Node_Str");
    throw new IOException("String_Node_Str");
  }
  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 (orientation != 0) {
    matrix.setRotate(orientation);
  }
  Bitmap.CompressFormat fmt;
  if (fileExtension != null && (fileExtension.equals("String_Node_Str") || fileExtension.equals("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) {
    AppLog.e(AppLog.T.UTILS,"String_Node_Str",e);
    throw e;
  }
catch (  NullPointerException e) {
    AppLog.e(AppLog.T.UTILS,"String_Node_Str",e);
    throw e;
  }
  if (bmpRotated == null) {
    AppLog.e(AppLog.T.UTILS,"String_Node_Str");
    throw new IOException("String_Node_Str");
  }
  return bmpRotated.compress(fmt,quality,outStream);
}

Fixed version (ground truth):
private static boolean resizeImageAndWriteToStream(Context context,Uri imageUri,String fileExtension,int maxWidth,int orientation,int quality,OutputStream outStream) throws OutOfMemoryError, IOException {
  String realFilePath=MediaUtils.getRealPathFromURI(context,imageUri);
  BitmapFactory.Options optBounds=new BitmapFactory.Options();
  optBounds.inJustDecodeBounds=true;
  try {
    BitmapFactory.decodeFile(realFilePath,optBounds);
  }
 catch (  OutOfMemoryError e) {
    AppLog.e(AppLog.T.UTILS,"String_Node_Str" + realFilePath,e);
    throw e;
  }
  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;
  final Bitmap bmpResized;
  try {
    bmpResized=BitmapFactory.decodeFile(realFilePath,optActual);
  }
 catch (  OutOfMemoryError e) {
    AppLog.e(AppLog.T.UTILS,"String_Node_Str" + realFilePath,e);
    throw e;
  }
  if (bmpResized == null) {
    AppLog.e(AppLog.T.UTILS,"String_Node_Str");
    throw new IOException("String_Node_Str");
  }
  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 (orientation != 0) {
    matrix.setRotate(orientation);
  }
  Bitmap.CompressFormat fmt;
  if (fileExtension != null && (fileExtension.equals("String_Node_Str") || fileExtension.equals("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) {
    AppLog.e(AppLog.T.UTILS,"String_Node_Str",e);
    throw e;
  }
catch (  NullPointerException e) {
    AppLog.e(AppLog.T.UTILS,"String_Node_Str",e);
    throw e;
  }
  if (bmpRotated == null) {
    AppLog.e(AppLog.T.UTILS,"String_Node_Str");
    throw new IOException("String_Node_Str");
  }
  return bmpRotated.compress(fmt,quality,outStream);
}