Program: 18325
Project: 18325
Buggy source:
/** 
 * Creates or update an API given the specified properties. Properties require at least application's URL (PROP_URL) ; the parent document URL (PROP_PARENTURL) is also recommended if known.
 * @param session
 * @param properties A set of properties of the document, among the ServiceAPI.PROP_XXX constants.
 * @return The created/updated API
 * @throws ClientException
 * @throws MalformedURLException 
 */
public final DocumentModel notifyServiceApi(CoreSession session,Map<String,String> properties) throws ClientException, MalformedURLException {
  String url=properties.get(Service.PROP_URL);
  if (url != null && !url.isEmpty()) {
    String parentUrl=properties.get(ServiceAPI.PROP_PARENTURL), title=properties.get("String_Node_Str");
    if (title == null || title.isEmpty()) {
      title=url;
      properties.put("String_Node_Str",title);
    }
    DocumentService docService=Framework.getRuntime().getService(DocumentService.class);
    DocumentModel parentModel=docService.findServiceApi(session,parentUrl);
    if (parentModel == null)     parentModel=docService.findAppliImpl(session,parentUrl);
    if (parentModel == null) {
      if (parentUrl == null) {
        parentModel=docService.getDefaultAppliImpl(session);
      }
 else {
        parentModel=docService.createAppliImpl(session,parentUrl);
      }
      session.save();
    }
    DocumentModel apiModel=docService.findServiceApi(session,url);
    if (apiModel == null) {
      apiModel=docService.createServiceAPI(session,parentModel.getPathAsString(),url);
    }
    if (!parentModel.getRef().equals(apiModel.getParentRef())) {
      apiModel=session.move(apiModel.getRef(),parentModel.getRef(),null);
    }
    if (url.toLowerCase().contains("String_Node_Str")) {
      try {
        HttpFile f=new HttpFile(new URL(url));
        f.download();
        apiModel.setProperty("String_Node_Str","String_Node_Str",f.getBlob());
      }
 catch (      Exception e) {
        throw new ClientException("String_Node_Str",e);
      }
    }
    setPropertiesIfNotNull(apiModel,ServiceAPI.SCHEMA,ServiceAPI.getPropertyList(),properties);
    session.saveDocument(apiModel);
    session.save();
    return apiModel;
  }
 else {
    throw new ClientException("String_Node_Str");
  }
}

Fixed version (ground truth):
/** 
 * Creates or update an API given the specified properties. Properties require at least application's URL (PROP_URL) ; the parent document URL (PROP_PARENTURL) is also recommended if known.
 * @param session
 * @param properties A set of properties of the document, among the ServiceAPI.PROP_XXX constants.
 * @return The created/updated API
 * @throws ClientException
 * @throws MalformedURLException 
 */
public final DocumentModel notifyServiceApi(CoreSession session,Map<String,String> properties) throws ClientException, MalformedURLException {
  String url=properties.get(Service.PROP_URL);
  if (url != null && !url.isEmpty()) {
    String parentUrl=properties.get(ServiceAPI.PROP_PARENTURL), title=properties.get("String_Node_Str");
    if (title == null || title.isEmpty()) {
      title=url;
      properties.put("String_Node_Str",title);
    }
    DocumentService docService=Framework.getRuntime().getService(DocumentService.class);
    DocumentModel parentModel=docService.findAppliImpl(session,parentUrl);
    if (parentModel == null) {
      parentModel=docService.findServiceApi(session,parentUrl);
    }
    if (parentModel == null) {
      if (parentUrl == null) {
        parentModel=docService.getDefaultAppliImpl(session);
      }
 else {
        parentModel=docService.createAppliImpl(session,parentUrl);
      }
      session.save();
    }
    DocumentModel apiModel=docService.findServiceApi(session,url);
    if (apiModel == null) {
      apiModel=docService.createServiceAPI(session,parentModel.getPathAsString(),url);
    }
    if (!parentModel.getRef().equals(apiModel.getParentRef())) {
      apiModel=session.move(apiModel.getRef(),parentModel.getRef(),null);
    }
    if (url.toLowerCase().contains("String_Node_Str")) {
      try {
        HttpFile f=new HttpFile(new URL(url));
        f.download();
        apiModel.setProperty("String_Node_Str","String_Node_Str",f.getBlob());
      }
 catch (      Exception e) {
        throw new ClientException("String_Node_Str",e);
      }
    }
    setPropertiesIfNotNull(apiModel,ServiceAPI.SCHEMA,ServiceAPI.getPropertyList(),properties);
    session.saveDocument(apiModel);
    session.save();
    return apiModel;
  }
 else {
    throw new ClientException("String_Node_Str");
  }
}