Program: 67127
Project: 67127
Buggy source:
/** 
 * Returns predefined expressions for sharing case.
 * @param headers
 * @return
 */
private Object[] getPredefinedExpressionsForSharing(ColumnBindingInfo[] headers){
  List<ColumnBindingInfo> commons=new LinkedList<ColumnBindingInfo>();
  List<ColumnBindingInfo> aggs=new LinkedList<ColumnBindingInfo>();
  List<ColumnBindingInfo> groups=new LinkedList<ColumnBindingInfo>();
  for (int i=0; i < headers.length; i++) {
    int type=headers[i].getColumnType();
switch (type) {
case ColumnBindingInfo.COMMON_COLUMN:
      commons.add(headers[i]);
    break;
case ColumnBindingInfo.AGGREGATE_COLUMN:
  aggs.add(headers[i]);
break;
case ColumnBindingInfo.GROUP_COLUMN:
groups.add(headers[i]);
break;
}
}
List<ColumnBindingInfo> groupsWithAgg=new LinkedList<ColumnBindingInfo>();
List<ColumnBindingInfo> groupsWithoutAgg=new LinkedList<ColumnBindingInfo>(groups);
for (Iterator<ColumnBindingInfo> iter=groupsWithoutAgg.iterator(); iter.hasNext(); ) {
ColumnBindingInfo cbiGroup=iter.next();
String groupName=cbiGroup.getName();
for (ColumnBindingInfo cbiAggr : aggs) {
if (groupName.equals(((ComputedColumnHandle)cbiAggr.getObjectHandle()).getAggregateOn())) {
iter.remove();
groupsWithAgg.add(cbiGroup);
break;
}
}
}
ColumnBindingInfo[] categorys=new ColumnBindingInfo[groups.size() + commons.size()];
int index=0;
for (ColumnBindingInfo cbi : groups) {
categorys[index++]=cbi;
}
for (ColumnBindingInfo cbi : commons) {
categorys[index++]=cbi;
}
ColumnBindingInfo[] optionals=null;
if (isInheritColumnsGroups() && groups.size() > 0) {
List<ColumnBindingInfo> g=new LinkedList<ColumnBindingInfo>();
DesignElementHandle reh=itemHandle;
while (reh != null) {
if (reh.getContainer() instanceof TableGroupHandle) {
reh=reh.getContainer();
for (ColumnBindingInfo cbi : groups) {
g.add(cbi);
if (reh.getName().equals(cbi.getName())) {
break;
}
}
break;
}
 else if (reh.getContainer() instanceof RowHandle && reh.getContainer() != null && !(reh.getContainer().getContainer() instanceof TableGroupHandle)) {
DesignElementHandle deh=reh;
while (deh != null) {
if (deh.getContainer() instanceof ListingHandle) {
deh=deh.getContainer();
break;
}
deh=deh.getContainer();
}
if (deh != null && deh instanceof ListingHandle) {
if (((ListingHandle)deh).getDetail().findPosn(reh.getContainer()) >= 0) {
g=groups;
}
 else if (((ListingHandle)deh).getHeader().findPosn(reh.getContainer()) >= 0) {
g.add(groups.get(0));
}
}
break;
}
 else if (reh.getContainer() instanceof ListingHandle) {
reh=null;
break;
}
reh=reh.getContainer();
}
optionals=new ColumnBindingInfo[g.size()];
int i=0;
for (ColumnBindingInfo cbi : g) {
optionals[i++]=cbi;
}
}
 else {
int size=(groups.size() > 0) ? 1 : 0;
optionals=new ColumnBindingInfo[size];
if (groups.size() > 0) {
optionals[0]=groups.get(0);
}
}
ColumnBindingInfo[] values=new ColumnBindingInfo[aggs.size() + commons.size()];
index=0;
for (ColumnBindingInfo cbi : aggs) {
values[index++]=cbi;
}
for (ColumnBindingInfo cbi : commons) {
values[index++]=cbi;
}
return new Object[]{categorys,optionals,values};
}

Fixed version (ground truth):
/** 
 * Returns predefined expressions for sharing case.
 * @param headers
 * @return
 */
private Object[] getPredefinedExpressionsForSharing(ColumnBindingInfo[] headers){
  List<ColumnBindingInfo> commons=new LinkedList<ColumnBindingInfo>();
  List<ColumnBindingInfo> aggs=new LinkedList<ColumnBindingInfo>();
  List<ColumnBindingInfo> groups=new LinkedList<ColumnBindingInfo>();
  for (int i=0; i < headers.length; i++) {
    int type=headers[i].getColumnType();
switch (type) {
case ColumnBindingInfo.COMMON_COLUMN:
      commons.add(headers[i]);
    break;
case ColumnBindingInfo.AGGREGATE_COLUMN:
  aggs.add(headers[i]);
break;
case ColumnBindingInfo.GROUP_COLUMN:
groups.add(headers[i]);
break;
}
}
List<ColumnBindingInfo> groupsWithAgg=new LinkedList<ColumnBindingInfo>();
List<ColumnBindingInfo> groupsWithoutAgg=new LinkedList<ColumnBindingInfo>(groups);
for (Iterator<ColumnBindingInfo> iter=groupsWithoutAgg.iterator(); iter.hasNext(); ) {
ColumnBindingInfo cbiGroup=iter.next();
String groupName=cbiGroup.getName();
for (ColumnBindingInfo cbiAggr : aggs) {
if (groupName.equals(((ComputedColumnHandle)cbiAggr.getObjectHandle()).getAggregateOn())) {
iter.remove();
groupsWithAgg.add(cbiGroup);
break;
}
}
}
ColumnBindingInfo[] categorys=new ColumnBindingInfo[groups.size() + commons.size()];
int index=0;
for (ColumnBindingInfo cbi : groups) {
categorys[index++]=cbi;
}
for (ColumnBindingInfo cbi : commons) {
categorys[index++]=cbi;
}
ColumnBindingInfo[] optionals=null;
if (isInheritColumnsGroups() && groups.size() > 0) {
List<ColumnBindingInfo> g=new LinkedList<ColumnBindingInfo>();
DesignElementHandle reh=itemHandle;
while (reh != null) {
if (reh.getContainer() instanceof GroupHandle) {
reh=reh.getContainer();
for (ColumnBindingInfo cbi : groups) {
g.add(cbi);
if (reh.getName().equals(cbi.getName())) {
break;
}
}
break;
}
 else if (reh.getContainer() instanceof RowHandle && reh.getContainer() != null && !(reh.getContainer().getContainer() instanceof GroupHandle)) {
DesignElementHandle deh=reh;
while (deh != null) {
if (deh.getContainer() instanceof ListingHandle) {
deh=deh.getContainer();
break;
}
deh=deh.getContainer();
}
if (deh != null && deh instanceof ListingHandle) {
if (((ListingHandle)deh).getDetail().findPosn(reh.getContainer()) >= 0) {
g=groups;
}
 else if (((ListingHandle)deh).getHeader().findPosn(reh.getContainer()) >= 0) {
g.add(groups.get(0));
}
}
break;
}
 else if (reh.getContainer() instanceof ListingHandle) {
reh=null;
break;
}
reh=reh.getContainer();
}
optionals=new ColumnBindingInfo[g.size()];
int i=0;
for (ColumnBindingInfo cbi : g) {
optionals[i++]=cbi;
}
}
 else {
int size=(groups.size() > 0) ? 1 : 0;
optionals=new ColumnBindingInfo[size];
if (groups.size() > 0) {
optionals[0]=groups.get(0);
}
}
ColumnBindingInfo[] values=new ColumnBindingInfo[aggs.size() + commons.size()];
index=0;
for (ColumnBindingInfo cbi : aggs) {
values[index++]=cbi;
}
for (ColumnBindingInfo cbi : commons) {
values[index++]=cbi;
}
return new Object[]{categorys,optionals,values};
}