Program: 18209
Project: 18209
Buggy source:
@Override public void handleEvent(Event event) throws ClientException {
  EventContext context=event.getContext();
  if (!(context instanceof DocumentEventContext)) {
    return;
  }
  DocumentEventContext documentContext=(DocumentEventContext)context;
  DocumentModel sourceDocument=documentContext.getSourceDocument();
  if (!sourceDocument.hasFacet("String_Node_Str")) {
    return;
  }
  try {
    CoreSession documentManager=documentContext.getCoreSession();
    DocumentService documentService=Framework.getService(DocumentService.class);
    String sourceFolderPath=documentService.getSourceFolderPath(sourceDocument.getType());
    DocumentModel parentModel=documentManager.getDocument(sourceDocument.getParentRef());
    if (!sourceDocument.isProxy() && !sourceDocument.getPathAsString().startsWith(sourceFolderPath) || sourceDocument.isProxy() && parentModel.hasFacet(SoaNode.FACET) && !sourceDocument.getPathAsString().startsWith(Repository.REPOSITORY_PATH)) {
      documentService.ensureSourceFolderExists(documentManager,sourceDocument.getType());
      String soaName=(String)sourceDocument.getPropertyValue(SoaNode.XPATH_SOANAME);
      if (soaName == null || soaName.isEmpty()) {
        sourceDocument.setPropertyValue(SoaNode.XPATH_SOANAME,sourceDocument.getName());
      }
      PathRef sourcePathRef=new PathRef(documentService.getSourcePath(documentService.createSoaNodeId(sourceDocument)));
      DocumentModel repositoryDocument;
      if (documentManager.exists(sourcePathRef)) {
        repositoryDocument=documentManager.getDocument(sourcePathRef);
        repositoryDocument.copyContent(sourceDocument);
        documentManager.saveDocument(repositoryDocument);
        documentManager.save();
        documentManager.removeDocument(sourceDocument.getRef());
      }
 else {
        repositoryDocument=documentManager.move(sourceDocument.getRef(),new PathRef(sourceFolderPath),sourceDocument.getName());
      }
      if (documentService.isSoaNode(documentManager,parentModel.getType())) {
        parentModel=documentService.find(documentManager,documentService.createSoaNodeId(parentModel));
      }
      documentManager.createProxy(repositoryDocument.getRef(),parentModel.getRef());
    }
    documentManager.save();
    IntelligentSystemTreeService intelligentSystemTreeServiceCache=Framework.getService(IntelligentSystemTreeService.class);
    intelligentSystemTreeServiceCache.handleDocumentModel(documentManager,sourceDocument,!DocumentEventTypes.DOCUMENT_CREATED.equals(event.getName()));
    documentManager.save();
  }
 catch (  Exception e) {
    logger.error("String_Node_Str",e);
  }
}

Fixed version (ground truth):
@Override public void handleEvent(Event event) throws ClientException {
  EventContext context=event.getContext();
  if (!(context instanceof DocumentEventContext)) {
    return;
  }
  DocumentEventContext documentContext=(DocumentEventContext)context;
  DocumentModel sourceDocument=documentContext.getSourceDocument();
  if (!sourceDocument.hasFacet("String_Node_Str")) {
    return;
  }
  try {
    CoreSession documentManager=documentContext.getCoreSession();
    DocumentService documentService=Framework.getService(DocumentService.class);
    String sourceFolderPath=documentService.getSourceFolderPath(sourceDocument.getType());
    DocumentModel parentModel=documentManager.getDocument(sourceDocument.getParentRef());
    if (!sourceDocument.isProxy() && !parentModel.getPathAsString().equals(sourceFolderPath) || sourceDocument.isProxy() && parentModel.hasFacet(SoaNode.FACET) && !sourceDocument.getPathAsString().startsWith(Repository.REPOSITORY_PATH)) {
      documentService.ensureSourceFolderExists(documentManager,sourceDocument.getType());
      String soaName=(String)sourceDocument.getPropertyValue(SoaNode.XPATH_SOANAME);
      if (soaName == null || soaName.isEmpty()) {
        sourceDocument.setPropertyValue(SoaNode.XPATH_SOANAME,sourceDocument.getName());
      }
      PathRef sourcePathRef=new PathRef(documentService.getSourcePath(documentService.createSoaNodeId(sourceDocument)));
      DocumentModel repositoryDocument;
      if (documentManager.exists(sourcePathRef)) {
        repositoryDocument=documentManager.getDocument(sourcePathRef);
        repositoryDocument.copyContent(sourceDocument);
        documentManager.saveDocument(repositoryDocument);
        documentManager.save();
        documentManager.removeDocument(sourceDocument.getRef());
      }
 else {
        repositoryDocument=documentManager.move(sourceDocument.getRef(),new PathRef(sourceFolderPath),sourceDocument.getName());
      }
      if (documentService.isSoaNode(documentManager,parentModel.getType())) {
        parentModel=documentService.find(documentManager,documentService.createSoaNodeId(parentModel));
      }
      documentManager.createProxy(repositoryDocument.getRef(),parentModel.getRef());
    }
    documentManager.save();
    IntelligentSystemTreeService intelligentSystemTreeServiceCache=Framework.getService(IntelligentSystemTreeService.class);
    intelligentSystemTreeServiceCache.handleDocumentModel(documentManager,sourceDocument,!DocumentEventTypes.DOCUMENT_CREATED.equals(event.getName()));
    documentManager.save();
  }
 catch (  Exception e) {
    logger.error("String_Node_Str",e);
  }
}