Program: 68722
Project: 68722
Buggy source:
/** 
 * 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;
  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 (Entry<String,ColumnBindingInfo> entry : groups.entrySet()) {
categorys[index][0]=entry.getKey();
categorys[index][1]=entry.getValue();
index++;
}
for (Entry<String,ColumnBindingInfo> entry : commons.entrySet()) {
categorys[index][0]=entry.getKey();
categorys[index][1]=entry.getValue();
index++;
}
if (isInheritColumnsGroups()) {
Map<String,ColumnBindingInfo> g=new LinkedHashMap<String,ColumnBindingInfo>(2);
DesignElementHandle reh=itemHandle;
while (reh != null) {
if (reh.getContainer() instanceof TableGroupHandle) {
reh=reh.getContainer();
for (Entry<String,ColumnBindingInfo> e : groups.entrySet()) {
g.put(e.getKey(),e.getValue());
if (reh.getName().equals(e.getValue().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) {
String key=groups.keySet().toArray(new String[]{})[0];
g.put(key,groups.get(key));
}
}
break;
}
 else if (reh.getContainer() instanceof ListingHandle) {
reh=null;
break;
}
reh=reh.getContainer();
}
optionals=new Object[g.size()][2];
int i=0;
for (Entry<String,ColumnBindingInfo> e : g.entrySet()) {
optionals[i][0]=e.getKey();
optionals[i++][1]=e.getValue();
}
}
 else {
int size=(groups.size() > 0) ? 1 : 0;
optionals=new Object[size][2];
if (groups.size() > 0) {
Entry<String,ColumnBindingInfo> 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 (Entry<String,ColumnBindingInfo> entry : aggs.entrySet()) {
values[index][0]=entry.getKey();
values[index][1]=entry.getValue();
index++;
}
for (Entry<String,ColumnBindingInfo> entry : commons.entrySet()) {
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;
  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 (Entry<String,ColumnBindingInfo> entry : groups.entrySet()) {
categorys[index][0]=entry.getKey();
categorys[index][1]=entry.getValue();
index++;
}
for (Entry<String,ColumnBindingInfo> entry : commons.entrySet()) {
categorys[index][0]=entry.getKey();
categorys[index][1]=entry.getValue();
index++;
}
if (isInheritColumnsGroups() && groups.size() > 0) {
Map<String,ColumnBindingInfo> g=new LinkedHashMap<String,ColumnBindingInfo>(2);
DesignElementHandle reh=itemHandle;
while (reh != null) {
if (reh.getContainer() instanceof TableGroupHandle) {
reh=reh.getContainer();
for (Entry<String,ColumnBindingInfo> e : groups.entrySet()) {
g.put(e.getKey(),e.getValue());
if (reh.getName().equals(e.getValue().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) {
String key=groups.keySet().toArray(new String[]{})[0];
g.put(key,groups.get(key));
}
}
break;
}
 else if (reh.getContainer() instanceof ListingHandle) {
reh=null;
break;
}
reh=reh.getContainer();
}
optionals=new Object[g.size()][2];
int i=0;
for (Entry<String,ColumnBindingInfo> e : g.entrySet()) {
optionals[i][0]=e.getKey();
optionals[i++][1]=e.getValue();
}
}
 else {
int size=(groups.size() > 0) ? 1 : 0;
optionals=new Object[size][2];
if (groups.size() > 0) {
Entry<String,ColumnBindingInfo> 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 (Entry<String,ColumnBindingInfo> entry : aggs.entrySet()) {
values[index][0]=entry.getKey();
values[index][1]=entry.getValue();
index++;
}
for (Entry<String,ColumnBindingInfo> entry : commons.entrySet()) {
values[index][0]=entry.getKey();
values[index][1]=entry.getValue();
index++;
}
return new Object[]{categorys,optionals,values};
}