Program: 70795
Project: 70795
Buggy source:
/** 
 * Returns predefined expressions for sharing case.
 * @param headers
 * @return
 */
private Object[] getPredefinedExpressionsForSharing(ColumnBindingInfo[] headers){
  Map commons=new LinkedHashMap();
  Map aggs=new LinkedHashMap();
  Map groups=new LinkedHashMap();
  Map groupsWithAgg=new LinkedHashMap();
  Map groupsWithoutAgg=new LinkedHashMap();
  for (int i=0; i < headers.length; i++) {
    int type=headers[i].getColumnType();
switch (type) {
case ColumnBindingInfo.COMMON_COLUMN:
      commons.put(ExpressionUtil.createJSRowExpression(headers[i].getName()),headers[i]);
    break;
case ColumnBindingInfo.AGGREGATE_COLUMN:
  aggs.put(ExpressionUtil.createJSRowExpression(headers[i].getName()),headers[i]);
break;
case ColumnBindingInfo.GROUP_COLUMN:
groups.put(ExpressionUtil.createJSRowExpression(headers[i].getName()),headers[i]);
break;
}
}
groupsWithoutAgg=new LinkedHashMap(groups);
for (Iterator iter=groupsWithoutAgg.entrySet().iterator(); iter.hasNext(); ) {
Entry entry=(Entry)iter.next();
String groupName=((ColumnBindingInfo)entry.getValue()).getName();
Object[] aggsValues=aggs.values().toArray();
for (int j=0; j < aggs.size(); j++) {
if (groupName.equals(((ComputedColumnHandle)((ColumnBindingInfo)aggsValues[j]).getObjectHandle()).getAggregateOn())) {
iter.remove();
groupsWithAgg.put(entry.getKey(),entry.getValue());
break;
}
}
}
Object[][] categorys=new Object[0][];
Object[][] optionals=new Object[0][];
categorys=new Object[groups.size() + commons.size()][2];
int index=0;
for (Iterator iter=groups.entrySet().iterator(); iter.hasNext(); ) {
Entry entry=(Entry)iter.next();
categorys[index][0]=entry.getKey();
categorys[index][1]=entry.getValue();
index++;
}
for (Iterator iter=commons.entrySet().iterator(); iter.hasNext(); ) {
Entry entry=(Entry)iter.next();
categorys[index][0]=entry.getKey();
categorys[index][1]=entry.getValue();
index++;
}
int size=(groups.size() > 0) ? 1 : 0;
optionals=new Object[size][2];
if (groups.size() > 0) {
Entry entry=(Entry)groups.entrySet().iterator().next();
;
optionals[0][0]=entry.getKey();
optionals[0][1]=entry.getValue();
}
Object[][] values=new Object[aggs.size() + commons.size()][2];
index=0;
for (Iterator iter=aggs.entrySet().iterator(); iter.hasNext(); ) {
Entry entry=(Entry)iter.next();
values[index][0]=entry.getKey();
values[index][1]=entry.getValue();
index++;
}
for (Iterator iter=commons.entrySet().iterator(); iter.hasNext(); ) {
Entry entry=(Entry)iter.next();
values[index][0]=entry.getKey();
values[index][1]=entry.getValue();
index++;
}
return new Object[]{categorys,optionals,values};
}

Fixed version (ground truth):
/** 
 * Returns predefined expressions for sharing case.
 * @param headers
 * @return
 */
private Object[] getPredefinedExpressionsForSharing(ColumnBindingInfo[] headers){
  Map<String,ColumnBindingInfo> commons=new LinkedHashMap<String,ColumnBindingInfo>();
  Map<String,ColumnBindingInfo> aggs=new LinkedHashMap<String,ColumnBindingInfo>();
  Map<String,ColumnBindingInfo> groups=new LinkedHashMap<String,ColumnBindingInfo>();
  Map<String,ColumnBindingInfo> groupsWithAgg=new LinkedHashMap<String,ColumnBindingInfo>();
  Map<String,ColumnBindingInfo> groupsWithoutAgg=new LinkedHashMap<String,ColumnBindingInfo>();
  for (int i=0; i < headers.length; i++) {
    int type=headers[i].getColumnType();
switch (type) {
case ColumnBindingInfo.COMMON_COLUMN:
      commons.put(ExpressionUtil.createJSRowExpression(headers[i].getName()),headers[i]);
    break;
case ColumnBindingInfo.AGGREGATE_COLUMN:
  aggs.put(ExpressionUtil.createJSRowExpression(headers[i].getName()),headers[i]);
break;
case ColumnBindingInfo.GROUP_COLUMN:
groups.put(ExpressionUtil.createJSRowExpression(headers[i].getName()),headers[i]);
break;
}
}
groupsWithoutAgg=new LinkedHashMap<String,ColumnBindingInfo>(groups);
for (Iterator<Entry<String,ColumnBindingInfo>> iter=groupsWithoutAgg.entrySet().iterator(); iter.hasNext(); ) {
Entry<String,ColumnBindingInfo> entry=iter.next();
String groupName=entry.getValue().getName();
ColumnBindingInfo[] aggsValues=aggs.values().toArray(new ColumnBindingInfo[]{});
for (int j=0; j < aggs.size(); j++) {
if (groupName.equals(((ComputedColumnHandle)aggsValues[j].getObjectHandle()).getAggregateOn())) {
iter.remove();
groupsWithAgg.put(entry.getKey(),entry.getValue());
break;
}
}
}
Object[][] categorys=new Object[0][];
Object[][] optionals=new Object[0][];
categorys=new Object[groups.size() + commons.size()][2];
int index=0;
for (Iterator iter=groups.entrySet().iterator(); iter.hasNext(); ) {
Entry entry=(Entry)iter.next();
categorys[index][0]=entry.getKey();
categorys[index][1]=entry.getValue();
index++;
}
for (Iterator iter=commons.entrySet().iterator(); iter.hasNext(); ) {
Entry entry=(Entry)iter.next();
categorys[index][0]=entry.getKey();
categorys[index][1]=entry.getValue();
index++;
}
int size=(groups.size() > 0) ? 1 : 0;
optionals=new Object[size][2];
if (groups.size() > 0) {
Entry entry=(Entry)groups.entrySet().iterator().next();
;
optionals[0][0]=entry.getKey();
optionals[0][1]=entry.getValue();
}
Object[][] values=new Object[aggs.size() + commons.size()][2];
index=0;
for (Iterator iter=aggs.entrySet().iterator(); iter.hasNext(); ) {
Entry entry=(Entry)iter.next();
values[index][0]=entry.getKey();
values[index][1]=entry.getValue();
index++;
}
for (Iterator iter=commons.entrySet().iterator(); iter.hasNext(); ) {
Entry entry=(Entry)iter.next();
values[index][0]=entry.getKey();
values[index][1]=entry.getValue();
index++;
}
return new Object[]{categorys,optionals,values};
}