Program: 74138
Project: 74138
Buggy source:
/** 
 * Inserts dataset column into the target. Add label or group key if possible
 * @param model column item
 * @param target insert target like cell or ListBandProxy
 * @param targetParent target container like table or list
 * @return to be inserted data item
 * @throws SemanticException
 */
protected static DataItemHandle performInsertDataSetColumn(ResultSetColumnHandle model,Object target,Object targetParent) throws SemanticException {
  DataItemHandle dataHandle=DesignElementFactory.getInstance().newDataItem(null);
  DataSetHandle dataSet=(DataSetHandle)model.getElementHandle();
  dataHandle.setResultSetColumn(model.getColumnName());
  if (targetParent instanceof ReportItemHandle) {
    ReportItemHandle container=(ReportItemHandle)targetParent;
    ComputedColumn bindingColumn=StructureFactory.newComputedColumn(dataHandle,model.getColumnName());
    bindingColumn.setDataType(model.getDataType());
    bindingColumn.setExpression(DEUtil.getExpression(model));
    if (target instanceof DesignElementHandle) {
      if (ExpressionUtil.hasAggregation(bindingColumn.getExpression())) {
        String groupType=DEUtil.getGroupControlType((DesignElementHandle)target);
        if (groupType.equals(DEUtil.TYPE_GROUP_GROUP))         bindingColumn.setAggregateOn(((GroupHandle)DEUtil.getGroups((DesignElementHandle)target).get(0)).getName());
 else         if (groupType.equals(DEUtil.TYPE_GROUP_LISTING))         bindingColumn.setAggregateOn(null);
      }
    }
    DataSetHandle containerDataSet=DEUtil.getFirstDataSet(container);
    container=DEUtil.getListingContainer(container);
    if (containerDataSet == null && container != null) {
      container.setDataSet(dataSet);
      containerDataSet=dataSet;
    }
    if (dataSet.equals(containerDataSet) && container != null) {
      container.addColumnBinding(bindingColumn,false);
    }
 else {
      dataHandle.setDataSet(dataSet);
      dataHandle.addColumnBinding(bindingColumn,false);
    }
  }
 else {
    ComputedColumn bindingColumn=StructureFactory.newComputedColumn(dataHandle,model.getColumnName());
    bindingColumn.setDataType(model.getDataType());
    bindingColumn.setExpression(DEUtil.getExpression(model));
    if (target instanceof DesignElementHandle) {
      if (ExpressionUtil.hasAggregation(bindingColumn.getExpression())) {
        String groupType=DEUtil.getGroupControlType((DesignElementHandle)target);
        if (groupType.equals(DEUtil.TYPE_GROUP_GROUP))         bindingColumn.setAggregateOn(((GroupHandle)DEUtil.getGroups((DesignElementHandle)target).get(0)).getName());
 else         if (groupType.equals(DEUtil.TYPE_GROUP_LISTING))         bindingColumn.setAggregateOn(null);
      }
    }
    dataHandle.addColumnBinding(bindingColumn,false);
    dataHandle.setDataSet(dataSet);
  }
  InsertInLayoutRule rule=new LabelAddRule(target);
  if (rule.canInsert()) {
    LabelHandle label=DesignElementFactory.getInstance().newLabel(null);
    label.setText(UIUtil.getColumnDisplayName(model));
    rule.insert(label);
  }
  rule=new GroupKeySetRule(target,model);
  if (rule.canInsert()) {
    rule.insert(model);
  }
  return dataHandle;
}

Fixed version (ground truth):
/** 
 * Inserts dataset column into the target. Add label or group key if possible
 * @param model column item
 * @param target insert target like cell or ListBandProxy
 * @param targetParent target container like table or list
 * @return to be inserted data item
 * @throws SemanticException
 */
protected static DataItemHandle performInsertDataSetColumn(ResultSetColumnHandle model,Object target,Object targetParent) throws SemanticException {
  DataItemHandle dataHandle=DesignElementFactory.getInstance().newDataItem(null);
  DataSetHandle dataSet=(DataSetHandle)model.getElementHandle();
  dataHandle.setResultSetColumn(model.getColumnName());
  if (targetParent instanceof ReportItemHandle) {
    ReportItemHandle container=(ReportItemHandle)targetParent;
    ComputedColumn bindingColumn=StructureFactory.newComputedColumn(dataHandle,model.getColumnName());
    bindingColumn.setDataType(model.getDataType());
    bindingColumn.setExpression(DEUtil.getExpression(model));
    if (target instanceof DesignElementHandle) {
      if (ExpressionUtil.hasAggregation(bindingColumn.getExpression())) {
        String groupType=DEUtil.getGroupControlType((DesignElementHandle)target);
        if (groupType.equals(DEUtil.TYPE_GROUP_GROUP))         bindingColumn.setAggregateOn(((GroupHandle)DEUtil.getGroups((DesignElementHandle)target).get(0)).getName());
 else         if (groupType.equals(DEUtil.TYPE_GROUP_LISTING))         bindingColumn.setAggregateOn(null);
      }
    }
    DataSetHandle containerDataSet=DEUtil.getFirstDataSet(container);
    container=DEUtil.getListingContainer(container);
    if (containerDataSet == null && container != null) {
      container.setDataSet(dataSet);
      containerDataSet=dataSet;
    }
    if (dataSet.equals(containerDataSet) && container != null) {
      if (container.getDataBindingReference() != null)       container.getDataBindingReference().addColumnBinding(bindingColumn,false);
 else       container.addColumnBinding(bindingColumn,false);
    }
 else {
      dataHandle.setDataSet(dataSet);
      dataHandle.addColumnBinding(bindingColumn,false);
    }
  }
 else {
    ComputedColumn bindingColumn=StructureFactory.newComputedColumn(dataHandle,model.getColumnName());
    bindingColumn.setDataType(model.getDataType());
    bindingColumn.setExpression(DEUtil.getExpression(model));
    if (target instanceof DesignElementHandle) {
      if (ExpressionUtil.hasAggregation(bindingColumn.getExpression())) {
        String groupType=DEUtil.getGroupControlType((DesignElementHandle)target);
        if (groupType.equals(DEUtil.TYPE_GROUP_GROUP))         bindingColumn.setAggregateOn(((GroupHandle)DEUtil.getGroups((DesignElementHandle)target).get(0)).getName());
 else         if (groupType.equals(DEUtil.TYPE_GROUP_LISTING))         bindingColumn.setAggregateOn(null);
      }
    }
    dataHandle.addColumnBinding(bindingColumn,false);
    dataHandle.setDataSet(dataSet);
  }
  InsertInLayoutRule rule=new LabelAddRule(target);
  if (rule.canInsert()) {
    LabelHandle label=DesignElementFactory.getInstance().newLabel(null);
    label.setText(UIUtil.getColumnDisplayName(model));
    rule.insert(label);
  }
  rule=new GroupKeySetRule(target,model);
  if (rule.canInsert()) {
    rule.insert(model);
  }
  return dataHandle;
}