Program: 134380
Project: 134380
Buggy source:
/** 
 * Given the path to an image, compress and resize it.
 * @param context the passed context
 * @param path the path to the original image
 * @param maxImageSize the maximum allowed width
 * @param quality the encoder quality
 * @return the path to the optimized image
 */
public static String optimizeImage(Context context,String path,int maxImageSize,int quality){
  if (context == null || TextUtils.isEmpty(path)) {
    return path;
  }
  File file=new File(path);
  if (!file.exists()) {
    return path;
  }
  String mimeType=MediaUtils.getMediaFileMimeType(file);
  if (mimeType.equals("String_Node_Str")) {
    return path;
  }
  Uri srcImageUri=Uri.parse(path);
  if (srcImageUri == null) {
    return path;
  }
  String fileName=MediaUtils.getMediaFileName(file,mimeType);
  String fileExtension=MimeTypeMap.getFileExtensionFromUrl(fileName).toLowerCase();
  int[] imageDimensions=getImageSize(srcImageUri,context);
  int selectedMaxSize=Math.max(imageDimensions[0],imageDimensions[1]);
  if (selectedMaxSize == 0) {
    return path;
  }
  if (maxImageSize == Integer.MAX_VALUE && quality == 100) {
    return path;
  }
  if (selectedMaxSize > maxImageSize) {
    selectedMaxSize=maxImageSize;
  }
  int orientation=getImageOrientation(context,path);
  File resizedImageFile;
  FileOutputStream out;
  try {
    String prefix=FileUtils.getFileNameFromPath(fileName);
    if (TextUtils.isEmpty(prefix) || prefix.length() < 3) {
      prefix="String_Node_Str";
    }
    resizedImageFile=File.createTempFile(prefix,"String_Node_Str" + fileExtension);
    out=new FileOutputStream(resizedImageFile);
  }
 catch (  IOException e) {
    AppLog.e(AppLog.T.MEDIA,"String_Node_Str");
    return path;
  }
catch (  SecurityException e) {
    AppLog.e(AppLog.T.MEDIA,"String_Node_Str");
    return path;
  }
  try {
    boolean res=resizeImageAndWriteToStream(context,srcImageUri,fileExtension,selectedMaxSize,orientation,quality,out);
    if (!res) {
      AppLog.w(AppLog.T.MEDIA,"String_Node_Str");
      return path;
    }
  }
 catch (  IOException e) {
    AppLog.e(AppLog.T.MEDIA,"String_Node_Str");
    return path;
  }
catch (  OutOfMemoryError e) {
    AppLog.e(AppLog.T.MEDIA,"String_Node_Str");
    return path;
  }
 finally {
    try {
      out.flush();
      out.close();
    }
 catch (    IOException e) {
    }
  }
  String tempFilePath=resizedImageFile.getPath();
  if (!TextUtils.isEmpty(tempFilePath)) {
    return tempFilePath;
  }
 else {
    AppLog.e(AppLog.T.MEDIA,"String_Node_Str");
  }
  return path;
}

Fixed version (ground truth):
/** 
 * Given the path to an image, compress and resize it.
 * @param context the passed context
 * @param path the path to the original image
 * @param maxImageSize the maximum allowed width
 * @param quality the encoder quality
 * @return the path to the optimized image
 */
public static String optimizeImage(Context context,String path,int maxImageSize,int quality){
  if (context == null || TextUtils.isEmpty(path)) {
    return path;
  }
  File file=new File(path);
  if (!file.exists()) {
    return path;
  }
  String mimeType=MediaUtils.getMediaFileMimeType(file);
  if (mimeType.equals("String_Node_Str")) {
    return path;
  }
  Uri srcImageUri=Uri.parse(path);
  if (srcImageUri == null) {
    return path;
  }
  String fileName=MediaUtils.getMediaFileName(file,mimeType);
  String fileExtension=MimeTypeMap.getFileExtensionFromUrl(fileName).toLowerCase(Locale.ROOT);
  int[] imageDimensions=getImageSize(srcImageUri,context);
  int selectedMaxSize=Math.max(imageDimensions[0],imageDimensions[1]);
  if (selectedMaxSize == 0) {
    return path;
  }
  if (maxImageSize == Integer.MAX_VALUE && quality == 100) {
    return path;
  }
  if (selectedMaxSize > maxImageSize) {
    selectedMaxSize=maxImageSize;
  }
  int orientation=getImageOrientation(context,path);
  File resizedImageFile;
  FileOutputStream out;
  try {
    String prefix=FileUtils.getFileNameFromPath(fileName);
    if (TextUtils.isEmpty(prefix) || prefix.length() < 3) {
      prefix="String_Node_Str";
    }
    resizedImageFile=File.createTempFile(prefix,"String_Node_Str" + fileExtension);
    out=new FileOutputStream(resizedImageFile);
  }
 catch (  IOException e) {
    AppLog.e(AppLog.T.MEDIA,"String_Node_Str");
    return path;
  }
catch (  SecurityException e) {
    AppLog.e(AppLog.T.MEDIA,"String_Node_Str");
    return path;
  }
  try {
    boolean res=resizeImageAndWriteToStream(context,srcImageUri,fileExtension,selectedMaxSize,orientation,quality,out);
    if (!res) {
      AppLog.w(AppLog.T.MEDIA,"String_Node_Str");
      return path;
    }
  }
 catch (  IOException e) {
    AppLog.e(AppLog.T.MEDIA,"String_Node_Str");
    return path;
  }
catch (  OutOfMemoryError e) {
    AppLog.e(AppLog.T.MEDIA,"String_Node_Str");
    return path;
  }
 finally {
    try {
      out.flush();
      out.close();
    }
 catch (    IOException e) {
    }
  }
  String tempFilePath=resizedImageFile.getPath();
  if (!TextUtils.isEmpty(tempFilePath)) {
    return tempFilePath;
  }
 else {
    AppLog.e(AppLog.T.MEDIA,"String_Node_Str");
  }
  return path;
}