Program: 13673
Project: 13673
Buggy source:
@Override public void onActivityResult(int requestCode,int resultCode,Intent data){
  super.onActivityResult(requestCode,resultCode,data);
  if (requestCode == EDITOR_MEDIA_SETTINGS) {
    if (mTappedMediaPredicate != null) {
      if (data == null || data.getExtras() == null) {
        return;
      }
      EditorImageMetaData metaData=data.getParcelableExtra(ARG_EDITOR_IMAGE_METADATA);
      if (metaData.isRemoved()) {
        String editorContentBeforeImageIsRemoved="String_Node_Str";
        if (isHistoryEnabled()) {
          editorContentBeforeImageIsRemoved=content.toFormattedHtml();
        }
        CaptionExtensionsKt.removeImageCaption(content,mTappedMediaPredicate);
        content.removeMedia(mTappedMediaPredicate);
        if (isHistoryEnabled()) {
          content.history.beforeTextChanged(editorContentBeforeImageIsRemoved);
        }
      }
 else {
        if (isHistoryEnabled()) {
          content.history.beforeTextChanged(content.toFormattedHtml());
        }
        AztecAttributes attributes=content.getElementAttributes(mTappedMediaPredicate);
        attributes.setValue(ATTR_SRC,metaData.getSrc());
        if (!TextUtils.isEmpty(metaData.getTitle())) {
          attributes.setValue(ATTR_TITLE,metaData.getTitle());
        }
 else {
          attributes.removeAttribute(ATTR_TITLE);
        }
        if (!TextUtils.isEmpty(metaData.getAlt())) {
          attributes.setValue(ATTR_ALT,metaData.getAlt());
        }
 else {
          attributes.removeAttribute(ATTR_ALT);
        }
        attributes.setValue(ATTR_DIMEN_WIDTH,metaData.getWidth());
        attributes.setValue(ATTR_DIMEN_HEIGHT,metaData.getHeight());
        if (!TextUtils.isEmpty(metaData.getLinkUrl())) {
          AztecAttributes linkAttributes=MediaLinkExtensionsKt.getMediaLinkAttributes(content,mTappedMediaPredicate);
          linkAttributes.setValue("String_Node_Str","String_Node_Str");
          linkAttributes.removeAttribute("String_Node_Str");
          if (metaData.isLinkTargetBlank()) {
            linkAttributes.setValue(ATTR_TARGET,"String_Node_Str");
          }
 else {
            linkAttributes.removeAttribute(ATTR_TARGET);
          }
          MediaLinkExtensionsKt.addLinkToMedia(content,mTappedMediaPredicate,UrlUtils.addUrlSchemeIfNeeded(metaData.getLinkUrl(),false),linkAttributes);
        }
 else {
          MediaLinkExtensionsKt.removeLinkFromMedia(content,mTappedMediaPredicate);
        }
        AttributesWithClass attributesWithClass=getAttributesWithClass(attributes);
        attributesWithClass.removeClassStartingWith(ATTR_ALIGN);
        attributesWithClass.removeClassStartingWith(ATTR_SIZE_DASH);
        attributesWithClass.removeClassStartingWith(ATTR_IMAGE_WP_DASH);
        if (!TextUtils.isEmpty(metaData.getCaption())) {
          AztecAttributes captionAttributes=CaptionExtensionsKt.getImageCaptionAttributes(content,mTappedMediaPredicate);
          if (!TextUtils.isEmpty(metaData.getAlign())) {
            captionAttributes.setValue(ATTR_ALIGN,ATTR_ALIGN + metaData.getAlign());
          }
 else {
            captionAttributes.removeAttribute(ATTR_ALIGN);
          }
          captionAttributes.setValue(ATTR_DIMEN_WIDTH,metaData.getWidth());
          CaptionExtensionsKt.setImageCaption(content,mTappedMediaPredicate,metaData.getCaption(),captionAttributes);
          List<IAztecAttributedSpan> tappedImageSpan=getSpansForPredicate(content.getEditableText(),mTappedMediaPredicate,true);
          if (tappedImageSpan.size() > 0) {
            int imageSpanEnd=content.getEditableText().getSpanEnd(tappedImageSpan.get(0));
            CaptionShortcodeSpan[] captions=content.getEditableText().getSpans(imageSpanEnd,imageSpanEnd,CaptionShortcodeSpan.class);
            if (captions.length > 0) {
              int captionStart=content.getEditableText().getSpanStart(captions[0]);
              int captionEnd=content.getEditableText().getSpanEnd(captions[0]);
              int captionFlags=content.getEditableText().getSpanFlags(captions[0]);
              if (content.getEditableText().charAt(captionEnd - 1) == '\n') {
                captionEnd--;
              }
              String expectedString="String_Node_Str" + metaData.getCaption();
              CharSequence actualContent=content.getEditableText().subSequence(imageSpanEnd,captionEnd);
              if (captionEnd == imageSpanEnd + expectedString.length() && actualContent.toString().equals(expectedString)) {
                content.disableTextChangedListener();
                content.getEditableText().delete(imageSpanEnd,imageSpanEnd + 1);
                content.getEditableText().setSpan(captions[0],captionStart,captionEnd - 1,captionFlags);
                content.enableTextChangedListener();
                content.fromHtml(content.toHtml(false));
              }
            }
          }
        }
 else {
          if (!TextUtils.isEmpty(metaData.getAlign())) {
            attributesWithClass.addClass(ATTR_ALIGN + metaData.getAlign());
          }
          CaptionExtensionsKt.removeImageCaption(content,mTappedMediaPredicate);
        }
        if (!TextUtils.isEmpty(metaData.getSize())) {
          attributesWithClass.addClass(metaData.getSize());
        }
        if (!TextUtils.isEmpty(metaData.getAttachmentId())) {
          attributesWithClass.addClass(ATTR_IMAGE_WP_DASH + metaData.getAttachmentId());
        }
        attributes.setValue(ATTR_CLASS,attributesWithClass.getAttributes().getValue(ATTR_CLASS));
        attributes.removeAttribute(TEMP_IMAGE_ID);
        content.updateElementAttributes(mTappedMediaPredicate,attributes);
      }
      mTappedMediaPredicate=null;
      if (isHistoryEnabled()) {
        content.history.handleHistory(content);
      }
    }
  }
}

Fixed version (ground truth):
@Override public void onActivityResult(int requestCode,int resultCode,Intent data){
  super.onActivityResult(requestCode,resultCode,data);
  if (requestCode == EDITOR_MEDIA_SETTINGS) {
    if (mTappedMediaPredicate != null) {
      if (data == null || data.getExtras() == null) {
        return;
      }
      EditorImageMetaData metaData=data.getParcelableExtra(ARG_EDITOR_IMAGE_METADATA);
      if (metaData.isRemoved()) {
        String editorContentBeforeImageIsRemoved="String_Node_Str";
        if (isHistoryEnabled()) {
          editorContentBeforeImageIsRemoved=content.toFormattedHtml();
        }
        CaptionExtensionsKt.removeImageCaption(content,mTappedMediaPredicate);
        content.removeMedia(mTappedMediaPredicate);
        if (isHistoryEnabled()) {
          content.history.beforeTextChanged(editorContentBeforeImageIsRemoved);
        }
      }
 else {
        if (isHistoryEnabled()) {
          content.history.beforeTextChanged(content.toFormattedHtml());
        }
        AztecAttributes attributes=content.getElementAttributes(mTappedMediaPredicate);
        attributes.setValue(ATTR_SRC,metaData.getSrc());
        if (!TextUtils.isEmpty(metaData.getTitle())) {
          attributes.setValue(ATTR_TITLE,metaData.getTitle());
        }
 else {
          attributes.removeAttribute(ATTR_TITLE);
        }
        if (!TextUtils.isEmpty(metaData.getAlt())) {
          attributes.setValue(ATTR_ALT,metaData.getAlt());
        }
 else {
          attributes.removeAttribute(ATTR_ALT);
        }
        attributes.setValue(ATTR_DIMEN_WIDTH,metaData.getWidth());
        attributes.setValue(ATTR_DIMEN_HEIGHT,metaData.getHeight());
        if (!TextUtils.isEmpty(metaData.getLinkUrl())) {
          AztecAttributes linkAttributes=MediaLinkExtensionsKt.getMediaLinkAttributes(content,mTappedMediaPredicate);
          linkAttributes.setValue("String_Node_Str","String_Node_Str");
          linkAttributes.removeAttribute("String_Node_Str");
          if (metaData.isLinkTargetBlank()) {
            linkAttributes.setValue(ATTR_TARGET,"String_Node_Str");
          }
 else {
            linkAttributes.removeAttribute(ATTR_TARGET);
          }
          MediaLinkExtensionsKt.addLinkToMedia(content,mTappedMediaPredicate,UrlUtils.addUrlSchemeIfNeeded(metaData.getLinkUrl(),false),linkAttributes);
        }
 else {
          MediaLinkExtensionsKt.removeLinkFromMedia(content,mTappedMediaPredicate);
        }
        AttributesWithClass attributesWithClass=getAttributesWithClass(attributes);
        attributesWithClass.removeClassStartingWith(ATTR_ALIGN);
        attributesWithClass.removeClassStartingWith(ATTR_SIZE_DASH);
        attributesWithClass.removeClassStartingWith(ATTR_IMAGE_WP_DASH);
        if (!TextUtils.isEmpty(metaData.getCaption())) {
          AztecAttributes captionAttributes=CaptionExtensionsKt.getImageCaptionAttributes(content,mTappedMediaPredicate);
          if (!TextUtils.isEmpty(metaData.getAlign())) {
            captionAttributes.setValue(ATTR_ALIGN,ATTR_ALIGN + metaData.getAlign());
          }
 else {
            captionAttributes.removeAttribute(ATTR_ALIGN);
          }
          captionAttributes.setValue(ATTR_DIMEN_WIDTH,metaData.getWidth());
          CaptionExtensionsKt.setImageCaption(content,mTappedMediaPredicate,metaData.getCaption(),captionAttributes);
          content.fromHtml(content.toHtml(false));
        }
 else {
          if (!TextUtils.isEmpty(metaData.getAlign())) {
            attributesWithClass.addClass(ATTR_ALIGN + metaData.getAlign());
          }
          CaptionExtensionsKt.removeImageCaption(content,mTappedMediaPredicate);
        }
        if (!TextUtils.isEmpty(metaData.getSize())) {
          attributesWithClass.addClass(metaData.getSize());
        }
        if (!TextUtils.isEmpty(metaData.getAttachmentId())) {
          attributesWithClass.addClass(ATTR_IMAGE_WP_DASH + metaData.getAttachmentId());
        }
        attributes.setValue(ATTR_CLASS,attributesWithClass.getAttributes().getValue(ATTR_CLASS));
        attributes.removeAttribute(TEMP_IMAGE_ID);
        content.updateElementAttributes(mTappedMediaPredicate,attributes);
      }
      mTappedMediaPredicate=null;
      if (isHistoryEnabled()) {
        content.history.handleHistory(content);
      }
    }
  }
}