Program: 13774
Project: 13774
Buggy source:
@Override public void appendMediaFile(final MediaFile mediaFile,final String mediaUrl,ImageLoader imageLoader){
  final int maxWidth=ImageUtils.getMaximumThumbnailWidthForEditor(getActivity());
  if (URLUtil.isNetworkUrl(mediaUrl)) {
    final Drawable placeholder;
    if (mediaFile.isVideo()) {
      placeholder=getResources().getDrawable(R.drawable.ic_gridicons_video_camera);
    }
 else {
      placeholder=getResources().getDrawable(R.drawable.ic_gridicons_image);
    }
    placeholder.setBounds(0,0,DEFAULT_MEDIA_PLACEHOLDER_DIMENSION_DP,DEFAULT_MEDIA_PLACEHOLDER_DIMENSION_DP);
    AztecAttributes attributes=new AztecAttributes();
    attributes.setValue(ATTR_SRC,mediaUrl);
    setAttributeValuesIfNotDefault(attributes,mediaFile);
    if (mediaFile.isVideo()) {
      content.insertVideo(placeholder,attributes);
    }
 else {
      content.insertImage(placeholder,attributes);
    }
    final String posterURL=mediaFile.isVideo() ? Utils.escapeQuotes(StringUtils.notNullStr(mediaFile.getThumbnailURL())) : mediaUrl;
    imageLoader.get(posterURL,new ImageLoader.ImageListener(){
      private void replaceDrawable(      Drawable newDrawable){
        AztecMediaSpan[] imageOrVideoSpans=content.getText().getSpans(0,content.getText().length(),AztecMediaSpan.class);
        for (        AztecMediaSpan currentClass : imageOrVideoSpans) {
          if (currentClass.getAttributes().hasAttribute(ATTR_SRC) && mediaUrl.equals(currentClass.getAttributes().getValue(ATTR_SRC))) {
            currentClass.setDrawable(newDrawable);
          }
        }
        content.refreshText();
      }
      private void showErrorPlaceholder(){
        ToastUtils.showToast(getActivity(),R.string.error_media_load);
        Drawable drawable=getResources().getDrawable(R.drawable.ic_image_failed_grey_a_40_48dp);
        replaceDrawable(drawable);
      }
      @Override public void onErrorResponse(      VolleyError error){
        if (!isAdded()) {
          return;
        }
        showErrorPlaceholder();
      }
      @Override public void onResponse(      ImageLoader.ImageContainer container,      boolean isImmediate){
        if (!isAdded()) {
          return;
        }
        Bitmap downloadedBitmap=container.getBitmap();
        if (downloadedBitmap == null) {
          if (isImmediate) {
            return;
          }
          showErrorPlaceholder();
          return;
        }
        AztecAttributes attributes=new AztecAttributes();
        attributes.setValue(ATTR_SRC,mediaUrl);
        setAttributeValuesIfNotDefault(attributes,mediaFile);
        int minimumDimension=DisplayUtils.dpToPx(getActivity(),MIN_BITMAP_DIMENSION_DP);
        if (downloadedBitmap.getHeight() < minimumDimension || downloadedBitmap.getWidth() < minimumDimension) {
          ToastUtils.showToast(getActivity(),R.string.error_media_small);
          Drawable drawable=getResources().getDrawable(R.drawable.ic_image_loading_grey_a_40_48dp);
          replaceDrawable(drawable);
          return;
        }
        Bitmap resizedBitmap=ImageUtils.getScaledBitmapAtLongestSide(downloadedBitmap,maxWidth);
        replaceDrawable(new BitmapDrawable(getResources(),resizedBitmap));
        if (mediaFile.isVideo()) {
          addVideoUploadingClassIfMissing(attributes);
          content.insertVideo(new BitmapDrawable(getResources(),resizedBitmap),attributes);
          overlayVideoIcon(0,new MediaPredicate(mediaUrl,ATTR_SRC));
        }
 else {
          content.insertImage(new BitmapDrawable(getResources(),resizedBitmap),attributes);
        }
      }
    }
,maxWidth,0);
    mActionStartedAt=System.currentTimeMillis();
  }
 else {
    String localMediaId=String.valueOf(mediaFile.getId());
    final String safeMediaPreviewUrl=mediaFile.isVideo() ? Utils.escapeQuotes(StringUtils.notNullStr(mediaFile.getThumbnailURL())) : Utils.escapeQuotes(mediaUrl);
    AztecAttributes attrs=new AztecAttributes();
    attrs.setValue(ATTR_ID_WP,localMediaId);
    attrs.setValue(ATTR_SRC,Utils.escapeQuotes(mediaUrl));
    attrs.setValue(ATTR_CLASS,ATTR_STATUS_UPLOADING);
    addDefaultSizeClassIfMissing(attrs);
    Bitmap bitmapToShow=ImageUtils.getWPImageSpanThumbnailFromFilePath(getActivity(),safeMediaPreviewUrl,maxWidth);
    MediaPredicate localMediaIdPredicate=MediaPredicate.getLocalMediaIdPredicate(localMediaId);
    if (bitmapToShow != null) {
      if (mediaFile.isVideo()) {
        addVideoUploadingClassIfMissing(attrs);
        content.insertVideo(new BitmapDrawable(getResources(),bitmapToShow),attrs);
      }
 else {
        content.insertImage(new BitmapDrawable(getResources(),bitmapToShow),attrs);
      }
    }
 else {
      ToastUtils.showToast(getActivity(),R.string.error_media_load);
      Drawable drawable=getResources().getDrawable(R.drawable.ic_image_failed_grey_a_40_48dp);
      drawable.setBounds(0,0,maxWidth,maxWidth);
      content.insertImage(drawable,attrs);
    }
    overlayProgressingMedia(localMediaIdPredicate);
    mUploadingMediaProgressMax.put(localMediaId,0f);
    if (mediaFile.isVideo()) {
      overlayVideoIcon(2,localMediaIdPredicate);
    }
    content.updateElementAttributes(localMediaIdPredicate,attrs);
    content.resetAttributedMediaSpan(localMediaIdPredicate);
  }
}

Fixed version (ground truth):
@Override public void appendMediaFile(final MediaFile mediaFile,final String mediaUrl,ImageLoader imageLoader){
  final int maxWidth=ImageUtils.getMaximumThumbnailWidthForEditor(getActivity());
  if (URLUtil.isNetworkUrl(mediaUrl)) {
    final Drawable placeholder;
    if (mediaFile.isVideo()) {
      placeholder=getResources().getDrawable(R.drawable.ic_gridicons_video_camera);
    }
 else {
      placeholder=getResources().getDrawable(R.drawable.ic_gridicons_image);
    }
    placeholder.setBounds(0,0,DEFAULT_MEDIA_PLACEHOLDER_DIMENSION_DP,DEFAULT_MEDIA_PLACEHOLDER_DIMENSION_DP);
    AztecAttributes attributes=new AztecAttributes();
    attributes.setValue(ATTR_SRC,mediaUrl);
    setAttributeValuesIfNotDefault(attributes,mediaFile);
    if (mediaFile.isVideo()) {
      addVideoUploadingClassIfMissing(attributes);
      content.insertVideo(placeholder,attributes);
      overlayVideoIcon(0,new MediaPredicate(mediaUrl,ATTR_SRC));
    }
 else {
      content.insertImage(placeholder,attributes);
    }
    final String posterURL=mediaFile.isVideo() ? Utils.escapeQuotes(StringUtils.notNullStr(mediaFile.getThumbnailURL())) : mediaUrl;
    imageLoader.get(posterURL,new ImageLoader.ImageListener(){
      private void replaceDrawable(      Drawable newDrawable){
        AztecMediaSpan[] imageOrVideoSpans=content.getText().getSpans(0,content.getText().length(),AztecMediaSpan.class);
        for (        AztecMediaSpan currentClass : imageOrVideoSpans) {
          if (currentClass.getAttributes().hasAttribute(ATTR_SRC) && mediaUrl.equals(currentClass.getAttributes().getValue(ATTR_SRC))) {
            currentClass.setDrawable(newDrawable);
          }
        }
        content.refreshText();
      }
      private void showErrorPlaceholder(){
        ToastUtils.showToast(getActivity(),R.string.error_media_load);
        Drawable drawable=getResources().getDrawable(R.drawable.ic_image_failed_grey_a_40_48dp);
        replaceDrawable(drawable);
      }
      @Override public void onErrorResponse(      VolleyError error){
        if (!isAdded()) {
          return;
        }
        showErrorPlaceholder();
      }
      @Override public void onResponse(      ImageLoader.ImageContainer container,      boolean isImmediate){
        if (!isAdded()) {
          return;
        }
        Bitmap downloadedBitmap=container.getBitmap();
        if (downloadedBitmap == null) {
          if (isImmediate) {
            return;
          }
          showErrorPlaceholder();
          return;
        }
        AztecAttributes attributes=new AztecAttributes();
        attributes.setValue(ATTR_SRC,mediaUrl);
        setAttributeValuesIfNotDefault(attributes,mediaFile);
        int minimumDimension=DisplayUtils.dpToPx(getActivity(),MIN_BITMAP_DIMENSION_DP);
        if (downloadedBitmap.getHeight() < minimumDimension || downloadedBitmap.getWidth() < minimumDimension) {
          ToastUtils.showToast(getActivity(),R.string.error_media_small);
          Drawable drawable=getResources().getDrawable(R.drawable.ic_image_loading_grey_a_40_48dp);
          replaceDrawable(drawable);
          return;
        }
        Bitmap resizedBitmap=ImageUtils.getScaledBitmapAtLongestSide(downloadedBitmap,maxWidth);
        replaceDrawable(new BitmapDrawable(getResources(),resizedBitmap));
      }
    }
,maxWidth,0);
    mActionStartedAt=System.currentTimeMillis();
  }
 else {
    String localMediaId=String.valueOf(mediaFile.getId());
    final String safeMediaPreviewUrl=mediaFile.isVideo() ? Utils.escapeQuotes(StringUtils.notNullStr(mediaFile.getThumbnailURL())) : Utils.escapeQuotes(mediaUrl);
    AztecAttributes attrs=new AztecAttributes();
    attrs.setValue(ATTR_ID_WP,localMediaId);
    attrs.setValue(ATTR_SRC,Utils.escapeQuotes(mediaUrl));
    attrs.setValue(ATTR_CLASS,ATTR_STATUS_UPLOADING);
    addDefaultSizeClassIfMissing(attrs);
    Bitmap bitmapToShow=ImageUtils.getWPImageSpanThumbnailFromFilePath(getActivity(),safeMediaPreviewUrl,maxWidth);
    MediaPredicate localMediaIdPredicate=MediaPredicate.getLocalMediaIdPredicate(localMediaId);
    if (bitmapToShow != null) {
      if (mediaFile.isVideo()) {
        addVideoUploadingClassIfMissing(attrs);
        content.insertVideo(new BitmapDrawable(getResources(),bitmapToShow),attrs);
      }
 else {
        content.insertImage(new BitmapDrawable(getResources(),bitmapToShow),attrs);
      }
    }
 else {
      ToastUtils.showToast(getActivity(),R.string.error_media_load);
      Drawable drawable=getResources().getDrawable(R.drawable.ic_image_failed_grey_a_40_48dp);
      drawable.setBounds(0,0,maxWidth,maxWidth);
      content.insertImage(drawable,attrs);
    }
    overlayProgressingMedia(localMediaIdPredicate);
    mUploadingMediaProgressMax.put(localMediaId,0f);
    if (mediaFile.isVideo()) {
      overlayVideoIcon(2,localMediaIdPredicate);
    }
    content.updateElementAttributes(localMediaIdPredicate,attrs);
    content.resetAttributedMediaSpan(localMediaIdPredicate);
  }
}