Program: 168611
Project: 168611
Buggy source:
@Override public List<Measurements> find(String tenantId,String name,Map<String,String> dimensions,DateTime startTime,@Nullable DateTime endTime,@Nullable String offset,int limit,Boolean mergeMetricsFlag) throws MultipleMetricsException {
  try (Handle h=db.open()){
    StringBuilder sb=new StringBuilder();
    if (name != null && !name.isEmpty()) {
      sb.append("String_Node_Str");
    }
    if (endTime != null) {
      sb.append("String_Node_Str");
    }
    if (offset != null && !offset.isEmpty()) {
      sb.append("String_Node_Str");
    }
    String sql=String.format(FIND_BY_METRIC_DEF_SQL,MetricQueries.buildJoinClauseFor(dimensions,TABLE_TO_JOIN_DIMENSIONS_ON),sb);
    Query<Map<String,Object>> query=h.createQuery(sql).bind("String_Node_Str",tenantId).bind("String_Node_Str",new Timestamp(startTime.getMillis())).bind("String_Node_Str",limit + 1);
    if (name != null && !name.isEmpty()) {
      logger.debug("String_Node_Str",name);
      query.bind("String_Node_Str",name);
    }
    if (endTime != null) {
      logger.debug("String_Node_Str",endTime);
      query.bind("String_Node_Str",new Timestamp(endTime.getMillis()));
    }
    if (offset != null && !offset.isEmpty()) {
      logger.debug("String_Node_Str",offset);
      query.bind("String_Node_Str",new Timestamp(DateTime.parse(offset).getMillis()));
    }
    MetricQueries.bindDimensionsToQuery(query,dimensions);
    List<Map<String,Object>> rows=query.list();
    Map<ByteBuffer,Measurements> results=new LinkedHashMap<>();
    for (    Map<String,Object> row : rows) {
      String metricName=(String)row.get("String_Node_Str");
      byte[] defIdBytes=(byte[])row.get("String_Node_Str");
      ByteBuffer defId=ByteBuffer.wrap(defIdBytes);
      byte[] defdimsIdBytes=(byte[])row.get("String_Node_Str");
      byte[] dimSetIdBytes=(byte[])row.get("String_Node_Str");
      ByteBuffer defdimsId=ByteBuffer.wrap(defdimsIdBytes);
      String timestamp=DATETIME_FORMATTER.print(((Timestamp)row.get("String_Node_Str")).getTime());
      double value=(double)row.get("String_Node_Str");
      String valueMetaString=(String)row.get("String_Node_Str");
      Map<String,String> valueMetaMap=new HashMap<>();
      if (valueMetaString != null && !valueMetaString.isEmpty()) {
        try {
          valueMetaMap=this.objectMapper.readValue(valueMetaString,VALUE_META_TYPE);
        }
 catch (        IOException e) {
          logger.error("String_Node_Str",valueMetaString);
        }
      }
      Measurements measurements;
      if (Boolean.TRUE.equals(mergeMetricsFlag)) {
        measurements=results.get(defId);
      }
 else {
        measurements=results.get(defdimsId);
      }
      if (measurements == null) {
        if (Boolean.TRUE.equals(mergeMetricsFlag)) {
          measurements=new Measurements(metricName,new HashMap<String,String>(),new ArrayList<Object[]>());
          results.put(defId,measurements);
        }
 else {
          measurements=new Measurements(metricName,MetricQueries.dimensionsFor(h,dimSetIdBytes),new ArrayList<Object[]>());
          results.put(defdimsId,measurements);
          if (results.keySet().size() > 1) {
            throw new MultipleMetricsException(name,dimensions);
          }
        }
      }
      measurements.addMeasurement(new Object[]{timestamp,value,valueMetaMap});
    }
    return new ArrayList<>(results.values());
  }
 }

Fixed version (ground truth):
@Override public List<Measurements> find(String tenantId,String name,Map<String,String> dimensions,DateTime startTime,@Nullable DateTime endTime,@Nullable String offset,int limit,Boolean mergeMetricsFlag) throws MultipleMetricsException {
  try (Handle h=db.open()){
    StringBuilder sb=new StringBuilder();
    if (name != null && !name.isEmpty()) {
      sb.append("String_Node_Str");
    }
    if (endTime != null) {
      sb.append("String_Node_Str");
    }
    if (offset != null && !offset.isEmpty()) {
      sb.append("String_Node_Str");
    }
    String sql=String.format(FIND_BY_METRIC_DEF_SQL,sb,MetricQueries.buildDimensionAndClause(dimensions,TABLE_TO_JOIN_DIMENSIONS_ON,0));
    Query<Map<String,Object>> query=h.createQuery(sql).bind("String_Node_Str",tenantId).bind("String_Node_Str",new Timestamp(startTime.getMillis())).bind("String_Node_Str",limit + 1);
    if (name != null && !name.isEmpty()) {
      logger.debug("String_Node_Str",name);
      query.bind("String_Node_Str",name);
    }
    if (endTime != null) {
      logger.debug("String_Node_Str",endTime);
      query.bind("String_Node_Str",new Timestamp(endTime.getMillis()));
    }
    if (offset != null && !offset.isEmpty()) {
      logger.debug("String_Node_Str",offset);
      query.bind("String_Node_Str",new Timestamp(DateTime.parse(offset).getMillis()));
    }
    MetricQueries.bindDimensionsToQuery(query,dimensions);
    List<Map<String,Object>> rows=query.list();
    Map<ByteBuffer,Measurements> results=new LinkedHashMap<>();
    for (    Map<String,Object> row : rows) {
      String metricName=(String)row.get("String_Node_Str");
      byte[] defIdBytes=(byte[])row.get("String_Node_Str");
      ByteBuffer defId=ByteBuffer.wrap(defIdBytes);
      byte[] defdimsIdBytes=(byte[])row.get("String_Node_Str");
      byte[] dimSetIdBytes=(byte[])row.get("String_Node_Str");
      ByteBuffer defdimsId=ByteBuffer.wrap(defdimsIdBytes);
      String timestamp=DATETIME_FORMATTER.print(((Timestamp)row.get("String_Node_Str")).getTime());
      double value=(double)row.get("String_Node_Str");
      String valueMetaString=(String)row.get("String_Node_Str");
      Map<String,String> valueMetaMap=new HashMap<>();
      if (valueMetaString != null && !valueMetaString.isEmpty()) {
        try {
          valueMetaMap=this.objectMapper.readValue(valueMetaString,VALUE_META_TYPE);
        }
 catch (        IOException e) {
          logger.error("String_Node_Str",valueMetaString);
        }
      }
      Measurements measurements;
      if (Boolean.TRUE.equals(mergeMetricsFlag)) {
        measurements=results.get(defId);
      }
 else {
        measurements=results.get(defdimsId);
      }
      if (measurements == null) {
        if (Boolean.TRUE.equals(mergeMetricsFlag)) {
          measurements=new Measurements(metricName,new HashMap<String,String>(),new ArrayList<Object[]>());
          results.put(defId,measurements);
        }
 else {
          measurements=new Measurements(metricName,MetricQueries.dimensionsFor(h,dimSetIdBytes),new ArrayList<Object[]>());
          results.put(defdimsId,measurements);
          if (results.keySet().size() > 1) {
            throw new MultipleMetricsException(name,dimensions);
          }
        }
      }
      measurements.addMeasurement(new Object[]{timestamp,value,valueMetaMap});
    }
    return new ArrayList<>(results.values());
  }
 }