Program: 26449
Project: 26449
Buggy source:
/** 
 * <p> Get the a custom report for the given key and data. Rather than creating a single chart with a line/bar for each field, this function creates a chart for <em>each</em> field that matches the given definition. </p> <p> This function uses all charts in the given report so it is possible for this function to create a large number of charts, especially if multiple DataTypes and/or fields are matched. </p>
 * @param filterByData should the initial reports list be filtered by the given data? See {@link #getReport(String,Iterable)}.
 */
public List<BaseChartDefinition> multiplexChartsAcrossFields(String key,DataSet data,boolean filterByData){
  List<BaseChartDefinition> chartDefinitions=null;
  if (filterByData) {
    chartDefinitions=getReport(key,java.util.Collections.singletonList(data));
  }
 else {
    chartDefinitions=getReport(key);
  }
  LOGGER.debug("String_Node_Str",chartDefinitions,data.getHostname());
  List<BaseChartDefinition> multiplexedChartDefinitions=new java.util.ArrayList<BaseChartDefinition>(10 * chartDefinitions.size());
  for (  BaseChartDefinition chartDefinition : chartDefinitions) {
    for (    DataDefinition dataDefinition : chartDefinition.getData()) {
      if (dataDefinition.matchesHost(data)) {
        for (        DataType type : dataDefinition.getMatchingTypes(data)) {
          for (          String field : dataDefinition.getMatchingFields(type)) {
            BaseChartDefinition newChartDefinition=copyChart(chartDefinition);
            newChartDefinition.setShortName(chartDefinition.getShortName() + "String_Node_Str" + dataDefinition.renameField(field));
            newChartDefinition.setTitle(chartDefinition.getTitle());
            newChartDefinition.setSubtitleNamingMode(NamingMode.FIELD);
            DataDefinition newData=null;
            if (dataDefinition instanceof DefaultDataDefinition) {
              DefaultDataDefinition old=(DefaultDataDefinition)dataDefinition;
              newData=old.withNewFields(new ExactFieldMatcher(field));
            }
 else {
              newData=new ExactDataDefinition(data,type,java.util.Collections.singletonList(field),dataDefinition.getStatistic(),dataDefinition.usesSecondaryYAxis());
            }
            newChartDefinition.addData(newData);
            multiplexedChartDefinitions.add(newChartDefinition);
          }
        }
      }
    }
  }
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("String_Node_Str",new Object[]{chartDefinitions,data.getHostname(),multiplexedChartDefinitions});
  }
  return multiplexedChartDefinitions;
}

Fixed version (ground truth):
/** 
 * <p> Get the a custom report for the given key and data. Rather than creating a single chart with a line/bar for each field, this function creates a chart for <em>each</em> field that matches the given definition. </p> <p> This function uses all charts in the given report so it is possible for this function to create a large number of charts, especially if multiple DataTypes and/or fields are matched. </p>
 * @param filterByData should the initial reports list be filtered by the given data? See{@link #getReport(String,Iterable)}.
 */
public List<BaseChartDefinition> multiplexChartsAcrossFields(String key,DataSet data,boolean filterByData){
  List<BaseChartDefinition> chartDefinitions=null;
  if (filterByData) {
    chartDefinitions=getReport(key,java.util.Collections.singletonList(data));
  }
 else {
    chartDefinitions=getReport(key);
  }
  LOGGER.debug("String_Node_Str",chartDefinitions,data.getHostname());
  Map<String,BaseChartDefinition> multiplexedChartDefinitions=new java.util.HashMap<String,BaseChartDefinition>(chartDefinitions.size() * 10);
  for (  BaseChartDefinition chartDefinition : chartDefinitions) {
    for (    DataDefinition dataDefinition : chartDefinition.getData()) {
      if (dataDefinition.matchesHost(data)) {
        for (        DataType type : dataDefinition.getMatchingTypes(data)) {
          for (          String field : dataDefinition.getMatchingFields(type)) {
            String name=chartDefinition.getShortName() + "String_Node_Str" + dataDefinition.renameField(field);
            BaseChartDefinition newChartDefinition=multiplexedChartDefinitions.get(name);
            if (newChartDefinition == null) {
              newChartDefinition=copyChart(chartDefinition);
              newChartDefinition.setShortName(name);
              newChartDefinition.setTitle(chartDefinition.getTitle());
              newChartDefinition.setSubtitleNamingMode(NamingMode.FIELD);
              multiplexedChartDefinitions.put(name,newChartDefinition);
            }
            DataDefinition newData=null;
            if (dataDefinition instanceof DefaultDataDefinition) {
              DefaultDataDefinition old=(DefaultDataDefinition)dataDefinition;
              newData=old.withNewFields(new ExactFieldMatcher(field));
            }
 else {
              newData=new ExactDataDefinition(data,type,java.util.Collections.singletonList(field),dataDefinition.getStatistic(),dataDefinition.usesSecondaryYAxis());
            }
            newChartDefinition.addData(newData);
          }
        }
      }
    }
  }
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("String_Node_Str",new Object[]{chartDefinitions,data.getHostname(),multiplexedChartDefinitions});
  }
  return new java.util.ArrayList<BaseChartDefinition>(multiplexedChartDefinitions.values());
}