Program: 142030
Project: 142030
Buggy source:
/** 
 * @param scaleByContainerOnly If true, means that we're just trying to ensure that our bitmapisn't way bigger than necessary, rather than creating a bitmap of an exact size based on a target width and height. In this case, targetWidth and targetHeight are ignored and the 2nd case below is used.
 * @return A bitmap representation of the given image file, scaled down if necessary such thatthe new dimensions of the image are the SMALLER of the following 2 options: 1) targetHeight and targetWidth 2) the largest dimensions for which the original aspect ratio is maintained, without exceeding either boundingWidth or boundingHeight (or just the original dimensions if the image already roughly fits in the bounds)
 */
private static Bitmap scaleDownToTargetOrContainer(String imageFilepath,int originalHeight,int originalWidth,int targetHeight,int targetWidth,int boundingHeight,int boundingWidth,boolean scaleByContainerOnly,boolean respectBoundsExactly){
  Pair<Integer,Integer> dimensImposedByContainer=getRoughDimensImposedByContainer(originalHeight,originalWidth,boundingHeight,boundingWidth);
  int newWidth, newHeight;
  if (scaleByContainerOnly) {
    newWidth=dimensImposedByContainer.first;
    newHeight=dimensImposedByContainer.second;
  }
 else {
    newWidth=Math.min(dimensImposedByContainer.first,targetWidth);
    newHeight=Math.min(dimensImposedByContainer.second,targetHeight);
  }
  int approximateScaleDownFactor=getApproxScaleDownFactor(newWidth,originalWidth);
  Bitmap b=inflateImageSafe(imageFilepath,approximateScaleDownFactor).first;
  if (scaleByContainerOnly && !respectBoundsExactly) {
    return b;
  }
 else {
    return Bitmap.createScaledBitmap(b,newWidth,newHeight,false);
  }
}

Fixed version (ground truth):
/** 
 * @param scaleByContainerOnly If true, means that we're just trying to ensure that our bitmapisn't way bigger than necessary, rather than creating a bitmap of an exact size based on a target width and height. In this case, targetWidth and targetHeight are ignored and the 2nd case below is used.
 * @return A bitmap representation of the given image file, scaled down if necessary such thatthe new dimensions of the image are the SMALLER of the following 2 options: 1) targetHeight and targetWidth 2) the largest dimensions for which the original aspect ratio is maintained, without exceeding either boundingWidth or boundingHeight (or just the original dimensions if the image already roughly fits in the bounds)
 */
private static Bitmap scaleDownToTargetOrContainer(String imageFilepath,int originalHeight,int originalWidth,int targetHeight,int targetWidth,int boundingHeight,int boundingWidth,boolean scaleByContainerOnly,boolean respectBoundsExactly){
  Pair<Integer,Integer> dimensImposedByContainer=getRoughDimensImposedByContainer(originalHeight,originalWidth,boundingHeight,boundingWidth);
  int newWidth, newHeight;
  if (scaleByContainerOnly) {
    newWidth=dimensImposedByContainer.first;
    newHeight=dimensImposedByContainer.second;
  }
 else {
    newWidth=Math.min(dimensImposedByContainer.first,targetWidth);
    newHeight=Math.min(dimensImposedByContainer.second,targetHeight);
  }
  int approximateScaleDownFactor=getApproxScaleDownFactor(newWidth,originalWidth);
  Bitmap b=inflateImageSafe(imageFilepath,approximateScaleDownFactor).first;
  if (scaleByContainerOnly && !respectBoundsExactly) {
    return b;
  }
 else {
    try {
      return Bitmap.createScaledBitmap(b,newWidth,newHeight,false);
    }
 catch (    OutOfMemoryError e) {
      Log.d(TAG,"String_Node_Str" + imageFilepath);
      return null;
    }
  }
}