Program: 13574
Project: 13574
Buggy source:
private void createInsertAttachmentButton(ToolbarView toolbar,final ParticipantId user){
  String encodedToken=HistorySupport.getToken();
  WaveRef waveRef=null;
  if (encodedToken != null && !encodedToken.isEmpty()) {
    waveRef=HistorySupport.waveRefFromHistoryToken(encodedToken);
  }
  Preconditions.checkState(waveRef != null);
  final String waveRefToken=URL.encode(GwtWaverefEncoder.encodeToUriQueryString(waveRef));
  new ToolbarButtonViewBuilder().setIcon(css.insertAttachment()).setTooltip("String_Node_Str").applyTo(toolbar.addClickButton(),new ToolbarClickButton.Listener(){
    @Override public void onClicked(){
      int tmpCursor=-1;
      FocusedRange focusedRange=editor.getSelectionHelper().getSelectionRange();
      if (focusedRange != null) {
        tmpCursor=focusedRange.getFocus();
      }
      final int cursorLoc=tmpCursor;
      AttachmentPopupView attachmentView=new AttachmentPopupWidget();
      attachmentView.init(new Listener(){
        @Override public void onShow(){
        }
        @Override public void onHide(){
        }
        @Override public void onDone(        String encodedWaveRef,        String attachmentId,        String fullFileName){
          int lastSlashPos=fullFileName.lastIndexOf("String_Node_Str");
          int lastBackSlashPos=fullFileName.lastIndexOf("String_Node_Str");
          String fileName=fullFileName;
          if (lastSlashPos != -1) {
            fileName=fullFileName.substring(lastSlashPos + 1,fullFileName.length());
          }
 else           if (lastBackSlashPos != -1) {
            fileName=fullFileName.substring(lastBackSlashPos + 1,fullFileName.length());
          }
          XmlStringBuilder xml=XmlStringBuilder.createFromXmlString(fileName);
          int to=-1;
          int docSize=editor.getDocument().size();
          if (cursorLoc != -1) {
            CMutableDocument doc=editor.getDocument();
            Point<ContentNode> point=doc.locate(cursorLoc);
            doc.insertXml(point,xml);
          }
 else {
            LineContainers.appendLine(editor.getDocument(),xml);
          }
          to=cursorLoc + editor.getDocument().size() - docSize;
          String linkValue=GWT.getHostPageBaseURL() + "String_Node_Str" + attachmentId+ "String_Node_Str"+ fileName+ "String_Node_Str"+ encodedWaveRef;
          EditorAnnotationUtil.setAnnotationOverRange(editor.getDocument(),editor.getCaretAnnotations(),Link.KEY,linkValue,cursorLoc,to);
          EditorAnnotationUtil.setAnnotationOverRange(editor.getDocument(),editor.getCaretAnnotations(),"String_Node_Str",attachmentId,cursorLoc,to);
          EditorAnnotationUtil.setAnnotationOverRange(editor.getDocument(),editor.getCaretAnnotations(),"String_Node_Str",fileName,cursorLoc,to);
        }
      }
);
      attachmentView.setAttachmentId(attachmentIdGenerator.newAttachmentId());
      attachmentView.setWaveRef(waveRefToken);
      attachmentView.show();
    }
  }
);
}

Fixed version (ground truth):
private void createInsertAttachmentButton(ToolbarView toolbar,final ParticipantId user){
  WaveRef waveRef=WaveRef.of(waveId);
  Preconditions.checkState(waveRef != null);
  final String waveRefToken=URL.encode(GwtWaverefEncoder.encodeToUriQueryString(waveRef));
  new ToolbarButtonViewBuilder().setIcon(css.insertAttachment()).setTooltip("String_Node_Str").applyTo(toolbar.addClickButton(),new ToolbarClickButton.Listener(){
    @Override public void onClicked(){
      int tmpCursor=-1;
      FocusedRange focusedRange=editor.getSelectionHelper().getSelectionRange();
      if (focusedRange != null) {
        tmpCursor=focusedRange.getFocus();
      }
      final int cursorLoc=tmpCursor;
      AttachmentPopupView attachmentView=new AttachmentPopupWidget();
      attachmentView.init(new Listener(){
        @Override public void onShow(){
        }
        @Override public void onHide(){
        }
        @Override public void onDone(        String encodedWaveRef,        String attachmentId,        String fullFileName){
          int lastSlashPos=fullFileName.lastIndexOf("String_Node_Str");
          int lastBackSlashPos=fullFileName.lastIndexOf("String_Node_Str");
          String fileName=fullFileName;
          if (lastSlashPos != -1) {
            fileName=fullFileName.substring(lastSlashPos + 1,fullFileName.length());
          }
 else           if (lastBackSlashPos != -1) {
            fileName=fullFileName.substring(lastBackSlashPos + 1,fullFileName.length());
          }
          XmlStringBuilder xml=XmlStringBuilder.createFromXmlString(fileName);
          int to=-1;
          int docSize=editor.getDocument().size();
          if (cursorLoc != -1) {
            CMutableDocument doc=editor.getDocument();
            Point<ContentNode> point=doc.locate(cursorLoc);
            doc.insertXml(point,xml);
          }
 else {
            LineContainers.appendLine(editor.getDocument(),xml);
          }
          to=cursorLoc + editor.getDocument().size() - docSize;
          String linkValue=GWT.getHostPageBaseURL() + "String_Node_Str" + attachmentId+ "String_Node_Str"+ fileName+ "String_Node_Str"+ encodedWaveRef;
          EditorAnnotationUtil.setAnnotationOverRange(editor.getDocument(),editor.getCaretAnnotations(),Link.KEY,linkValue,cursorLoc,to);
          EditorAnnotationUtil.setAnnotationOverRange(editor.getDocument(),editor.getCaretAnnotations(),"String_Node_Str",attachmentId,cursorLoc,to);
          EditorAnnotationUtil.setAnnotationOverRange(editor.getDocument(),editor.getCaretAnnotations(),"String_Node_Str",fileName,cursorLoc,to);
        }
      }
);
      attachmentView.setAttachmentId(attachmentIdGenerator.newAttachmentId());
      attachmentView.setWaveRef(waveRefToken);
      attachmentView.show();
    }
  }
);
}