Program: 35723
Project: 35723
Buggy source:
protected void buildAndExecuteRestOfQuery(int userId,Filter filter,Set<Dimension> dimensions,final List<Bucket> buckets,StringBuilder from,StringBuilder columns,StringBuilder where,StringBuilder groupBy,int nextColumnIndex,Bundler valueBundler){
  final List<Bundler> bundlers=new ArrayList<Bundler>();
  bundlers.add(valueBundler);
  StringBuilder dimColumns=new StringBuilder();
  for (  Dimension dimension : dimensions) {
    if (dimension.getType() == DimensionType.Activity) {
      dimColumns.append("String_Node_Str");
      bundlers.add(new OrderedEntityBundler(dimension,nextColumnIndex));
      nextColumnIndex+=3;
    }
 else     if (dimension.getType() == DimensionType.ActivityCategory) {
      dimColumns.append("String_Node_Str");
      bundlers.add(new SimpleBundler(dimension,nextColumnIndex));
      nextColumnIndex+=1;
    }
 else     if (dimension.getType() == DimensionType.Database) {
      dimColumns.append("String_Node_Str");
      bundlers.add(new EntityBundler(dimension,nextColumnIndex));
      nextColumnIndex+=2;
    }
 else     if (dimension.getType() == DimensionType.Partner) {
      dimColumns.append("String_Node_Str");
      bundlers.add(new EntityBundler(dimension,nextColumnIndex));
      nextColumnIndex+=2;
    }
 else     if (dimension.getType() == DimensionType.Indicator) {
      dimColumns.append("String_Node_Str");
      bundlers.add(new OrderedEntityBundler(dimension,nextColumnIndex));
      nextColumnIndex+=3;
    }
 else     if (dimension.getType() == DimensionType.IndicatorCategory) {
      dimColumns.append("String_Node_Str");
      bundlers.add(new SimpleBundler(dimension,nextColumnIndex));
      nextColumnIndex+=1;
    }
 else     if (dimension instanceof DateDimension) {
      DateDimension dateDim=(DateDimension)dimension;
      if (dateDim.getUnit() == DateUnit.YEAR) {
        dimColumns.append("String_Node_Str");
        bundlers.add(new YearBundler(dimension,nextColumnIndex));
        nextColumnIndex+=1;
      }
 else       if (dateDim.getUnit() == DateUnit.MONTH) {
        dimColumns.append("String_Node_Str");
        bundlers.add(new MonthBundler(dimension,nextColumnIndex));
        nextColumnIndex+=2;
      }
 else       if (dateDim.getUnit() == DateUnit.QUARTER) {
        dimColumns.append("String_Node_Str").append(dialect.formatQuarterFunction("String_Node_Str"));
        bundlers.add(new QuarterBundler(nextColumnIndex,dimension));
        nextColumnIndex+=2;
      }
    }
 else     if (dimension instanceof AdminDimension) {
      AdminDimension adminDim=(AdminDimension)dimension;
      String tableAlias="String_Node_Str" + adminDim.getLevelId();
      from.append("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str").append(adminDim.getLevelId()).append("String_Node_Str").append(tableAlias).append("String_Node_Str").append(tableAlias).append("String_Node_Str");
      dimColumns.append("String_Node_Str").append(tableAlias).append("String_Node_Str").append("String_Node_Str").append(tableAlias).append("String_Node_Str");
      bundlers.add(new EntityBundler(adminDim,nextColumnIndex));
      nextColumnIndex+=2;
    }
 else     if (dimension instanceof AttributeGroupDimension) {
      AttributeGroupDimension attrGroupDim=(AttributeGroupDimension)dimension;
      List<Integer> attributeIds=attrGroupDim.getAttributeIds();
      int count=0;
      for (      Integer attributeId : attributeIds) {
        String tableAlias="String_Node_Str" + attributeId;
        from.append("String_Node_Str" + "String_Node_Str" + tableAlias + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str").append(attributeId).append("String_Node_Str").append(tableAlias).append("String_Node_Str").append(tableAlias).append("String_Node_Str");
        dimColumns.append("String_Node_Str").append(tableAlias).append("String_Node_Str" + tableAlias + "String_Node_Str");
        count++;
      }
      Log.debug("String_Node_Str" + count);
      bundlers.add(new AttributeBundler(dimension,nextColumnIndex,count));
      nextColumnIndex+=count;
    }
  }
  columns.append(dimColumns);
  groupBy.append(dimColumns);
  where.append("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str");
  appendVisibilityFilter(where,userId);
  final List<Object> parameters=new ArrayList<Object>();
  if (filter.getMinDate() != null) {
    where.append("String_Node_Str");
    parameters.add(new java.sql.Date(filter.getMinDate().getTime()));
  }
  if (filter.getMaxDate() != null) {
    where.append("String_Node_Str");
    parameters.add(new java.sql.Date(filter.getMaxDate().getTime()));
  }
  for (  DimensionType type : filter.getRestrictedDimensions()) {
    if (type == DimensionType.Indicator) {
      appendIdCriteria(where,"String_Node_Str",filter.getRestrictions(type),parameters);
    }
 else     if (type == DimensionType.Activity) {
      appendIdCriteria(where,"String_Node_Str",filter.getRestrictions(type),parameters);
    }
 else     if (type == DimensionType.Database) {
      appendIdCriteria(where,"String_Node_Str",filter.getRestrictions(type),parameters);
    }
 else     if (type == DimensionType.Partner) {
      appendIdCriteria(where,"String_Node_Str",filter.getRestrictions(type),parameters);
    }
 else     if (type == DimensionType.AdminLevel) {
      where.append("String_Node_Str" + "String_Node_Str");
      appendIdCriteria(where,"String_Node_Str",filter.getRestrictions(type),parameters);
      where.append("String_Node_Str");
    }
  }
  final StringBuilder sql=new StringBuilder();
  sql.append("String_Node_Str").append(columns).append("String_Node_Str").append(from).append("String_Node_Str").append(where).append("String_Node_Str").append(groupBy);
  Session session=((HibernateEntityManager)em).getSession();
  System.out.println(sql.toString());
  session.doWork(new Work(){
    public void execute(    Connection connection) throws SQLException {
      PreparedStatement stmt=connection.prepareStatement(sql.toString());
      for (int i=0; i != parameters.size(); ++i) {
        stmt.setObject(i + 1,parameters.get(i));
      }
      ResultSet rs=stmt.executeQuery();
      while (rs.next()) {
        Bucket bucket=new Bucket();
        for (        Bundler bundler : bundlers) {
          bundler.bundle(rs,bucket);
        }
        buckets.add(bucket);
      }
    }
  }
);
}

Fixed version (ground truth):
protected void buildAndExecuteRestOfQuery(int userId,Filter filter,Set<Dimension> dimensions,final List<Bucket> buckets,StringBuilder from,StringBuilder columns,StringBuilder where,StringBuilder groupBy,int nextColumnIndex,Bundler valueBundler){
  final List<Bundler> bundlers=new ArrayList<Bundler>();
  bundlers.add(valueBundler);
  StringBuilder dimColumns=new StringBuilder();
  for (  Dimension dimension : dimensions) {
    if (dimension.getType() == DimensionType.Activity) {
      dimColumns.append("String_Node_Str");
      bundlers.add(new OrderedEntityBundler(dimension,nextColumnIndex));
      nextColumnIndex+=3;
    }
 else     if (dimension.getType() == DimensionType.ActivityCategory) {
      dimColumns.append("String_Node_Str");
      bundlers.add(new SimpleBundler(dimension,nextColumnIndex));
      nextColumnIndex+=1;
    }
 else     if (dimension.getType() == DimensionType.Database) {
      dimColumns.append("String_Node_Str");
      bundlers.add(new EntityBundler(dimension,nextColumnIndex));
      nextColumnIndex+=2;
    }
 else     if (dimension.getType() == DimensionType.Partner) {
      dimColumns.append("String_Node_Str");
      bundlers.add(new EntityBundler(dimension,nextColumnIndex));
      nextColumnIndex+=2;
    }
 else     if (dimension.getType() == DimensionType.Indicator) {
      dimColumns.append("String_Node_Str");
      bundlers.add(new OrderedEntityBundler(dimension,nextColumnIndex));
      nextColumnIndex+=3;
    }
 else     if (dimension.getType() == DimensionType.IndicatorCategory) {
      dimColumns.append("String_Node_Str");
      bundlers.add(new SimpleBundler(dimension,nextColumnIndex));
      nextColumnIndex+=1;
    }
 else     if (dimension instanceof DateDimension) {
      DateDimension dateDim=(DateDimension)dimension;
      if (dateDim.getUnit() == DateUnit.YEAR) {
        dimColumns.append("String_Node_Str");
        bundlers.add(new YearBundler(dimension,nextColumnIndex));
        nextColumnIndex+=1;
      }
 else       if (dateDim.getUnit() == DateUnit.MONTH) {
        dimColumns.append("String_Node_Str");
        bundlers.add(new MonthBundler(dimension,nextColumnIndex));
        nextColumnIndex+=2;
      }
 else       if (dateDim.getUnit() == DateUnit.QUARTER) {
        dimColumns.append("String_Node_Str").append(dialect.formatQuarterFunction("String_Node_Str"));
        bundlers.add(new QuarterBundler(nextColumnIndex,dimension));
        nextColumnIndex+=2;
      }
    }
 else     if (dimension instanceof AdminDimension) {
      AdminDimension adminDim=(AdminDimension)dimension;
      String tableAlias="String_Node_Str" + adminDim.getLevelId();
      from.append("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str").append(adminDim.getLevelId()).append("String_Node_Str").append(tableAlias).append("String_Node_Str").append(tableAlias).append("String_Node_Str");
      dimColumns.append("String_Node_Str").append(tableAlias).append("String_Node_Str").append("String_Node_Str").append(tableAlias).append("String_Node_Str");
      bundlers.add(new EntityBundler(adminDim,nextColumnIndex));
      nextColumnIndex+=2;
    }
 else     if (dimension instanceof AttributeGroupDimension) {
      AttributeGroupDimension attrGroupDim=(AttributeGroupDimension)dimension;
      List<Integer> attributeIds=attrGroupDim.getAttributeIds();
      int count=0;
      for (      Integer attributeId : attributeIds) {
        String tableAlias="String_Node_Str" + attributeId;
        from.append("String_Node_Str" + "String_Node_Str" + tableAlias + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str").append(attributeId).append("String_Node_Str").append(tableAlias).append("String_Node_Str").append(tableAlias).append("String_Node_Str");
        dimColumns.append("String_Node_Str").append(tableAlias).append("String_Node_Str").append(tableAlias).append("String_Node_Str");
        count++;
      }
      Log.debug("String_Node_Str" + count);
      bundlers.add(new AttributeBundler(dimension,nextColumnIndex,count));
      nextColumnIndex+=count;
    }
  }
  columns.append(dimColumns);
  groupBy.append(dimColumns);
  where.append("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str");
  appendVisibilityFilter(where,userId);
  final List<Object> parameters=new ArrayList<Object>();
  if (filter.getMinDate() != null) {
    where.append("String_Node_Str");
    parameters.add(new java.sql.Date(filter.getMinDate().getTime()));
  }
  if (filter.getMaxDate() != null) {
    where.append("String_Node_Str");
    parameters.add(new java.sql.Date(filter.getMaxDate().getTime()));
  }
  for (  DimensionType type : filter.getRestrictedDimensions()) {
    if (type == DimensionType.Indicator) {
      appendIdCriteria(where,"String_Node_Str",filter.getRestrictions(type),parameters);
    }
 else     if (type == DimensionType.Activity) {
      appendIdCriteria(where,"String_Node_Str",filter.getRestrictions(type),parameters);
    }
 else     if (type == DimensionType.Database) {
      appendIdCriteria(where,"String_Node_Str",filter.getRestrictions(type),parameters);
    }
 else     if (type == DimensionType.Partner) {
      appendIdCriteria(where,"String_Node_Str",filter.getRestrictions(type),parameters);
    }
 else     if (type == DimensionType.AdminLevel) {
      where.append("String_Node_Str" + "String_Node_Str");
      appendIdCriteria(where,"String_Node_Str",filter.getRestrictions(type),parameters);
      where.append("String_Node_Str");
    }
  }
  final StringBuilder sql=new StringBuilder();
  sql.append("String_Node_Str").append(columns).append("String_Node_Str").append(from).append("String_Node_Str").append(where).append("String_Node_Str").append(groupBy);
  Session session=((HibernateEntityManager)em).getSession();
  System.out.println(sql.toString());
  session.doWork(new Work(){
    public void execute(    Connection connection) throws SQLException {
      PreparedStatement stmt=connection.prepareStatement(sql.toString());
      for (int i=0; i != parameters.size(); ++i) {
        stmt.setObject(i + 1,parameters.get(i));
      }
      ResultSet rs=stmt.executeQuery();
      while (rs.next()) {
        Bucket bucket=new Bucket();
        for (        Bundler bundler : bundlers) {
          bundler.bundle(rs,bucket);
        }
        buckets.add(bucket);
      }
    }
  }
);
}