Program: 118863
Project: 118863
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
 */
public static List<ElementParameter> getParametersFromForm(IElement element,EComponentCategory category,Form form,ElementParameter parentParam,AtomicInteger lastRowNum){
  List<ElementParameter> elementParameters=new ArrayList<>();
  if (category == null) {
    category=EComponentCategory.BASIC;
  }
  if (lastRowNum == null) {
    lastRowNum=new AtomicInteger();
  }
  if (form == null) {
    return elementParameters;
  }
  ComponentProperties compProperties=form.getProperties();
  if (element instanceof INode) {
    INode node=(INode)element;
    if (node.getComponentProperties() == null) {
      node.setComponentProperties(compProperties);
    }
  }
  compProperties.getProperties();
  List<Widget> formWidgets=form.getWidgets();
  for (  Widget widget : formWidgets) {
    NamedThing[] widgetProperties=widget.getProperties();
    NamedThing widgetProperty=widgetProperties[0];
    GenericElementParameter param=new GenericElementParameter(element,compProperties,widget,getComponentService());
    if (parentParam != null) {
      param.setParentParameter(parentParam);
    }
    param.setCategory(category);
    param.setRepositoryValue(widgetProperty.getName());
    if (parentParam != null) {
    }
    param.setShow(parentParam == null ? widget.isVisible() : parentParam.isShow(null) && widget.isVisible());
    int rowNum=0;
    if (widget.getOrder() != 1) {
      rowNum=lastRowNum.get();
    }
 else {
      rowNum=widget.getRow();
      if (parentParam != null) {
        rowNum+=parentParam.getNumRow();
      }
      rowNum=rowNum + lastRowNum.get();
    }
    param.setNumRow(rowNum);
    lastRowNum.set(rowNum);
    if (widgetProperty instanceof Form) {
      elementParameters.addAll(getParametersFromForm(element,category,(Form)widgetProperty,param,lastRowNum));
      continue;
    }
    SchemaElement se=null;
    if (widgetProperty instanceof SchemaElement) {
      se=(SchemaElement)widgetProperties[0];
      param.setContext("String_Node_Str");
    }
    EParameterFieldType fieldType=null;
switch (widget.getWidgetType()) {
case DEFAULT:
      if (se == null) {
        fieldType=EParameterFieldType.LABEL;
        param.setValue(widgetProperty.getDisplayName());
        break;
      }
switch (se.getType()) {
case BOOLEAN:
      fieldType=EParameterFieldType.CHECK;
    break;
case BYTE_ARRAY:
  fieldType=EParameterFieldType.TEXT;
break;
case DATE:
fieldType=EParameterFieldType.DATE;
break;
case DATETIME:
fieldType=EParameterFieldType.DATE;
break;
case DECIMAL:
fieldType=EParameterFieldType.TEXT;
break;
case DOUBLE:
fieldType=EParameterFieldType.TEXT;
break;
case DYNAMIC:
fieldType=EParameterFieldType.TEXT;
break;
case ENUM:
fieldType=EParameterFieldType.CLOSED_LIST;
break;
case FLOAT:
fieldType=EParameterFieldType.TEXT;
break;
case INT:
fieldType=EParameterFieldType.TEXT;
break;
case SCHEMA:
fieldType=EParameterFieldType.SCHEMA_TYPE;
break;
case STRING:
fieldType=EParameterFieldType.TEXT;
break;
default :
fieldType=EParameterFieldType.TEXT;
break;
}
break;
case BUTTON:
fieldType=EParameterFieldType.BUTTON;
break;
case COMPONENT_REFERENCE:
fieldType=EParameterFieldType.COMPONENT_REFERENCE;
break;
case NAME_SELECTION_AREA:
fieldType=EParameterFieldType.NAME_SELECTION_AREA;
break;
case NAME_SELECTION_REFERENCE:
fieldType=EParameterFieldType.NAME_SELECTION_REFERENCE;
break;
case SCHEMA_EDITOR:
break;
case SCHEMA_REFERENCE:
fieldType=EParameterFieldType.SCHEMA_TYPE;
break;
default :
break;
}
param.setFieldType(fieldType != null ? fieldType : EParameterFieldType.TEXT);
if (se != null) {
param.setRequired(se.isRequired());
param.setValue(compProperties.getValue(se));
List<?> values=se.getPossibleValues();
if (values != null) {
param.setPossibleValues(values);
List<String> possVals=new ArrayList<>();
List<String> possValsDisplay=new ArrayList<>();
for (Object obj : values) {
if (obj instanceof NameAndLabel) {
NameAndLabel nal=(NameAndLabel)obj;
possVals.add(nal.getName());
possValsDisplay.add(nal.getLabel());
}
 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 (widgetProperty instanceof PresentationItem) {
param.setValue(null);
}
param.setReadOnly(false);
param.setSerialized(true);
elementParameters.add(param);
}
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
 */
public static List<ElementParameter> getParametersFromForm(IElement element,EComponentCategory category,ComponentProperties compProperties,Form form,ElementParameter parentParam,AtomicInteger lastRowNum){
  List<ElementParameter> elementParameters=new ArrayList<>();
  if (category == null) {
    category=EComponentCategory.BASIC;
  }
  if (lastRowNum == null) {
    lastRowNum=new AtomicInteger();
  }
  if (form == null) {
    return elementParameters;
  }
  if (compProperties == null) {
    compProperties=form.getProperties();
  }
  if (element instanceof INode) {
    INode node=(INode)element;
    if (node.getComponentProperties() == null) {
      node.setComponentProperties(compProperties);
    }
  }
  compProperties.getProperties();
  List<Widget> formWidgets=form.getWidgets();
  for (  Widget widget : formWidgets) {
    NamedThing[] widgetProperties=widget.getProperties();
    NamedThing widgetProperty=widgetProperties[0];
    GenericElementParameter param=new GenericElementParameter(element,compProperties,widget,getComponentService());
    if (parentParam != null) {
      param.setParentParameter(parentParam);
    }
    param.setCategory(category);
    param.setRepositoryValue(widgetProperty.getName());
    if (parentParam != null) {
    }
    param.setShow(parentParam == null ? widget.isVisible() : parentParam.isShow(null) && widget.isVisible());
    int rowNum=0;
    if (widget.getOrder() != 1) {
      rowNum=lastRowNum.get();
    }
 else {
      rowNum=widget.getRow();
      if (parentParam != null) {
        rowNum+=parentParam.getNumRow();
      }
      rowNum=rowNum + lastRowNum.get();
    }
    param.setNumRow(rowNum);
    lastRowNum.set(rowNum);
    if (widgetProperty instanceof Form) {
      Form subForm=(Form)widgetProperty;
      ComponentProperties subProperties=subForm.getProperties();
      subProperties=(ComponentProperties)compProperties.getProperty(subProperties.getClass());
      elementParameters.addAll(getParametersFromForm(element,category,subProperties,subForm,param,lastRowNum));
      continue;
    }
    SchemaElement se=null;
    if (widgetProperty instanceof SchemaElement) {
      se=(SchemaElement)widgetProperties[0];
      param.setContext("String_Node_Str");
    }
    EParameterFieldType fieldType=null;
switch (widget.getWidgetType()) {
case DEFAULT:
      if (se == null) {
        fieldType=EParameterFieldType.LABEL;
        param.setValue(widgetProperty.getDisplayName());
        break;
      }
switch (se.getType()) {
case BOOLEAN:
      fieldType=EParameterFieldType.CHECK;
    break;
case BYTE_ARRAY:
  fieldType=EParameterFieldType.TEXT;
break;
case DATE:
fieldType=EParameterFieldType.DATE;
break;
case DATETIME:
fieldType=EParameterFieldType.DATE;
break;
case DECIMAL:
fieldType=EParameterFieldType.TEXT;
break;
case DOUBLE:
fieldType=EParameterFieldType.TEXT;
break;
case DYNAMIC:
fieldType=EParameterFieldType.TEXT;
break;
case ENUM:
fieldType=EParameterFieldType.CLOSED_LIST;
break;
case FLOAT:
fieldType=EParameterFieldType.TEXT;
break;
case INT:
fieldType=EParameterFieldType.TEXT;
break;
case SCHEMA:
fieldType=EParameterFieldType.SCHEMA_TYPE;
break;
case STRING:
fieldType=EParameterFieldType.TEXT;
break;
default :
fieldType=EParameterFieldType.TEXT;
break;
}
break;
case BUTTON:
fieldType=EParameterFieldType.BUTTON;
break;
case COMPONENT_REFERENCE:
fieldType=EParameterFieldType.COMPONENT_REFERENCE;
break;
case NAME_SELECTION_AREA:
fieldType=EParameterFieldType.NAME_SELECTION_AREA;
break;
case NAME_SELECTION_REFERENCE:
fieldType=EParameterFieldType.NAME_SELECTION_REFERENCE;
break;
case SCHEMA_EDITOR:
break;
case SCHEMA_REFERENCE:
fieldType=EParameterFieldType.SCHEMA_TYPE;
break;
default :
break;
}
param.setFieldType(fieldType != null ? fieldType : EParameterFieldType.TEXT);
if (se != null) {
se=compProperties.getProperty(se.getName());
param.setRequired(se.isRequired());
param.setValue(compProperties.getValue(se));
List<?> values=se.getPossibleValues();
if (values != null) {
param.setPossibleValues(values);
List<String> possVals=new ArrayList<>();
List<String> possValsDisplay=new ArrayList<>();
for (Object obj : values) {
if (obj instanceof NameAndLabel) {
NameAndLabel nal=(NameAndLabel)obj;
possVals.add(nal.getName());
possValsDisplay.add(nal.getLabel());
}
 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 (widgetProperty instanceof PresentationItem) {
param.setValue(null);
}
param.setReadOnly(false);
param.setSerialized(true);
elementParameters.add(param);
}
return elementParameters;
}