Program: 18307
Project: 18307
Buggy source:
public void handleEvent(Event event){
  EventContext ctx=event.getContext();
  if (!(ctx instanceof DocumentEventContext)) {
    return;
  }
  CoreSession session=ctx.getCoreSession();
  DocumentModel doc=((DocumentEventContext)ctx).getSourceDocument();
  if (doc == null) {
    return;
  }
  String type=doc.getType();
  if (!type.equals(DOCTYPE) || doc.isProxy()) {
    return;
  }
  try {
    String title=(String)doc.getProperty("String_Node_Str","String_Node_Str");
    String url=(String)doc.getProperty(SCHEMA,PROP_URL);
    String fileUrl=(String)doc.getProperty(SCHEMA,PROP_FILEURL);
    if (fileUrl == null) {
      fileUrl=guessFileUrl(url);
    }
    if (fileUrl != null) {
      try {
        Blob blob=downloadBlob(fileUrl);
        if (blob == null && fileUrl != null && !fileUrl.equals(guessFileUrl(url))) {
          blob=downloadBlob(guessFileUrl(url));
        }
        if (blob != null) {
          doc.setProperty("String_Node_Str","String_Node_Str",blob);
          doc.setProperty("String_Node_Str","String_Node_Str",ApiUrlProcessor.computeServiceTitle(fileUrl) + "String_Node_Str");
          File tmpFile=File.createTempFile(doc.getId(),null);
          blob.transferTo(tmpFile);
          try {
            WSDLReader reader=WSDLFactory.newInstance().newWSDLReader();
            Description desc=reader.read(tmpFile.toURI().toURL());
            org.ow2.easywsdl.wsdl.api.Service firstService=(org.ow2.easywsdl.wsdl.api.Service)desc.getServices().get(0);
            String namespace=desc.getTargetNamespace();
            doc.setProperty(Service.SCHEMA,Service.PROP_WSDLNAMESPACE,namespace);
            Endpoint firstEndpoint=firstService.getEndpoints().get(0);
            url=PropertyNormalizer.normalizeUrl(firstEndpoint.getAddress());
            doc.setProperty(SCHEMA,PROP_URL,url);
            String serviceName=firstService.getQName().getLocalPart();
            doc.setProperty(Service.SCHEMA,Service.PROP_WSDLSERVICENAME,serviceName);
            if (title == null || title.isEmpty() || title.equals(fileUrl)) {
              doc.setProperty("String_Node_Str","String_Node_Str",serviceName);
            }
            if (doc.getParentRef() != null) {
              DocumentModel apiModel=session.getDocument(doc.getParentRef());
              String storedProtocol=(String)apiModel.getProperty(ServiceAPI.SCHEMA,ServiceAPI.PROP_PROTOCOLS);
              try {
                String protocol=((Binding)((Endpoint)firstService.getEndpoints().get(0)).getBinding()).getTransportProtocol();
                if (storedProtocol == null || !storedProtocol.contains(protocol)) {
                  if (storedProtocol == null || storedProtocol.isEmpty()) {
                    apiModel.setProperty(ServiceAPI.SCHEMA,ServiceAPI.PROP_PROTOCOLS,protocol);
                  }
 else {
                    apiModel.setProperty(ServiceAPI.SCHEMA,ServiceAPI.PROP_PROTOCOLS,storedProtocol + "String_Node_Str" + protocol);
                  }
                }
              }
 catch (              Exception e) {
                log.warn("String_Node_Str" + e.getMessage());
              }
              if (apiModel.getParentRef() != null) {
                DocumentModel appliImplModel=session.getDocument(apiModel.getParentRef());
                String existingServer=(String)appliImplModel.getProperty(AppliImpl.SCHEMA,AppliImpl.PROP_SERVER);
                String newServer=InetAddress.getByName(new URL(firstEndpoint.getAddress()).getHost()).getHostAddress();
                if (existingServer == null || !newServer.equals(existingServer)) {
                  appliImplModel.setProperty(AppliImpl.SCHEMA,AppliImpl.PROP_SERVER,newServer);
                }
                try {
                  String provider=new URL(((Endpoint)firstService.getEndpoints().get(0)).getAddress()).getAuthority();
                  String existingProvider=(String)appliImplModel.getProperty(AppliImpl.SCHEMA,AppliImpl.PROP_PROVIDER);
                  if (existingProvider == null || !provider.equals(existingProvider)) {
                    appliImplModel.setProperty(AppliImpl.SCHEMA,AppliImpl.PROP_PROVIDER,provider);
                  }
                }
 catch (                Exception e) {
                }
                session.saveDocument(appliImplModel);
              }
              session.saveDocument(apiModel);
            }
          }
 catch (          Exception e) {
            log.warn("String_Node_Str" + e.getMessage());
          }
 finally {
            tmpFile.delete();
          }
        }
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
    }
    session.save();
    if (url != null) {
      try {
        doc.setProperty(SCHEMA,PROP_URL,PropertyNormalizer.normalizeUrl(url));
      }
 catch (      MalformedURLException e) {
        log.warn("String_Node_Str",e);
      }
    }
    if (fileUrl != null) {
      if (fileUrl.contains("String_Node_Str")) {
        doc.setProperty(SCHEMA,PROP_FILEURL,"String_Node_Str" + EasySOAConstants.HTML_FORM_GENERATOR_PORT + "String_Node_Str");
      }
 else {
        doc.setProperty(SCHEMA,PROP_FILEURL,PropertyNormalizer.normalizeUrl(fileUrl));
      }
    }
    String referencedService=(String)doc.getProperty(SCHEMA,PROP_REFERENCESERVICE);
    if (referencedService == null || !session.exists(new IdRef(referencedService))) {
      DocumentModel newReferenceService=null;
      ServiceValidationService validationService=Framework.getService(ServiceValidationService.class);
      SortedSet<CorrelationMatch> correlatedServices=validationService.findCorrelatedServices(session,doc);
      if (correlatedServices != null && !correlatedServices.isEmpty() && correlatedServices.first().getCorrelationRate() > 0.9) {
        newReferenceService=correlatedServices.first().getDocumentModel();
        doc.setProperty(SCHEMA,PROP_REFERENCESERVICE,newReferenceService.getId());
        doc.setProperty(SCHEMA,PROP_REFERENCESERVICEORIGIN,"String_Node_Str" + correlatedServices.first().getCorrelationRateAsPercentageString() + "String_Node_Str");
      }
 else {
        doc.setProperty(SCHEMA,PROP_REFERENCESERVICE,null);
      }
    }
    DocumentModel oldDoc=session.getDocument(doc.getRef());
    Object wasDirty=oldDoc.getProperty(Service.SCHEMA,Service.PROP_VALIDATIONSTATEDIRTY);
    if (wasDirty == null || wasDirty.equals(doc.getProperty(Service.SCHEMA,Service.PROP_VALIDATIONSTATEDIRTY))) {
      doc.setProperty(Service.SCHEMA,Service.PROP_VALIDATIONSTATEDIRTY,true);
    }
    try {
      DocumentService docService=Framework.getService(DocumentService.class);
      DocumentModel workspace=docService.getWorkspace(session,doc);
      DocumentModelList existingServiceModels=session.query("String_Node_Str" + Service.DOCTYPE + "String_Node_Str"+ "String_Node_Str"+ workspace.getPathAsString()+ "String_Node_Str"+ Service.SCHEMA_PREFIX+ Service.PROP_URL+ "String_Node_Str"+ url+ "String_Node_Str");
      for (      DocumentModel existingServiceModel : existingServiceModels) {
        if (existingServiceModel != null && !existingServiceModel.getRef().equals(doc.getRef()) && !existingServiceModel.isProxy()) {
          docService.mergeDocument(session,existingServiceModel,doc,false);
        }
      }
    }
 catch (    Exception e) {
      log.error("String_Node_Str",e);
    }
  }
 catch (  Exception e) {
    log.error(e);
  }
}

Fixed version (ground truth):
public void handleEvent(Event event){
  EventContext ctx=event.getContext();
  if (!(ctx instanceof DocumentEventContext)) {
    return;
  }
  CoreSession session=ctx.getCoreSession();
  DocumentModel doc=((DocumentEventContext)ctx).getSourceDocument();
  if (doc == null) {
    return;
  }
  String type=doc.getType();
  if (!type.equals(DOCTYPE) || doc.isProxy()) {
    return;
  }
  try {
    String title=(String)doc.getProperty("String_Node_Str","String_Node_Str");
    String url=(String)doc.getProperty(SCHEMA,PROP_URL);
    String fileUrl=(String)doc.getProperty(SCHEMA,PROP_FILEURL);
    if (fileUrl == null) {
      fileUrl=guessFileUrl(url);
    }
    if (fileUrl != null) {
      try {
        Blob blob=downloadBlob(fileUrl);
        if (blob == null && fileUrl != null && !fileUrl.equals(guessFileUrl(url))) {
          blob=downloadBlob(guessFileUrl(url));
        }
        if (blob != null) {
          doc.setProperty("String_Node_Str","String_Node_Str",blob);
          doc.setProperty("String_Node_Str","String_Node_Str",ApiUrlProcessor.computeServiceTitle(fileUrl) + "String_Node_Str");
          File tmpFile=File.createTempFile(doc.getId(),null);
          blob.transferTo(tmpFile);
          try {
            WSDLReader reader=WSDLFactory.newInstance().newWSDLReader();
            Description desc=reader.read(tmpFile.toURI().toURL());
            org.ow2.easywsdl.wsdl.api.Service firstService=(org.ow2.easywsdl.wsdl.api.Service)desc.getServices().get(0);
            String namespace=desc.getTargetNamespace();
            doc.setProperty(Service.SCHEMA,Service.PROP_WSDLNAMESPACE,namespace);
            Endpoint firstEndpoint=firstService.getEndpoints().get(0);
            url=PropertyNormalizer.normalizeUrl(firstEndpoint.getAddress());
            doc.setProperty(SCHEMA,PROP_URL,url);
            String serviceName=firstService.getQName().getLocalPart();
            doc.setProperty(Service.SCHEMA,Service.PROP_WSDLSERVICENAME,serviceName);
            if (title == null || title.isEmpty() || title.equals(fileUrl)) {
              doc.setProperty("String_Node_Str","String_Node_Str",serviceName);
            }
            if (doc.getParentRef() != null) {
              DocumentModel apiModel=session.getDocument(doc.getParentRef());
              String storedProtocol=(String)apiModel.getProperty(ServiceAPI.SCHEMA,ServiceAPI.PROP_PROTOCOLS);
              try {
                String protocol=((Binding)((Endpoint)firstService.getEndpoints().get(0)).getBinding()).getTransportProtocol();
                if (storedProtocol == null || !storedProtocol.contains(protocol)) {
                  if (storedProtocol == null || storedProtocol.isEmpty()) {
                    apiModel.setProperty(ServiceAPI.SCHEMA,ServiceAPI.PROP_PROTOCOLS,protocol);
                  }
 else {
                    apiModel.setProperty(ServiceAPI.SCHEMA,ServiceAPI.PROP_PROTOCOLS,storedProtocol + "String_Node_Str" + protocol);
                  }
                }
              }
 catch (              Exception e) {
                log.warn("String_Node_Str" + e.getMessage());
              }
              if (apiModel.getParentRef() != null) {
                DocumentModel appliImplModel=session.getDocument(apiModel.getParentRef());
                String existingServer=(String)appliImplModel.getProperty(AppliImpl.SCHEMA,AppliImpl.PROP_SERVER);
                String newServer=InetAddress.getByName(new URL(firstEndpoint.getAddress()).getHost()).getHostAddress();
                if (existingServer == null || !newServer.equals(existingServer)) {
                  appliImplModel.setProperty(AppliImpl.SCHEMA,AppliImpl.PROP_SERVER,newServer);
                }
                try {
                  String provider=new URL(((Endpoint)firstService.getEndpoints().get(0)).getAddress()).getAuthority();
                  String existingProvider=(String)appliImplModel.getProperty(AppliImpl.SCHEMA,AppliImpl.PROP_PROVIDER);
                  if (existingProvider == null || !provider.equals(existingProvider)) {
                    appliImplModel.setProperty(AppliImpl.SCHEMA,AppliImpl.PROP_PROVIDER,provider);
                  }
                }
 catch (                Exception e) {
                }
                session.saveDocument(appliImplModel);
              }
              session.saveDocument(apiModel);
            }
          }
 catch (          Exception e) {
            log.warn("String_Node_Str" + e.getMessage());
          }
 finally {
            tmpFile.delete();
          }
        }
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
    }
    session.save();
    if (url != null) {
      try {
        doc.setProperty(SCHEMA,PROP_URL,PropertyNormalizer.normalizeUrl(url));
      }
 catch (      MalformedURLException e) {
        log.warn("String_Node_Str",e);
      }
    }
    if (fileUrl != null) {
      if (fileUrl.contains("String_Node_Str")) {
        doc.setProperty(SCHEMA,PROP_FILEURL,"String_Node_Str" + EasySOAConstants.HTML_FORM_GENERATOR_PORT + "String_Node_Str");
      }
 else {
        doc.setProperty(SCHEMA,PROP_FILEURL,PropertyNormalizer.normalizeUrl(fileUrl));
      }
    }
    String referencedService=(String)doc.getProperty(SCHEMA,PROP_REFERENCESERVICE);
    if (referencedService == null || !session.exists(new IdRef(referencedService))) {
      DocumentModel newReferenceService=null;
      ServiceValidationService validationService=Framework.getService(ServiceValidationService.class);
      SortedSet<CorrelationMatch> correlatedServices=validationService.findCorrelatedServices(session,doc);
      if (correlatedServices != null && !correlatedServices.isEmpty() && correlatedServices.first().getCorrelationRate() > 0.9) {
        newReferenceService=correlatedServices.first().getDocumentModel();
        doc.setProperty(SCHEMA,PROP_REFERENCESERVICE,newReferenceService.getId());
        doc.setProperty(SCHEMA,PROP_REFERENCESERVICEORIGIN,"String_Node_Str" + correlatedServices.first().getCorrelationRateAsPercentageString() + "String_Node_Str");
      }
 else {
        doc.setProperty(SCHEMA,PROP_REFERENCESERVICE,null);
      }
    }
    DocumentModel oldDoc=session.getDocument(doc.getRef());
    Object wasDirty=oldDoc.getProperty(Service.SCHEMA,Service.PROP_VALIDATIONSTATEDIRTY);
    if (wasDirty == null || wasDirty.equals(doc.getProperty(Service.SCHEMA,Service.PROP_VALIDATIONSTATEDIRTY))) {
      doc.setProperty(Service.SCHEMA,Service.PROP_VALIDATIONSTATEDIRTY,true);
    }
    try {
      DocumentService docService=Framework.getService(DocumentService.class);
      DocumentModel workspace=docService.getWorkspace(session,doc);
      DocumentModelList existingServiceModels=session.query("String_Node_Str" + Service.DOCTYPE + "String_Node_Str"+ "String_Node_Str"+ workspace.getPathAsString()+ "String_Node_Str"+ Service.SCHEMA_PREFIX+ Service.PROP_URL+ "String_Node_Str"+ url+ "String_Node_Str"+ "String_Node_Str");
      for (      DocumentModel existingServiceModel : existingServiceModels) {
        if (existingServiceModel != null && !existingServiceModel.getRef().equals(doc.getRef()) && !existingServiceModel.isProxy()) {
          docService.mergeDocument(session,existingServiceModel,doc,false);
        }
      }
    }
 catch (    Exception e) {
      log.error("String_Node_Str",e);
    }
  }
 catch (  Exception e) {
    log.error(e);
  }
}