Program: 168419
Project: 168419
Buggy source:
private EVExercise parseWorkoutSamples(EVExercise exercise,Node workoutNode){
  int totalSamples=countNodeItems(workoutNode,"String_Node_Str");
  int currentSampleNumber=0;
  float lastDistance=0;
  boolean distanceinsample=false;
  boolean firstsample=true;
  exercise.setSampleList(new ExerciseSample[totalSamples]);
  double lastOffset=0;
  double currentOffset=0;
  Position lastPosition=new Position(0,0);
  NodeList children=workoutNode.getChildNodes();
  NodeList sampleChildren=null;
  String childName;
  ExerciseSample lastSample=new ExerciseSample();
  Double latitude=0.0, longitude=0.0;
  double belowZone[]={0,0,0,0,0,0};
  double inZone[]={0,0,0,0,0,0};
  double aboveZone[]={0,0,0,0,0,0};
  int istop=children.getLength();
  for (int i=0; i < istop; i++) {
    childName=children.item(i).getNodeName();
    if (childName.equals("String_Node_Str")) {
      ExerciseSample sample=new ExerciseSample();
      sampleChildren=children.item(i).getChildNodes();
      int jstop=sampleChildren.getLength();
      for (int j=0; j < jstop; j++) {
        childName=sampleChildren.item(j).getNodeName();
        if (childName.equals("String_Node_Str")) {
          if (currentOffset != 0)           lastOffset=currentOffset;
          currentOffset=Double.valueOf(sampleChildren.item(j).getTextContent()).doubleValue();
          sample.setTimestamp((long)(1000 * currentOffset));
        }
 else         if (childName.equals("String_Node_Str")) {
          sample.setHeartRate((short)Short.valueOf(sampleChildren.item(j).getTextContent()));
        }
 else         if (childName.equals("String_Node_Str")) {
          sample.setSpeed((float)3.6 * Float.valueOf(sampleChildren.item(j).getTextContent()).floatValue());
        }
 else         if (childName.equals("String_Node_Str")) {
        }
 else         if (childName.equals("String_Node_Str")) {
        }
 else         if (childName.equals("String_Node_Str")) {
          sample.setCadence((short)Short.valueOf(sampleChildren.item(j).getTextContent()));
          exercise.getRecordingMode().setCadence(true);
        }
 else         if (childName.equals("String_Node_Str")) {
          double dist=Double.valueOf(sampleChildren.item(j).getTextContent());
          sample.setDistance((int)Math.round(dist));
          distanceinsample=true;
        }
 else         if (childName.equals("String_Node_Str")) {
          latitude=Double.valueOf(sampleChildren.item(j).getTextContent()).doubleValue();
        }
 else         if (childName.equals("String_Node_Str")) {
          longitude=Double.valueOf(sampleChildren.item(j).getTextContent()).doubleValue();
        }
 else         if (childName.equals("String_Node_Str")) {
          sample.setAltitude(Float.valueOf(sampleChildren.item(j).getTextContent()).shortValue());
        }
 else         if (childName.equals("String_Node_Str")) {
          sample.setTemperature(Float.valueOf(sampleChildren.item(j).getTextContent()).shortValue());
        }
 else         if (childName.equals("String_Node_Str")) {
        }
      }
      sample.setPosition(new Position(latitude,longitude));
      if (firstsample) {
        lastPosition=sample.getPosition();
        firstsample=false;
      }
      if (!distanceinsample) {
        lastDistance+=getDistanceFromPositions(lastPosition,sample.getPosition());
        sample.setDistance((int)lastDistance);
        lastPosition=sample.getPosition();
      }
      if (sample.getHeartRate() == 0)       sample.setHeartRate(lastSample.getHeartRate());
 else       lastSample.setHeartRate(sample.getHeartRate());
      exercise.getSampleList()[currentSampleNumber++]=sample;
      for (int j=0; j < 6; j++) {
        if (sample.getHeartRate() > exercise.getHeartRateLimits()[j].getUpperHeartRate()) {
          aboveZone[j]+=(currentOffset - lastOffset);
        }
 else         if (sample.getHeartRate() < exercise.getHeartRateLimits()[j].getLowerHeartRate()) {
          belowZone[j]+=(currentOffset - lastOffset);
        }
 else {
          inZone[j]+=(currentOffset - lastOffset);
        }
      }
    }
  }
  for (int i=0; i < 6; i++) {
    exercise.getHeartRateLimits()[i].setTimeAbove((short)aboveZone[i]);
    exercise.getHeartRateLimits()[i].setTimeBelow((short)belowZone[i]);
    exercise.getHeartRateLimits()[i].setTimeWithin((short)inZone[i]);
  }
  exercise.setRecordingInterval((short)2);
  return exercise;
}

Fixed version (ground truth):
private EVExercise parseWorkoutSamples(EVExercise exercise,Node workoutNode){
  int totalSamples=countNodeItems(workoutNode,"String_Node_Str");
  int currentSampleNumber=0;
  float lastDistance=0;
  boolean distanceinsample=false;
  boolean firstsample=true;
  exercise.setSampleList(new ExerciseSample[totalSamples]);
  double lastOffset=0;
  double currentOffset=0;
  Position lastPosition=new Position(0,0);
  NodeList children=workoutNode.getChildNodes();
  NodeList sampleChildren=null;
  String childName;
  ExerciseSample lastSample=new ExerciseSample();
  Double latitude=0.0, longitude=0.0;
  double belowZone[]={0,0,0,0,0,0};
  double inZone[]={0,0,0,0,0,0};
  double aboveZone[]={0,0,0,0,0,0};
  int istop=children.getLength();
  for (int i=0; i < istop; i++) {
    childName=children.item(i).getNodeName();
    if (childName.equals("String_Node_Str")) {
      ExerciseSample sample=new ExerciseSample();
      sampleChildren=children.item(i).getChildNodes();
      int jstop=sampleChildren.getLength();
      for (int j=0; j < jstop; j++) {
        childName=sampleChildren.item(j).getNodeName();
        if (childName.equals("String_Node_Str")) {
          if (currentOffset != 0)           lastOffset=currentOffset;
          currentOffset=Double.valueOf(sampleChildren.item(j).getTextContent()).doubleValue();
          sample.setTimestamp((long)(1000 * currentOffset));
        }
 else         if (childName.equals("String_Node_Str")) {
          sample.setHeartRate((short)Short.valueOf(sampleChildren.item(j).getTextContent()));
        }
 else         if (childName.equals("String_Node_Str")) {
          sample.setSpeed((float)3.6 * Float.valueOf(sampleChildren.item(j).getTextContent()).floatValue());
        }
 else         if (childName.equals("String_Node_Str")) {
        }
 else         if (childName.equals("String_Node_Str")) {
        }
 else         if (childName.equals("String_Node_Str")) {
          sample.setCadence((short)Short.valueOf(sampleChildren.item(j).getTextContent()));
          exercise.getRecordingMode().setCadence(true);
        }
 else         if (childName.equals("String_Node_Str")) {
          double dist=Double.valueOf(sampleChildren.item(j).getTextContent());
          sample.setDistance((int)Math.round(dist));
          distanceinsample=true;
        }
 else         if (childName.equals("String_Node_Str")) {
          latitude=Double.valueOf(sampleChildren.item(j).getTextContent());
        }
 else         if (childName.equals("String_Node_Str")) {
          longitude=Double.valueOf(sampleChildren.item(j).getTextContent());
        }
 else         if (childName.equals("String_Node_Str")) {
          sample.setAltitude(Float.valueOf(sampleChildren.item(j).getTextContent()).shortValue());
        }
 else         if (childName.equals("String_Node_Str")) {
          sample.setTemperature(Float.valueOf(sampleChildren.item(j).getTextContent()).shortValue());
        }
 else         if (childName.equals("String_Node_Str")) {
        }
      }
      sample.setPosition(new Position(latitude,longitude));
      if (firstsample) {
        lastPosition=sample.getPosition();
        firstsample=false;
      }
      if (!distanceinsample) {
        lastDistance+=getDistanceFromPositions(lastPosition,sample.getPosition());
        sample.setDistance((int)lastDistance);
        lastPosition=sample.getPosition();
      }
      if (sample.getHeartRate() == 0)       sample.setHeartRate(lastSample.getHeartRate());
 else       lastSample.setHeartRate(sample.getHeartRate());
      exercise.getSampleList()[currentSampleNumber++]=sample;
      for (int j=0; j < 6; j++) {
        if (sample.getHeartRate() > exercise.getHeartRateLimits()[j].getUpperHeartRate()) {
          aboveZone[j]+=(currentOffset - lastOffset);
        }
 else         if (sample.getHeartRate() < exercise.getHeartRateLimits()[j].getLowerHeartRate()) {
          belowZone[j]+=(currentOffset - lastOffset);
        }
 else {
          inZone[j]+=(currentOffset - lastOffset);
        }
      }
    }
  }
  for (int i=0; i < 6; i++) {
    exercise.getHeartRateLimits()[i].setTimeAbove((short)aboveZone[i]);
    exercise.getHeartRateLimits()[i].setTimeBelow((short)belowZone[i]);
    exercise.getHeartRateLimits()[i].setTimeWithin((short)inZone[i]);
  }
  exercise.setRecordingInterval((short)2);
  return exercise;
}