Program: 118621
Project: 118621
Buggy source:
/** 
 * Set the values to default if needed.
 * @param currentParam Current parameter that has been modified in the interface
 * @param testedParam Tested parameter, to know if there is a link for the default values between this parameter andthe current.
 */
private void setDefaultValues(IElementParameter currentParam,IElementParameter testedParam,IElement referenceNode){
  List<? extends IElementParameter> elementParameters=referenceNode.getElementParameters();
  if (elementParameters == null) {
    return;
  }
  boolean contains=false;
  for (  IElementParameterDefaultValue value : testedParam.getDefaultValues()) {
    if (value.getIfCondition() != null) {
      if (value.getIfCondition().contains(currentParam.getName())) {
        contains=true;
        break;
      }
    }
    if (value.getNotIfCondition() != null) {
      if (value.getNotIfCondition().contains(currentParam.getName())) {
        contains=true;
        break;
      }
    }
  }
  if (!contains && testedParam.getFieldType().equals(EParameterFieldType.CLOSED_LIST)) {
    boolean isCurrentComboValid=true;
    if (testedParam.getListItemsShowIf() != null || testedParam.getListItemsNotShowIf() != null) {
      String value=(String)testedParam.getValue();
      int index=ArrayUtils.indexOf(testedParam.getListItemsValue(),value);
      if (index != -1) {
        if (testedParam.getListItemsShowIf() != null) {
          String conditionShowIf=testedParam.getListItemsShowIf()[index];
          if (conditionShowIf != null) {
            isCurrentComboValid=Expression.evaluate(conditionShowIf,elementParameters);
          }
        }
        if (testedParam.getListItemsNotShowIf() != null) {
          String conditionNotShowIf=testedParam.getListItemsNotShowIf()[index];
          if (conditionNotShowIf != null) {
            isCurrentComboValid=!Expression.evaluate(conditionNotShowIf,elementParameters);
          }
        }
      }
    }
    if (!isCurrentComboValid && testedParam.getListItemsShowIf() != null) {
      for (      String condition : testedParam.getListItemsShowIf()) {
        if (condition != null && condition.contains(currentParam.getName())) {
          boolean isValid=Expression.evaluate(condition,elementParameters);
          if (isValid) {
            int index=ArrayUtils.indexOf(testedParam.getListItemsShowIf(),condition);
            testedParam.setValue(testedParam.getListItemsValue()[index]);
            break;
          }
        }
      }
    }
    if (!isCurrentComboValid && !contains && testedParam.getListItemsNotShowIf() != null) {
      for (      String condition : testedParam.getListItemsNotShowIf()) {
        if (condition != null && condition.contains(currentParam.getName())) {
          boolean isValid=!Expression.evaluate(condition,elementParameters);
          if (isValid) {
            int index=ArrayUtils.indexOf(testedParam.getListItemsNotShowIf(),condition);
            testedParam.setValue(testedParam.getListItemsValue()[index]);
            break;
          }
        }
 else         if (condition == null) {
          int index=ArrayUtils.indexOf(testedParam.getListItemsNotShowIf(),condition);
          testedParam.setValue(testedParam.getListItemsValue()[index]);
          break;
        }
      }
    }
  }
 else   if (testedParam.getDefaultValues().size() > 0 && contains) {
    oldElementValues.put(testedParam,testedParam.getValue());
    if (!testedParam.getFieldType().equals(EParameterFieldType.SCHEMA_TYPE)) {
      String oldMapping="String_Node_Str";
      if (!testedParam.getFieldType().equals(EParameterFieldType.CHECK) && !testedParam.getFieldType().equals(EParameterFieldType.RADIO)) {
        oldMapping=(String)testedParam.getValue();
      }
      testedParam.setValueToDefault(elementParameters);
      if (testedParam.getFieldType().equals(EParameterFieldType.MAPPING_TYPE)) {
        String newMapping=(String)testedParam.getValue();
        if (!oldMapping.equals(newMapping)) {
          Node node=(Node)referenceNode;
          if (node.getMetadataList().size() > 0) {
            IMetadataTable metadataTable=node.getMetadataList().get(0);
            metadataTable.setDbms(newMapping);
          }
        }
      }
    }
 else {
      Node node=(Node)referenceNode;
      if (node.getMetadataList().size() > 0) {
        IMetadataTable metadataTable=null;
        IMetadataTable newMetadataTable=null;
        boolean isBuiltIn=false;
        final IElementParameter elementParameter=testedParam.getChildParameters().get(EParameterFieldType.SCHEMA_TYPE.getName());
        if (elementParameter != null) {
          Object value=elementParameter.getValue();
          if ("String_Node_Str".equals(value.toString())) {
            isBuiltIn=true;
          }
        }
        if (isBuiltIn || elementParameter == null) {
          metadataTable=node.getMetadataFromConnector(testedParam.getContext());
          testedParam.setValueToDefault(node.getElementParameters());
          newMetadataTable=((IMetadataTable)testedParam.getValue()).clone(true);
          if (metadataTable != null && newMetadataTable != null) {
            newMetadataTable.setTableName(metadataTable.getTableName());
            newMetadataTable.setAttachedConnector(metadataTable.getAttachedConnector());
            boolean needClearTargetTable=newMetadataTable.getListColumns().isEmpty();
            if (!needClearTargetTable) {
              needClearTargetTable=false;
              for (              IMetadataColumn column : newMetadataTable.getListColumns()) {
                if (!column.isCustom()) {
                  needClearTargetTable=true;
                  break;
                }
              }
            }
            if (needClearTargetTable) {
              metadataTable.getListColumns().clear();
            }
            List<IMetadataColumn> columnsToRemove=new ArrayList<IMetadataColumn>();
            for (            IMetadataColumn column : metadataTable.getListColumns()) {
              if (column.isCustom() || column.isReadOnly()) {
                columnsToRemove.add(column);
              }
            }
            metadataTable.getListColumns().removeAll(columnsToRemove);
            boolean onlyHaveCustomInDefault=true;
            List<IMetadataColumn> customColumnsFromDefault=new ArrayList<IMetadataColumn>();
            for (            IMetadataColumn column : newMetadataTable.getListColumns()) {
              if (!column.isCustom() && !column.isReadOnly()) {
                onlyHaveCustomInDefault=false;
              }
 else {
                customColumnsFromDefault.add(column);
              }
            }
            metadataTable.getListColumns().addAll(customColumnsFromDefault);
            if (onlyHaveCustomInDefault) {
              metadataTable.setReadOnly(newMetadataTable.isReadOnly());
              newMetadataTable=metadataTable;
            }
            ChangeMetadataCommand changeMetadataCommand=new ChangeMetadataCommand(node,null,null,newMetadataTable);
            changeMetadataCommands.add(changeMetadataCommand);
            changeMetadataCommand.execute(true);
          }
        }
 else {
          metadataTable=node.getMetadataFromConnector(testedParam.getContext());
          if (testedParam.getName().equals("String_Node_Str")) {
            newMetadataTable=metadataTable;
          }
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Set the values to default if needed.
 * @param currentParam Current parameter that has been modified in the interface
 * @param testedParam Tested parameter, to know if there is a link for the default values between this parameter andthe current.
 */
private void setDefaultValues(IElementParameter currentParam,IElementParameter testedParam,IElement referenceNode){
  List<? extends IElementParameter> elementParameters=referenceNode.getElementParameters();
  if (elementParameters == null) {
    return;
  }
  boolean contains=false;
  for (  IElementParameterDefaultValue value : testedParam.getDefaultValues()) {
    if (value.getIfCondition() != null) {
      if (value.getIfCondition().contains(currentParam.getName())) {
        contains=true;
        break;
      }
    }
    if (value.getNotIfCondition() != null) {
      if (value.getNotIfCondition().contains(currentParam.getName())) {
        contains=true;
        break;
      }
    }
  }
  if (!contains && testedParam.getFieldType().equals(EParameterFieldType.CLOSED_LIST)) {
    boolean isCurrentComboValid=true;
    if (testedParam.getListItemsShowIf() != null || testedParam.getListItemsNotShowIf() != null) {
      String value=(String)testedParam.getValue();
      int index=ArrayUtils.indexOf(testedParam.getListItemsValue(),value);
      if (index != -1) {
        if (testedParam.getListItemsShowIf() != null) {
          String conditionShowIf=testedParam.getListItemsShowIf()[index];
          if (conditionShowIf != null) {
            isCurrentComboValid=Expression.evaluate(conditionShowIf,elementParameters);
          }
        }
        if (testedParam.getListItemsNotShowIf() != null) {
          String conditionNotShowIf=testedParam.getListItemsNotShowIf()[index];
          if (conditionNotShowIf != null) {
            isCurrentComboValid=!Expression.evaluate(conditionNotShowIf,elementParameters);
          }
        }
      }
    }
    if (!isCurrentComboValid && testedParam.getListItemsShowIf() != null) {
      for (      String condition : testedParam.getListItemsShowIf()) {
        if (condition != null && condition.contains(currentParam.getName())) {
          boolean isValid=Expression.evaluate(condition,elementParameters);
          if (isValid) {
            int index=ArrayUtils.indexOf(testedParam.getListItemsShowIf(),condition);
            testedParam.setValue(testedParam.getListItemsValue()[index]);
            break;
          }
        }
      }
    }
    if (!isCurrentComboValid && !contains && testedParam.getListItemsNotShowIf() != null) {
      for (      String condition : testedParam.getListItemsNotShowIf()) {
        if (condition != null && condition.contains(currentParam.getName())) {
          boolean isValid=!Expression.evaluate(condition,elementParameters);
          if (isValid) {
            int index=ArrayUtils.indexOf(testedParam.getListItemsNotShowIf(),condition);
            testedParam.setValue(testedParam.getListItemsValue()[index]);
            break;
          }
        }
 else         if (condition == null) {
          int index=ArrayUtils.indexOf(testedParam.getListItemsNotShowIf(),condition);
          testedParam.setValue(testedParam.getListItemsValue()[index]);
          break;
        }
      }
    }
  }
 else   if (testedParam.getDefaultValues().size() > 0 && contains) {
    oldElementValues.put(testedParam,testedParam.getValue());
    if (!(testedParam.getFieldType().equals(EParameterFieldType.SCHEMA_TYPE) || testedParam.getFieldType().equals(EParameterFieldType.SCHEMA_REFERENCE))) {
      String oldMapping="String_Node_Str";
      if (!testedParam.getFieldType().equals(EParameterFieldType.CHECK) && !testedParam.getFieldType().equals(EParameterFieldType.RADIO)) {
        oldMapping=(String)testedParam.getValue();
      }
      testedParam.setValueToDefault(elementParameters);
      if (testedParam.getFieldType().equals(EParameterFieldType.MAPPING_TYPE)) {
        String newMapping=(String)testedParam.getValue();
        if (!oldMapping.equals(newMapping)) {
          Node node=(Node)referenceNode;
          if (node.getMetadataList().size() > 0) {
            IMetadataTable metadataTable=node.getMetadataList().get(0);
            metadataTable.setDbms(newMapping);
          }
        }
      }
    }
 else {
      Node node=(Node)referenceNode;
      if (node.getMetadataList().size() > 0) {
        IMetadataTable metadataTable=null;
        IMetadataTable newMetadataTable=null;
        boolean isBuiltIn=false;
        final IElementParameter elementParameter=testedParam.getChildParameters().get(EParameterFieldType.SCHEMA_TYPE.getName());
        if (elementParameter != null) {
          Object value=elementParameter.getValue();
          if ("String_Node_Str".equals(value.toString())) {
            isBuiltIn=true;
          }
        }
        if (isBuiltIn || elementParameter == null) {
          metadataTable=node.getMetadataFromConnector(testedParam.getContext());
          testedParam.setValueToDefault(node.getElementParameters());
          newMetadataTable=((IMetadataTable)testedParam.getValue()).clone(true);
          if (metadataTable != null && newMetadataTable != null) {
            newMetadataTable.setTableName(metadataTable.getTableName());
            newMetadataTable.setAttachedConnector(metadataTable.getAttachedConnector());
            boolean needClearTargetTable=newMetadataTable.getListColumns().isEmpty();
            if (!needClearTargetTable) {
              needClearTargetTable=false;
              for (              IMetadataColumn column : newMetadataTable.getListColumns()) {
                if (!column.isCustom()) {
                  needClearTargetTable=true;
                  break;
                }
              }
            }
            if (needClearTargetTable) {
              metadataTable.getListColumns().clear();
            }
            List<IMetadataColumn> columnsToRemove=new ArrayList<IMetadataColumn>();
            for (            IMetadataColumn column : metadataTable.getListColumns()) {
              if (column.isCustom() || column.isReadOnly()) {
                columnsToRemove.add(column);
              }
            }
            metadataTable.getListColumns().removeAll(columnsToRemove);
            boolean onlyHaveCustomInDefault=true;
            List<IMetadataColumn> customColumnsFromDefault=new ArrayList<IMetadataColumn>();
            for (            IMetadataColumn column : newMetadataTable.getListColumns()) {
              if (!column.isCustom() && !column.isReadOnly()) {
                onlyHaveCustomInDefault=false;
              }
 else {
                customColumnsFromDefault.add(column);
              }
            }
            metadataTable.getListColumns().addAll(customColumnsFromDefault);
            if (onlyHaveCustomInDefault) {
              metadataTable.setReadOnly(newMetadataTable.isReadOnly());
              newMetadataTable=metadataTable;
            }
            ChangeMetadataCommand changeMetadataCommand=new ChangeMetadataCommand(node,null,null,newMetadataTable);
            changeMetadataCommands.add(changeMetadataCommand);
            changeMetadataCommand.execute(true);
          }
        }
 else {
          metadataTable=node.getMetadataFromConnector(testedParam.getContext());
          if (testedParam.getName().equals("String_Node_Str")) {
            newMetadataTable=metadataTable;
          }
        }
      }
    }
  }
}