Program: 118502
Project: 118502
Buggy source:
/** 
 * DOC ycbai Comment method "loadParametersFromForm". <p> Get element parameters of <code>element</code> from <code>form</code>.
 * @param node optional, used if there is a component setting up the properties
 * @param element
 * @param category
 * @param form
 * @return parameters list
 */
private static List<ElementParameter> getParametersFromForm(IElement element,EComponentCategory category,ComponentProperties rootProperty,ComponentProperties compProperties,String parentPropertiesPath,Form form,Widget parentWidget,AtomicInteger lastRowNum){
  List<ElementParameter> elementParameters=new ArrayList<>();
  List<String> parameterNames=new ArrayList<>();
  EComponentCategory compCategory=category;
  if (compCategory == null) {
    compCategory=EComponentCategory.BASIC;
  }
  AtomicInteger lastRN=lastRowNum;
  if (lastRN == null) {
    lastRN=new AtomicInteger();
  }
  if (form == null) {
    return elementParameters;
  }
  ComponentProperties componentProperties=compProperties;
  if (componentProperties == null) {
    componentProperties=(ComponentProperties)form.getProperties();
  }
  if (element instanceof INode) {
    INode node=(INode)element;
    if (node.getComponentProperties() == null) {
      node.setComponentProperties(componentProperties);
    }
  }
  componentProperties.setValueEvaluator(null);
  Collection<Widget> formWidgets=form.getWidgets();
  for (  Widget widget : formWidgets) {
    NamedThing widgetProperty=widget.getContent();
    String propertiesPath=getPropertiesPath(parentPropertiesPath,null);
    if (widgetProperty instanceof Form) {
      Form subForm=(Form)widgetProperty;
      ComponentProperties subProperties=(ComponentProperties)subForm.getProperties();
      if (!isSameComponentProperties(componentProperties,widgetProperty)) {
        propertiesPath=getPropertiesPath(parentPropertiesPath,subProperties.getName());
      }
      elementParameters.addAll(getParametersFromForm(element,compCategory,rootProperty,subProperties,propertiesPath,subForm,widget,lastRN));
      continue;
    }
    GenericElementParameter param=new GenericElementParameter(element,rootProperty,form,widget,getComponentService());
    String parameterName=propertiesPath.concat(param.getName());
    param.setName(parameterName);
    param.setCategory(compCategory);
    param.setShow(parentWidget == null ? !widget.isHidden() : !parentWidget.isHidden() && !widget.isHidden());
    int rowNum=0;
    if (widget.getOrder() != 1) {
      rowNum=lastRN.get();
    }
 else {
      rowNum=widget.getRow();
      if (parentWidget != null) {
        rowNum+=parentWidget.getRow();
      }
      rowNum=rowNum + lastRN.get();
    }
    param.setNumRow(rowNum);
    lastRN.set(rowNum);
    EParameterFieldType fieldType=getFieldType(widget,widgetProperty);
    param.setFieldType(fieldType != null ? fieldType : EParameterFieldType.TEXT);
    if (widgetProperty instanceof SchemaProperty) {
      boolean found=false;
      param.setContext(EConnectionType.FLOW_MAIN.getName());
      for (      Connector connector : rootProperty.getAvailableConnectors(null,true)) {
        if (!(((SchemaProperty)widgetProperty).getValue() instanceof Schema)) {
          continue;
        }
        if (connector instanceof PropertyPathConnector) {
          String linkedSchema=((PropertyPathConnector)connector).getPropertyPath() + "String_Node_Str";
          if (parameterName.equals(linkedSchema)) {
            found=true;
            param.setContext(connector.getName());
            IElementParameterDefaultValue defaultValue=new ElementParameterDefaultValue();
            Schema schema=(Schema)((SchemaProperty)widgetProperty).getValue();
            defaultValue.setDefaultValue(new Schema.Parser().parse(schema.toString()));
            param.getDefaultValues().add(defaultValue);
          }
        }
      }
      if (!found) {
        for (        Connector connector : rootProperty.getAvailableConnectors(null,false)) {
          if (!(((SchemaProperty)widgetProperty).getValue() instanceof Schema)) {
            continue;
          }
          if (connector instanceof PropertyPathConnector) {
            String linkedSchema=((PropertyPathConnector)connector).getPropertyPath() + "String_Node_Str";
            if (parameterName.equals(linkedSchema)) {
              if (GenericNodeConnector.INPUT_CONNECTOR.equals(connector.getName())) {
                param.setContext(EConnectionType.FLOW_MAIN.getName());
              }
 else {
                param.setContext(connector.getName());
              }
              IElementParameterDefaultValue defaultValue=new ElementParameterDefaultValue();
              Schema schema=(Schema)((SchemaProperty)widgetProperty).getValue();
              defaultValue.setDefaultValue(new Schema.Parser().parse(schema.toString()));
              param.getDefaultValues().add(defaultValue);
            }
          }
        }
      }
    }
    if (widgetProperty instanceof PresentationItem) {
      param.setValue(widgetProperty.getDisplayName());
    }
 else     if (widgetProperty instanceof Property) {
      Property property=(Property)widgetProperty;
      param.setRequired(property.isRequired());
      param.setValue(getParameterValue(element,property));
      param.setSupportContext(isSupportContext(property));
      List<?> values=property.getPossibleValues();
      if (values != null || (fieldType != null && fieldType.equals(EParameterFieldType.CLOSED_LIST))) {
        if (values == null) {
          values=Collections.emptyList();
        }
        param.setPossibleValues(values);
        List<String> possVals=new ArrayList<>();
        List<String> possValsDisplay=new ArrayList<>();
        for (        Object obj : values) {
          if (obj instanceof NamedThing) {
            NamedThing nal=(NamedThing)obj;
            possVals.add(nal.getName());
            possValsDisplay.add(nal.getDisplayName());
          }
 else {
            possVals.add(String.valueOf(obj));
            possValsDisplay.add(String.valueOf(obj));
          }
        }
        param.setListItemsDisplayName(possValsDisplay.toArray(new String[0]));
        param.setListItemsDisplayCodeName(possValsDisplay.toArray(new String[0]));
        param.setListItemsValue(possVals.toArray(new String[0]));
      }
    }
 else     if (fieldType != null && fieldType.equals(EParameterFieldType.TABLE) && widgetProperty instanceof Properties) {
      Properties table=(Properties)widgetProperty;
      Form mainForm=table.getForm(Form.MAIN);
      param.setDisplayName(mainForm.getTitle());
      List<ElementParameter> parameters=getParametersFromForm(new FakeElement("String_Node_Str"),mainForm);
      param.setSupportContext(false);
      List<String> codeNames=new ArrayList<>();
      List<String> possValsDisplay=new ArrayList<>();
      for (      ElementParameter curParam : parameters) {
        curParam.setFilter(null);
        curParam.setContext(null);
        curParam.setShowIf(null);
        curParam.setNotShowIf(null);
        curParam.setReadOnlyIf(null);
        curParam.setNotReadOnlyIf(null);
        curParam.setNoContextAssist(false);
        curParam.setRaw(false);
        curParam.setReadOnly(false);
        codeNames.add(curParam.getName());
        possValsDisplay.add(curParam.getDisplayName());
      }
      param.setListItemsDisplayName(possValsDisplay.toArray(new String[0]));
      param.setListItemsDisplayCodeName(codeNames.toArray(new String[0]));
      param.setListItemsValue(parameters.toArray(new ElementParameter[0]));
      String[] listItemsShowIf=new String[parameters.size()];
      String[] listItemsNotShowIf=new String[parameters.size()];
      param.setListItemsShowIf(listItemsShowIf);
      param.setListItemsNotShowIf(listItemsNotShowIf);
      param.setValue(GenericTableUtils.getTableValues(table,param));
    }
    param.setReadOnly(false);
    param.setSerialized(true);
    param.setDynamicSettings(true);
    if (!parameterNames.contains(parameterName)) {
      elementParameters.add(param);
      parameterNames.add(parameterName);
    }
  }
  return elementParameters;
}

Fixed version (ground truth):
/** 
 * DOC ycbai Comment method "loadParametersFromForm". <p> Get element parameters of <code>element</code> from <code>form</code>.
 * @param node optional, used if there is a component setting up the properties
 * @param element
 * @param category
 * @param form
 * @return parameters list
 */
private static List<ElementParameter> getParametersFromForm(IElement element,EComponentCategory category,ComponentProperties rootProperty,ComponentProperties compProperties,String parentPropertiesPath,Form form,Widget parentWidget,AtomicInteger lastRowNum){
  List<ElementParameter> elementParameters=new ArrayList<>();
  List<String> parameterNames=new ArrayList<>();
  EComponentCategory compCategory=category;
  if (compCategory == null) {
    compCategory=EComponentCategory.BASIC;
  }
  AtomicInteger lastRN=lastRowNum;
  if (lastRN == null) {
    lastRN=new AtomicInteger();
  }
  if (form == null) {
    return elementParameters;
  }
  ComponentProperties componentProperties=compProperties;
  if (componentProperties == null) {
    componentProperties=(ComponentProperties)form.getProperties();
  }
  if (element instanceof INode) {
    INode node=(INode)element;
    if (node.getComponentProperties() == null) {
      node.setComponentProperties(componentProperties);
    }
  }
  componentProperties.setValueEvaluator(null);
  Collection<Widget> formWidgets=form.getWidgets();
  for (  Widget widget : formWidgets) {
    NamedThing widgetProperty=widget.getContent();
    String propertiesPath=getPropertiesPath(parentPropertiesPath,null);
    if (widgetProperty instanceof Form) {
      Form subForm=(Form)widgetProperty;
      ComponentProperties subProperties=(ComponentProperties)subForm.getProperties();
      if (!isSameComponentProperties(componentProperties,widgetProperty)) {
        propertiesPath=getPropertiesPath(parentPropertiesPath,subProperties.getName());
      }
      elementParameters.addAll(getParametersFromForm(element,compCategory,rootProperty,subProperties,propertiesPath,subForm,widget,lastRN));
      continue;
    }
    GenericElementParameter param=new GenericElementParameter(element,rootProperty,form,widget,getComponentService());
    String parameterName=propertiesPath.concat(param.getName());
    param.setName(parameterName);
    param.setCategory(compCategory);
    param.setShow(parentWidget == null ? !widget.isHidden() : !parentWidget.isHidden() && !widget.isHidden());
    int rowNum=0;
    if (widget.getOrder() != 1) {
      rowNum=lastRN.get();
    }
 else {
      rowNum=widget.getRow();
      if (parentWidget != null) {
        rowNum+=parentWidget.getRow();
      }
      rowNum=rowNum + lastRN.get();
    }
    param.setNumRow(rowNum);
    lastRN.set(rowNum);
    EParameterFieldType fieldType=getFieldType(widget,widgetProperty);
    param.setFieldType(fieldType != null ? fieldType : EParameterFieldType.TEXT);
    if (widgetProperty instanceof SchemaProperty) {
      boolean found=false;
      param.setContext(EConnectionType.FLOW_MAIN.getName());
      for (      Connector connector : rootProperty.getAvailableConnectors(null,true)) {
        if (!(((SchemaProperty)widgetProperty).getValue() instanceof Schema)) {
          continue;
        }
        if (connector instanceof PropertyPathConnector) {
          String linkedSchema=((PropertyPathConnector)connector).getPropertyPath() + "String_Node_Str";
          if (parameterName.equals(linkedSchema)) {
            found=true;
            param.setContext(connector.getName());
            IElementParameterDefaultValue defaultValue=new ElementParameterDefaultValue();
            Schema schema=(Schema)((SchemaProperty)widgetProperty).getValue();
            defaultValue.setDefaultValue(new Schema.Parser().parse(schema.toString()));
            param.getDefaultValues().add(defaultValue);
          }
        }
      }
      if (!found) {
        for (        Connector connector : rootProperty.getAvailableConnectors(null,false)) {
          if (!(((SchemaProperty)widgetProperty).getValue() instanceof Schema)) {
            continue;
          }
          if (connector instanceof PropertyPathConnector) {
            String linkedSchema=((PropertyPathConnector)connector).getPropertyPath() + "String_Node_Str";
            if (parameterName.equals(linkedSchema)) {
              if (GenericNodeConnector.INPUT_CONNECTOR.equals(connector.getName())) {
                param.setContext(EConnectionType.FLOW_MAIN.getName());
              }
 else {
                param.setContext(connector.getName());
              }
              IElementParameterDefaultValue defaultValue=new ElementParameterDefaultValue();
              Schema schema=(Schema)((SchemaProperty)widgetProperty).getValue();
              defaultValue.setDefaultValue(new Schema.Parser().parse(schema.toString()));
              param.getDefaultValues().add(defaultValue);
            }
          }
        }
      }
    }
    if (widgetProperty instanceof PresentationItem) {
      param.setValue(widgetProperty.getDisplayName());
    }
 else     if (widgetProperty instanceof Property) {
      Property property=(Property)widgetProperty;
      param.setRequired(property.isRequired());
      param.setValue(getParameterValue(element,property));
      if (EParameterFieldType.NAME_SELECTION_AREA.equals(fieldType)) {
        param.setSupportContext(false);
      }
 else {
        param.setSupportContext(isSupportContext(property));
      }
      property.setTaggedValue(IComponentConstants.SUPPORT_CONTEXT,param.isSupportContext());
      List<?> values=property.getPossibleValues();
      if (values != null || EParameterFieldType.CLOSED_LIST.equals(fieldType)) {
        if (values == null) {
          values=Collections.emptyList();
        }
        param.setPossibleValues(values);
        List<String> possVals=new ArrayList<>();
        List<String> possValsDisplay=new ArrayList<>();
        for (        Object obj : values) {
          if (obj instanceof NamedThing) {
            NamedThing nal=(NamedThing)obj;
            possVals.add(nal.getName());
            possValsDisplay.add(nal.getDisplayName());
          }
 else {
            possVals.add(String.valueOf(obj));
            possValsDisplay.add(String.valueOf(obj));
          }
        }
        param.setListItemsDisplayName(possValsDisplay.toArray(new String[0]));
        param.setListItemsDisplayCodeName(possValsDisplay.toArray(new String[0]));
        param.setListItemsValue(possVals.toArray(new String[0]));
      }
    }
 else     if (fieldType != null && fieldType.equals(EParameterFieldType.TABLE) && widgetProperty instanceof Properties) {
      Properties table=(Properties)widgetProperty;
      Form mainForm=table.getForm(Form.MAIN);
      param.setDisplayName(mainForm.getTitle());
      List<ElementParameter> parameters=getParametersFromForm(new FakeElement("String_Node_Str"),mainForm);
      param.setSupportContext(false);
      List<String> codeNames=new ArrayList<>();
      List<String> possValsDisplay=new ArrayList<>();
      for (      ElementParameter curParam : parameters) {
        curParam.setFilter(null);
        curParam.setContext(null);
        curParam.setShowIf(null);
        curParam.setNotShowIf(null);
        curParam.setReadOnlyIf(null);
        curParam.setNotReadOnlyIf(null);
        curParam.setNoContextAssist(false);
        curParam.setRaw(false);
        curParam.setReadOnly(false);
        codeNames.add(curParam.getName());
        possValsDisplay.add(curParam.getDisplayName());
      }
      param.setListItemsDisplayName(possValsDisplay.toArray(new String[0]));
      param.setListItemsDisplayCodeName(codeNames.toArray(new String[0]));
      param.setListItemsValue(parameters.toArray(new ElementParameter[0]));
      String[] listItemsShowIf=new String[parameters.size()];
      String[] listItemsNotShowIf=new String[parameters.size()];
      param.setListItemsShowIf(listItemsShowIf);
      param.setListItemsNotShowIf(listItemsNotShowIf);
      param.setValue(GenericTableUtils.getTableValues(table,param));
    }
    param.setReadOnly(false);
    param.setSerialized(true);
    param.setDynamicSettings(true);
    if (!parameterNames.contains(parameterName)) {
      elementParameters.add(param);
      parameterNames.add(parameterName);
    }
  }
  return elementParameters;
}