Program: 35423
Project: 35423
Buggy source:
public void addPoints(PointList geom){
  int nPoints=geom.getSize() - 1;
  if (nPoints == 0)   return;
  if (_prevSegmentItem != null)   _startIndex=_prevSegmentItem.getTo();
  int j0=0;
  if (_firstSegment) {
    j0=1;
    _x0=geom.getLon(0);
    _y0=geom.getLat(0);
    _z0=geom.getEle(0);
    _maxAltitude=_z0;
    _minAltitude=_z0;
    _pointsCount++;
    _firstSegment=false;
  }
  for (int j=j0; j < nPoints; ++j) {
    _x1=geom.getLon(j);
    _y1=geom.getLat(j);
    _z1=geom.getEle(j);
    _elevDiff=_z1 - _z0;
    _cumElevation+=_elevDiff;
    double segLength=_distCalc.calcDist(_y0,_x0,_y1,_x1);
    _prevMinAltitude=_minAltitude;
    _prevMaxAltitude=_maxAltitude;
    if (_z1 > _maxAltitude)     _maxAltitude=_z1;
    if (_z1 < _minAltitude)     _minAltitude=_z1;
    if ((_prevMaxAltitude - _z1 > SteepnessUtil.ELEVATION_THRESHOLD || _z1 - _prevMinAltitude > SteepnessUtil.ELEVATION_THRESHOLD) && _splitLength > 30) {
      boolean bApply=true;
      int elevSign=(_cumElevation - _elevDiff) > 0 ? 1 : -1;
      double gradient=elevSign * 100 * (_prevMaxAltitude - _prevMinAltitude) / _splitLength;
      if (_prevGradientCat != 0) {
        double zn=Double.MIN_NORMAL;
        if (j + 1 < nPoints)         zn=geom.getEle(j + 1);
        if (zn != Double.MIN_VALUE) {
          double elevGap=segLength / 30;
          if (elevSign > 0 && _prevGradientCat > 0) {
            if (Math.abs(zn - _z1) < elevGap)             bApply=false;
          }
 else           if (_prevGradientCat < 0) {
            if (Math.abs(zn - _z1) < elevGap)             bApply=false;
          }
        }
      }
      if (bApply) {
        int gradientCat=SteepnessUtil.getCategory(gradient);
        int iEnd=_pointsCount - 1;
        if (_prevGradientCat == gradientCat && _prevSegmentItem != null) {
          _prevSegmentItem.setTo(iEnd);
          _prevSegmentItem.setDistance(_prevSegmentItem.getDistance() + _splitLength);
        }
 else {
          RouteSegmentItem item=new RouteSegmentItem(_startIndex,iEnd,gradientCat,_splitLength);
          _extraInfo.add(item);
          _prevSegmentItem=item;
        }
        _prevGradientCat=gradientCat;
        _startIndex=iEnd;
        _minAltitude=Math.min(_z0,_z1);
        _maxAltitude=Math.max(_z0,_z1);
        _splitLength=0.0;
        _cumElevation=_elevDiff;
      }
    }
    _splitLength+=segLength;
    _x0=_x1;
    _y0=_y1;
    _z0=_z1;
    _pointsCount++;
  }
  if (_splitLength > 0) {
    int iEnd=_pointsCount;
    _elevDiff=_maxAltitude - _minAltitude;
    if (_extraInfo.isEmpty() && _splitLength < 50 && _elevDiff < SteepnessUtil.ELEVATION_THRESHOLD)     _elevDiff=0;
    double gradient=(_cumElevation > 0 ? 1 : -1) * 100 * _elevDiff / _splitLength;
    int gc=SteepnessUtil.getCategory(gradient);
    if (_prevSegmentItem != null && (_prevGradientCat == gc || _splitLength < 30)) {
      _prevSegmentItem.setTo(iEnd);
    }
 else {
      RouteSegmentItem item=new RouteSegmentItem(_startIndex,iEnd,_prevGradientCat,_splitLength);
      _extraInfo.add(item);
      _prevSegmentItem=item;
    }
  }
}

Fixed version (ground truth):
public void addPoints(PointList geom){
  int nPoints=geom.getSize() - 1;
  if (nPoints == 0)   return;
  if (_prevSegmentItem != null)   _startIndex=_prevSegmentItem.getTo();
  int j0=0;
  if (_firstSegment) {
    j0=1;
    _x0=geom.getLon(0);
    _y0=geom.getLat(0);
    _z0=geom.getEle(0);
    _maxAltitude=_z0;
    _minAltitude=_z0;
    _pointsCount++;
    _firstSegment=false;
  }
  for (int j=j0; j < nPoints; ++j) {
    _x1=geom.getLon(j);
    _y1=geom.getLat(j);
    _z1=geom.getEle(j);
    _elevDiff=_z1 - _z0;
    _cumElevation+=_elevDiff;
    double segLength=_distCalc.calcDist(_y0,_x0,_y1,_x1);
    _prevMinAltitude=_minAltitude;
    _prevMaxAltitude=_maxAltitude;
    if (_z1 > _maxAltitude)     _maxAltitude=_z1;
    if (_z1 < _minAltitude)     _minAltitude=_z1;
    if ((_prevMaxAltitude - _z1 > SteepnessUtil.ELEVATION_THRESHOLD || _z1 - _prevMinAltitude > SteepnessUtil.ELEVATION_THRESHOLD) && _splitLength > 30) {
      boolean bApply=true;
      int elevSign=(_cumElevation - _elevDiff) > 0 ? 1 : -1;
      double gradient=elevSign * 100 * (_prevMaxAltitude - _prevMinAltitude) / _splitLength;
      if (_prevGradientCat != 0) {
        double zn=Double.MIN_NORMAL;
        if (j + 1 < nPoints)         zn=geom.getEle(j + 1);
        if (zn != Double.MIN_VALUE) {
          double elevGap=segLength / 30;
          if (elevSign > 0 && _prevGradientCat > 0) {
            if (Math.abs(zn - _z1) < elevGap)             bApply=false;
          }
 else           if (_prevGradientCat < 0) {
            if (Math.abs(zn - _z1) < elevGap)             bApply=false;
          }
        }
      }
      if (bApply) {
        int gradientCat=SteepnessUtil.getCategory(gradient);
        int iEnd=_startIndex + _pointsCount;
        if (_prevGradientCat == gradientCat && _prevSegmentItem != null) {
          _prevSegmentItem.setTo(iEnd);
          _prevSegmentItem.setDistance(_prevSegmentItem.getDistance() + _splitLength);
        }
 else {
          RouteSegmentItem item=new RouteSegmentItem(_startIndex,iEnd,gradientCat,_splitLength);
          _extraInfo.add(item);
          _prevSegmentItem=item;
        }
        _pointsCount=0;
        _startIndex=iEnd;
        _prevGradientCat=gradientCat;
        _minAltitude=Math.min(_z0,_z1);
        _maxAltitude=Math.max(_z0,_z1);
        _splitLength=0.0;
        _cumElevation=_elevDiff;
      }
    }
    _splitLength+=segLength;
    _x0=_x1;
    _y0=_y1;
    _z0=_z1;
    _pointsCount++;
  }
  if (_splitLength > 0) {
    _elevDiff=_maxAltitude - _minAltitude;
    if (_extraInfo.isEmpty() && _splitLength < 50 && _elevDiff < SteepnessUtil.ELEVATION_THRESHOLD)     _elevDiff=0;
    double gradient=(_cumElevation > 0 ? 1 : -1) * 100 * _elevDiff / _splitLength;
    int gradientCat=SteepnessUtil.getCategory(gradient);
    if (_prevSegmentItem != null && (_prevGradientCat == gradientCat || _splitLength < 30)) {
      _prevSegmentItem.setTo(_startIndex + _pointsCount);
    }
 else {
      RouteSegmentItem item=new RouteSegmentItem(_startIndex,_startIndex + _pointsCount,gradientCat,_splitLength);
      _extraInfo.add(item);
      _prevSegmentItem=item;
      _prevGradientCat=gradientCat;
      _pointsCount=0;
    }
  }
}