Program: 18333
Project: 18333
Buggy source:
/** 
 * Creates or update a Service given the specified properties. Properties require at least application's URL (PROP_URL) and parent API URL (PROP_PARENTURL). If parent API is unknown, you can use the   {@link #computeApiUrl} function.
 * @param session
 * @param properties A set of properties of the document, among the Service.PROP_XXX constants.
 * @return The created/updated Service
 * @throws ClientException
 * @throws MalformedURLException 
 */
public final DocumentModel notifyService(CoreSession session,Map<String,String> properties) throws ClientException, MalformedURLException {
  if (properties.get(Service.PROP_URL) != null) {
    String url=properties.get(Service.PROP_URL), parentUrl=properties.get(Service.PROP_PARENTURL);
    if (parentUrl == null) {
      parentUrl=computeApiUrl(url);
    }
    DocumentService docService=Framework.getRuntime().getService(DocumentService.class);
    DocumentModel apiModel=docService.findServiceApi(session,parentUrl);
    if (apiModel == null) {
      apiModel=docService.createServiceAPI(session,null,parentUrl);
      String serviceTitle=properties.get(Service.PROP_URL);
      if (serviceTitle != null) {
        apiModel.setProperty("String_Node_Str","String_Node_Str",serviceTitle + "String_Node_Str");
      }
      session.saveDocument(apiModel);
      session.save();
    }
    DocumentModel serviceModel=docService.findService(session,url);
    if (serviceModel == null)     serviceModel=docService.createService(session,apiModel.getPathAsString(),url);
    setPropertiesIfNotNull(serviceModel,Service.SCHEMA,Service.getPropertyList(),properties);
    properties.put(Service.PROP_CALLCOUNT,getNewCallcount(serviceModel,properties.get(Service.PROP_CALLCOUNT)));
    if (!apiModel.getRef().equals(serviceModel.getParentRef())) {
      serviceModel=session.move(serviceModel.getRef(),apiModel.getRef(),null);
    }
    session.saveDocument(serviceModel);
    session.save();
    return serviceModel;
  }
 else {
    throw new ClientException("String_Node_Str");
  }
}

Fixed version (ground truth):
/** 
 * Creates or update a Service given the specified properties. Properties require at least application's URL (PROP_URL) and parent API URL (PROP_PARENTURL). If parent API is unknown, you can use the   {@link #computeApiUrl} function.
 * @param session
 * @param properties A set of properties of the document, among the Service.PROP_XXX constants.
 * @return The created/updated Service
 * @throws ClientException
 * @throws MalformedURLException 
 */
public final DocumentModel notifyService(CoreSession session,Map<String,String> properties) throws ClientException, MalformedURLException {
  if (properties.get(Service.PROP_URL) != null) {
    String url=properties.get(Service.PROP_URL), parentUrl=properties.get(Service.PROP_PARENTURL);
    if (parentUrl == null) {
      parentUrl=computeApiUrl(url);
    }
    DocumentService docService=Framework.getRuntime().getService(DocumentService.class);
    DocumentModel apiModel=docService.findServiceApi(session,parentUrl);
    if (apiModel == null) {
      apiModel=docService.createServiceAPI(session,null,parentUrl);
      String serviceTitle=properties.get(Service.PROP_URL);
      if (serviceTitle != null) {
        apiModel.setProperty("String_Node_Str","String_Node_Str",serviceTitle + "String_Node_Str");
      }
      session.saveDocument(apiModel);
      session.save();
    }
    DocumentModel serviceModel=docService.findService(session,url);
    if (serviceModel == null)     serviceModel=docService.createService(session,apiModel.getPathAsString(),url);
    properties.put(Service.PROP_CALLCOUNT,getNewCallcount(serviceModel,properties.get(Service.PROP_CALLCOUNT)));
    setPropertiesIfNotNull(serviceModel,Service.SCHEMA,Service.getPropertyList(),properties);
    if (!apiModel.getRef().equals(serviceModel.getParentRef())) {
      serviceModel=session.move(serviceModel.getRef(),apiModel.getRef(),null);
    }
    session.saveDocument(serviceModel);
    session.save();
    return serviceModel;
  }
 else {
    throw new ClientException("String_Node_Str");
  }
}