Program: 14876
Project: 14876
Buggy source:
public String uploadMediaFile(MediaFile mf,Blog blog){
  String content="String_Node_Str";
  String curImagePath=mf.getFilePath();
  if (curImagePath == null)   return null;
  if (curImagePath.contains("String_Node_Str")) {
    XMLRPCClient client=new XMLRPCClient(blog.getUrl(),blog.getHttpuser(),blog.getHttppassword());
    String tempFileName="String_Node_Str" + System.currentTimeMillis();
    try {
      context.openFileOutput(tempFileName,Context.MODE_PRIVATE);
    }
 catch (    FileNotFoundException e) {
      mErrorMessage=getResources().getString(R.string.file_error_create);
      mIsMediaError=true;
      return null;
    }
    File tempFile=context.getFileStreamPath(tempFileName);
    Uri videoUri=Uri.parse(curImagePath);
    File videoFile=null;
    String mimeType="String_Node_Str", xRes="String_Node_Str", yRes="String_Node_Str";
    if (videoUri.toString().contains("String_Node_Str")) {
      String[] projection=new String[]{Video.Media._ID,Video.Media.DATA,Video.Media.MIME_TYPE,Video.Media.RESOLUTION};
      Cursor cur=context.getContentResolver().query(videoUri,projection,null,null,null);
      if (cur != null && cur.moveToFirst()) {
        int mimeTypeColumn, resolutionColumn, dataColumn;
        dataColumn=cur.getColumnIndex(Video.Media.DATA);
        mimeTypeColumn=cur.getColumnIndex(Video.Media.MIME_TYPE);
        resolutionColumn=cur.getColumnIndex(Video.Media.RESOLUTION);
        mf=new MediaFile();
        String thumbData=cur.getString(dataColumn);
        mimeType=cur.getString(mimeTypeColumn);
        videoFile=new File(thumbData);
        mf.setFilePath(videoFile.getPath());
        String resolution=cur.getString(resolutionColumn);
        if (resolution != null) {
          String[] resx=resolution.split("String_Node_Str");
          xRes=resx[0];
          yRes=resx[1];
        }
 else {
          if (!blog.getMaxImageWidth().equals("String_Node_Str")) {
            xRes=blog.getMaxImageWidth();
            yRes=String.valueOf(Math.round(Integer.valueOf(blog.getMaxImageWidth()) * 0.75));
          }
 else {
            xRes="String_Node_Str";
            yRes="String_Node_Str";
          }
        }
      }
    }
 else {
      String filePath=videoUri.toString().replace("String_Node_Str","String_Node_Str");
      mf.setFilePath(filePath);
      videoFile=new File(filePath);
    }
    if (videoFile == null) {
      mErrorMessage=context.getResources().getString(R.string.error_media_upload);
      return null;
    }
    if (TextUtils.isEmpty(mimeType)) {
      mimeType=getMediaFileMimeType(videoFile,false);
    }
    String videoName=getMediaFileName(videoFile,mimeType);
    Map<String,Object> m=new HashMap<String,Object>();
    m.put("String_Node_Str",videoName);
    m.put("String_Node_Str",mimeType);
    m.put("String_Node_Str",mf);
    m.put("String_Node_Str",true);
    Object[] params={1,blog.getUsername(),blog.getPassword(),m};
    FeatureSet featureSet=synchronousGetFeatureSet();
    boolean selfHosted=WordPress.currentBlog != null && !WordPress.currentBlog.isDotcomFlag();
    boolean isVideoEnabled=selfHosted || (featureSet != null && mFeatureSet.isVideopressEnabled());
    if (isVideoEnabled) {
      Object result=uploadFileHelper(client,params,tempFile);
      Map<?,?> resultMap=(HashMap<?,?>)result;
      if (resultMap != null && resultMap.containsKey("String_Node_Str")) {
        String resultURL=resultMap.get("String_Node_Str").toString();
        if (resultMap.containsKey("String_Node_Str")) {
          resultURL=resultMap.get("String_Node_Str").toString() + "String_Node_Str";
        }
 else {
          resultURL=String.format("String_Node_Str",xRes,yRes,resultURL,mimeType,resultURL);
        }
        content=content + resultURL;
      }
 else {
        return null;
      }
    }
 else {
      mErrorMessage=getString(R.string.media_no_video_message);
      mErrorUnavailableVideoPress=true;
      return null;
    }
  }
 else {
    curImagePath=mf.getFilePath();
    Uri imageUri=Uri.parse(curImagePath);
    File imageFile=null;
    String mimeType="String_Node_Str", orientation="String_Node_Str", path="String_Node_Str";
    if (imageUri.toString().contains("String_Node_Str")) {
      String[] projection;
      Uri imgPath;
      projection=new String[]{Images.Media._ID,Images.Media.DATA,Images.Media.MIME_TYPE,Images.Media.ORIENTATION};
      imgPath=imageUri;
      Cursor cur=context.getContentResolver().query(imgPath,projection,null,null,null);
      if (cur.moveToFirst()) {
        int dataColumn, mimeTypeColumn, orientationColumn;
        dataColumn=cur.getColumnIndex(Images.Media.DATA);
        mimeTypeColumn=cur.getColumnIndex(Images.Media.MIME_TYPE);
        orientationColumn=cur.getColumnIndex(Images.Media.ORIENTATION);
        orientation=cur.getString(orientationColumn);
        String thumbData=cur.getString(dataColumn);
        mimeType=cur.getString(mimeTypeColumn);
        imageFile=new File(thumbData);
        path=thumbData;
        mf.setFilePath(imageFile.getPath());
      }
    }
 else {
      path=imageUri.toString().replace("String_Node_Str","String_Node_Str");
      imageFile=new File(path);
      mf.setFilePath(path);
    }
    if (imageFile == null) {
      mErrorMessage=context.getString(R.string.file_not_found);
      mIsMediaError=true;
      return null;
    }
    if (TextUtils.isEmpty(mimeType)) {
      mimeType=getMediaFileMimeType(imageFile,false);
    }
    String fileName=getMediaFileName(imageFile,mimeType);
    ImageHelper ih=new ImageHelper();
    orientation=ih.getExifOrientation(path,orientation);
    String resizedPictureURL=null;
    boolean shouldUploadResizedVersion=false;
    if (!mimeType.equals("String_Node_Str") && !blog.getMaxImageWidth().equals("String_Node_Str")) {
      int pictureSettingWidth=mf.getWidth();
      BitmapFactory.Options options=new BitmapFactory.Options();
      options.inJustDecodeBounds=true;
      BitmapFactory.decodeFile(path,options);
      int imageHeight=options.outHeight;
      int imageWidth=options.outWidth;
      int[] dimensions={imageWidth,imageHeight};
      if (dimensions[0] != 0 && dimensions[0] != pictureSettingWidth) {
        shouldUploadResizedVersion=true;
      }
    }
    if (shouldUploadResizedVersion) {
      byte[] bytes;
      byte[] finalBytes;
      try {
        bytes=new byte[(int)imageFile.length()];
      }
 catch (      OutOfMemoryError er) {
        mErrorMessage=context.getString(R.string.out_of_memory);
        mIsMediaError=true;
        return null;
      }
      DataInputStream in=null;
      try {
        in=new DataInputStream(new FileInputStream(imageFile));
      }
 catch (      FileNotFoundException e) {
        e.printStackTrace();
      }
      try {
        in.readFully(bytes);
      }
 catch (      IOException e) {
        e.printStackTrace();
      }
      try {
        in.close();
      }
 catch (      IOException e) {
        e.printStackTrace();
      }
      String width=String.valueOf(mf.getWidth());
      String fileExtensionThumb=MimeTypeMap.getFileExtensionFromUrl(fileName).toLowerCase();
      finalBytes=ih.createThumbnail(bytes,width,orientation,false,fileExtensionThumb);
      if (finalBytes == null) {
        mErrorMessage=context.getString(R.string.out_of_memory);
        mIsMediaError=true;
        return null;
      }
      Map<String,Object> m=new HashMap<String,Object>();
      m.put("String_Node_Str",fileName);
      m.put("String_Node_Str",mimeType);
      m.put("String_Node_Str",finalBytes);
      m.put("String_Node_Str",true);
      resizedPictureURL=uploadPicture(m,mf,blog);
      if (resizedPictureURL == null)       return null;
    }
    String fullSizeUrl=null;
    if (!shouldUploadResizedVersion || blog.isFullSizeImage()) {
      Map<String,Object> m=new HashMap<String,Object>();
      m.put("String_Node_Str",fileName);
      m.put("String_Node_Str",mimeType);
      m.put("String_Node_Str",mf);
      m.put("String_Node_Str",true);
      fullSizeUrl=uploadPicture(m,mf,blog);
      if (fullSizeUrl == null)       return null;
    }
    String alignment="String_Node_Str";
switch (mf.getHorizontalAlignment()) {
case 0:
      alignment="String_Node_Str";
    break;
case 1:
  alignment="String_Node_Str";
break;
case 2:
alignment="String_Node_Str";
break;
case 3:
alignment="String_Node_Str";
break;
}
String alignmentCSS="String_Node_Str" + alignment + "String_Node_Str";
if ((fullSizeUrl != null && fullSizeUrl.equalsIgnoreCase("String_Node_Str")) || (resizedPictureURL != null && resizedPictureURL.equalsIgnoreCase("String_Node_Str"))) {
return "String_Node_Str";
}
if (fullSizeUrl != null && resizedPictureURL != null) {
}
 else if (fullSizeUrl == null) {
fullSizeUrl=resizedPictureURL;
}
 else {
resizedPictureURL=fullSizeUrl;
}
String mediaTitle=TextUtils.isEmpty(mf.getTitle()) ? "String_Node_Str" : mf.getTitle();
content=content + "String_Node_Str" + fullSizeUrl+ "String_Node_Str"+ mediaTitle+ "String_Node_Str"+ alignmentCSS+ "String_Node_Str"+ resizedPictureURL+ "String_Node_Str";
if (!TextUtils.isEmpty(mf.getCaption())) {
content=String.format("String_Node_Str",alignment,mf.getWidth(),TextUtils.htmlEncode(mf.getCaption()),content);
}
}
return content;
}

Fixed version (ground truth):
public String uploadMediaFile(MediaFile mf,Blog blog){
  String content="String_Node_Str";
  String curImagePath=mf.getFilePath();
  if (curImagePath == null)   return null;
  if (curImagePath.contains("String_Node_Str")) {
    XMLRPCClient client=new XMLRPCClient(blog.getUrl(),blog.getHttpuser(),blog.getHttppassword());
    String tempFileName="String_Node_Str" + System.currentTimeMillis();
    try {
      context.openFileOutput(tempFileName,Context.MODE_PRIVATE);
    }
 catch (    FileNotFoundException e) {
      mErrorMessage=getResources().getString(R.string.file_error_create);
      mIsMediaError=true;
      return null;
    }
    File tempFile=context.getFileStreamPath(tempFileName);
    Uri videoUri=Uri.parse(curImagePath);
    File videoFile=null;
    String mimeType="String_Node_Str", xRes="String_Node_Str", yRes="String_Node_Str";
    if (videoUri.toString().contains("String_Node_Str")) {
      String[] projection=new String[]{Video.Media._ID,Video.Media.DATA,Video.Media.MIME_TYPE,Video.Media.RESOLUTION};
      Cursor cur=context.getContentResolver().query(videoUri,projection,null,null,null);
      if (cur != null && cur.moveToFirst()) {
        int mimeTypeColumn, resolutionColumn, dataColumn;
        dataColumn=cur.getColumnIndex(Video.Media.DATA);
        mimeTypeColumn=cur.getColumnIndex(Video.Media.MIME_TYPE);
        resolutionColumn=cur.getColumnIndex(Video.Media.RESOLUTION);
        mf=new MediaFile();
        String thumbData=cur.getString(dataColumn);
        mimeType=cur.getString(mimeTypeColumn);
        videoFile=new File(thumbData);
        mf.setFilePath(videoFile.getPath());
        String resolution=cur.getString(resolutionColumn);
        if (resolution != null) {
          String[] resx=resolution.split("String_Node_Str");
          xRes=resx[0];
          yRes=resx[1];
        }
 else {
          if (!blog.getMaxImageWidth().equals("String_Node_Str")) {
            xRes=blog.getMaxImageWidth();
            yRes=String.valueOf(Math.round(Integer.valueOf(blog.getMaxImageWidth()) * 0.75));
          }
 else {
            xRes="String_Node_Str";
            yRes="String_Node_Str";
          }
        }
      }
    }
 else {
      String filePath=videoUri.toString().replace("String_Node_Str","String_Node_Str");
      mf.setFilePath(filePath);
      videoFile=new File(filePath);
    }
    if (videoFile == null) {
      mErrorMessage=context.getResources().getString(R.string.error_media_upload);
      return null;
    }
    if (TextUtils.isEmpty(mimeType)) {
      mimeType=getMediaFileMimeType(videoFile,false);
    }
    String videoName=getMediaFileName(videoFile,mimeType);
    Map<String,Object> m=new HashMap<String,Object>();
    m.put("String_Node_Str",videoName);
    m.put("String_Node_Str",mimeType);
    m.put("String_Node_Str",mf);
    m.put("String_Node_Str",true);
    Object[] params={1,blog.getUsername(),blog.getPassword(),m};
    FeatureSet featureSet=synchronousGetFeatureSet();
    boolean selfHosted=WordPress.currentBlog != null && !WordPress.currentBlog.isDotcomFlag();
    boolean isVideoEnabled=selfHosted || (featureSet != null && mFeatureSet.isVideopressEnabled());
    if (isVideoEnabled) {
      Object result=uploadFileHelper(client,params,tempFile);
      Map<?,?> resultMap=(HashMap<?,?>)result;
      if (resultMap != null && resultMap.containsKey("String_Node_Str")) {
        String resultURL=resultMap.get("String_Node_Str").toString();
        if (resultMap.containsKey("String_Node_Str")) {
          resultURL=resultMap.get("String_Node_Str").toString() + "String_Node_Str";
        }
 else {
          resultURL=String.format("String_Node_Str",xRes,yRes,resultURL,mimeType,resultURL);
        }
        content=content + resultURL;
      }
 else {
        return null;
      }
    }
 else {
      mErrorMessage=getString(R.string.media_no_video_message);
      mErrorUnavailableVideoPress=true;
      return null;
    }
  }
 else {
    curImagePath=mf.getFilePath();
    Uri imageUri=Uri.parse(curImagePath);
    File imageFile=null;
    String mimeType="String_Node_Str", orientation="String_Node_Str", path="String_Node_Str";
    if (imageUri.toString().contains("String_Node_Str")) {
      String[] projection;
      Uri imgPath;
      projection=new String[]{Images.Media._ID,Images.Media.DATA,Images.Media.MIME_TYPE,Images.Media.ORIENTATION};
      imgPath=imageUri;
      Cursor cur=context.getContentResolver().query(imgPath,projection,null,null,null);
      if (cur.moveToFirst()) {
        int dataColumn, mimeTypeColumn, orientationColumn;
        dataColumn=cur.getColumnIndex(Images.Media.DATA);
        mimeTypeColumn=cur.getColumnIndex(Images.Media.MIME_TYPE);
        orientationColumn=cur.getColumnIndex(Images.Media.ORIENTATION);
        orientation=cur.getString(orientationColumn);
        String thumbData=cur.getString(dataColumn);
        mimeType=cur.getString(mimeTypeColumn);
        imageFile=new File(thumbData);
        path=thumbData;
        mf.setFilePath(imageFile.getPath());
      }
    }
 else {
      path=imageUri.toString().replace("String_Node_Str","String_Node_Str");
      imageFile=new File(path);
      mf.setFilePath(path);
    }
    if (imageFile == null) {
      mErrorMessage=context.getString(R.string.file_not_found);
      mIsMediaError=true;
      return null;
    }
    if (TextUtils.isEmpty(mimeType)) {
      mimeType=getMediaFileMimeType(imageFile,true);
    }
    String fileName=getMediaFileName(imageFile,mimeType);
    ImageHelper ih=new ImageHelper();
    orientation=ih.getExifOrientation(path,orientation);
    String resizedPictureURL=null;
    boolean shouldUploadResizedVersion=false;
    if (!mimeType.equals("String_Node_Str") && !blog.getMaxImageWidth().equals("String_Node_Str")) {
      int pictureSettingWidth=mf.getWidth();
      BitmapFactory.Options options=new BitmapFactory.Options();
      options.inJustDecodeBounds=true;
      BitmapFactory.decodeFile(path,options);
      int imageHeight=options.outHeight;
      int imageWidth=options.outWidth;
      int[] dimensions={imageWidth,imageHeight};
      if (dimensions[0] != 0 && dimensions[0] != pictureSettingWidth) {
        shouldUploadResizedVersion=true;
      }
    }
    if (shouldUploadResizedVersion) {
      byte[] bytes;
      byte[] finalBytes;
      try {
        bytes=new byte[(int)imageFile.length()];
      }
 catch (      OutOfMemoryError er) {
        mErrorMessage=context.getString(R.string.out_of_memory);
        mIsMediaError=true;
        return null;
      }
      DataInputStream in=null;
      try {
        in=new DataInputStream(new FileInputStream(imageFile));
      }
 catch (      FileNotFoundException e) {
        e.printStackTrace();
      }
      try {
        in.readFully(bytes);
      }
 catch (      IOException e) {
        e.printStackTrace();
      }
      try {
        in.close();
      }
 catch (      IOException e) {
        e.printStackTrace();
      }
      String width=String.valueOf(mf.getWidth());
      String fileExtensionThumb=MimeTypeMap.getFileExtensionFromUrl(fileName).toLowerCase();
      finalBytes=ih.createThumbnail(bytes,width,orientation,false,fileExtensionThumb);
      if (finalBytes == null) {
        mErrorMessage=context.getString(R.string.out_of_memory);
        mIsMediaError=true;
        return null;
      }
      Map<String,Object> m=new HashMap<String,Object>();
      m.put("String_Node_Str",fileName);
      m.put("String_Node_Str",mimeType);
      m.put("String_Node_Str",finalBytes);
      m.put("String_Node_Str",true);
      resizedPictureURL=uploadPicture(m,mf,blog);
      if (resizedPictureURL == null)       return null;
    }
    String fullSizeUrl=null;
    if (!shouldUploadResizedVersion || blog.isFullSizeImage()) {
      Map<String,Object> m=new HashMap<String,Object>();
      m.put("String_Node_Str",fileName);
      m.put("String_Node_Str",mimeType);
      m.put("String_Node_Str",mf);
      m.put("String_Node_Str",true);
      fullSizeUrl=uploadPicture(m,mf,blog);
      if (fullSizeUrl == null)       return null;
    }
    String alignment="String_Node_Str";
switch (mf.getHorizontalAlignment()) {
case 0:
      alignment="String_Node_Str";
    break;
case 1:
  alignment="String_Node_Str";
break;
case 2:
alignment="String_Node_Str";
break;
case 3:
alignment="String_Node_Str";
break;
}
String alignmentCSS="String_Node_Str" + alignment + "String_Node_Str";
if ((fullSizeUrl != null && fullSizeUrl.equalsIgnoreCase("String_Node_Str")) || (resizedPictureURL != null && resizedPictureURL.equalsIgnoreCase("String_Node_Str"))) {
return "String_Node_Str";
}
if (fullSizeUrl != null && resizedPictureURL != null) {
}
 else if (fullSizeUrl == null) {
fullSizeUrl=resizedPictureURL;
}
 else {
resizedPictureURL=fullSizeUrl;
}
String mediaTitle=TextUtils.isEmpty(mf.getTitle()) ? "String_Node_Str" : mf.getTitle();
content=content + "String_Node_Str" + fullSizeUrl+ "String_Node_Str"+ mediaTitle+ "String_Node_Str"+ alignmentCSS+ "String_Node_Str"+ resizedPictureURL+ "String_Node_Str";
if (!TextUtils.isEmpty(mf.getCaption())) {
content=String.format("String_Node_Str",alignment,mf.getWidth(),TextUtils.htmlEncode(mf.getCaption()),content);
}
}
return content;
}