Program: 18337
Project: 18337
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);
    if (!apiModel.getRef().equals(serviceModel.getParentRef())) {
      session.move(serviceModel.getRef(),apiModel.getRef(),null);
    }
    int newCallcount;
    try {
      newCallcount=Integer.parseInt((String)serviceModel.getProperty(Service.SCHEMA,Service.PROP_CALLCOUNT));
    }
 catch (    Exception e) {
      newCallcount=0;
    }
    try {
      newCallcount+=(properties.get(Service.PROP_CALLCOUNT) != null) ? Integer.parseInt(properties.get(Service.PROP_CALLCOUNT)) : 0;
    }
 catch (    NumberFormatException e) {
    }
    properties.put(Service.PROP_CALLCOUNT,Integer.toString(newCallcount));
    setPropertiesIfNotNull(serviceModel,Service.SCHEMA,Service.getPropertyList(),properties);
    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);
    if (!apiModel.getRef().equals(serviceModel.getParentRef())) {
      session.move(serviceModel.getRef(),apiModel.getRef(),null);
    }
    properties.put(Service.PROP_CALLCOUNT,getNewCallcount(serviceModel,Long.parseLong(properties.get(Service.PROP_CALLCOUNT))));
    setPropertiesIfNotNull(serviceModel,Service.SCHEMA,Service.getPropertyList(),properties);
    session.saveDocument(serviceModel);
    session.save();
    return serviceModel;
  }
 else {
    throw new ClientException("String_Node_Str");
  }
}