Program: 19223
Project: 19223
Buggy source:
private void CalculateBoundsForFeatureSet() throws IOException {
  FeatureType featype=this.getDatasetFeatureType();
  if (featype != null) {
    this.stationDateRange=new HashMap<Integer,CalendarDateRange>();
    this.stationBBox=new HashMap<Integer,LatLonRect>();
    CalendarDate start=null, end=null;
    int stationIndex=0;
switch (featype) {
case TRAJECTORY:
      try {
        TrajectoryFeatureCollection collection=(TrajectoryFeatureCollection)getFeatureTypeDataSet();
        collection.resetIteration();
        while (collection.hasNext()) {
          TrajectoryFeature feature=collection.next();
          if (DatasetHandlerAdapter.calcBounds(feature)) {
            if (start == null || start.isAfter(feature.getCalendarDateRange().getStart())) {
              start=feature.getCalendarDateRange().getStart();
            }
            if (end == null || end.isBefore(feature.getCalendarDateRange().getEnd())) {
              end=feature.getCalendarDateRange().getEnd();
            }
            this.stationDateRange.put(stationIndex,feature.getCalendarDateRange());
            this.stationBBox.put(stationIndex,feature.getBoundingBox());
            stationIndex++;
          }
 else {
            GetExtentsFromSubFeatures(feature,stationIndex);
          }
        }
      }
 catch (      Exception ex) {
        _log.error(ex.getMessage(),ex);
      }
    break;
case STATION:
  try {
    StationTimeSeriesFeatureCollection collection=(StationTimeSeriesFeatureCollection)getFeatureTypeDataSet();
    collection.resetIteration();
    while (collection.hasNext()) {
      StationTimeSeriesFeature feature=collection.next();
      if (DatasetHandlerAdapter.calcBounds(feature)) {
        if (start == null || start.isAfter(feature.getCalendarDateRange().getStart())) {
          start=feature.getCalendarDateRange().getStart();
        }
        if (end == null || end.isBefore(feature.getCalendarDateRange().getEnd())) {
          end=feature.getCalendarDateRange().getEnd();
        }
        this.stationDateRange.put(stationIndex,feature.getCalendarDateRange());
        this.stationBBox.put(stationIndex,feature.getBoundingBox());
      }
 else {
        GetExtentsFromSubFeatures(feature,stationIndex);
      }
      stationIndex++;
    }
  }
 catch (  Exception ex) {
    _log.error(ex.getMessage(),ex);
  }
break;
case PROFILE:
try {
ProfileFeatureCollection collection=(ProfileFeatureCollection)getFeatureTypeDataSet();
collection.resetIteration();
while (collection.hasNext()) {
  ProfileFeature feature=collection.next();
  if (DatasetHandlerAdapter.calcBounds(feature)) {
    CalendarDate profileDate=CalendarDate.of(feature.getTime());
    if (start == null || start.isAfter(profileDate)) {
      start=profileDate;
    }
    if (end == null || end.isBefore(profileDate)) {
      end=profileDate;
    }
    this.stationDateRange.put(stationIndex,CalendarDateRange.of(profileDate,profileDate));
    this.stationBBox.put(stationIndex,new LatLonRect(feature.getLatLon(),feature.getLatLon()));
    stationIndex++;
  }
 else {
    GetExtentsFromSubFeatures(feature,stationIndex);
  }
}
}
 catch (Exception ex) {
_log.error(ex.getMessage(),ex);
}
break;
case GRID:
start=getGridDataset().getCalendarDateStart();
end=getGridDataset().getCalendarDateEnd();
this.stationDateRange.put(0,CalendarDateRange.of(start,end));
break;
case STATION_PROFILE:
try {
CalendarDateRange nullrange=null;
StationProfileFeatureCollection collection=(StationProfileFeatureCollection)getFeatureTypeDataSet();
collection.resetIteration();
while (collection.hasNext()) {
StationProfileFeature feature=collection.next();
PointFeatureCollection flattened=feature.flatten(null,nullrange);
if (DatasetHandlerAdapter.calcBounds(flattened)) {
if (start == null || start.isAfter(flattened.getCalendarDateRange().getStart())) {
start=flattened.getCalendarDateRange().getStart();
}
if (end == null || end.isBefore(flattened.getCalendarDateRange().getEnd())) {
end=flattened.getCalendarDateRange().getEnd();
}
this.stationDateRange.put(stationIndex,flattened.getCalendarDateRange());
this.stationBBox.put(stationIndex,flattened.getBoundingBox());
stationIndex++;
}
 else {
GetExtentsFromSubFeatures(flattened,stationIndex);
}
}
}
 catch (Exception ex) {
_log.error(ex.getMessage(),ex);
}
break;
case SECTION:
try {
CalendarDateRange nullrange=null;
SectionFeatureCollection collection=(SectionFeatureCollection)getFeatureTypeDataSet();
collection.resetIteration();
while (collection.hasNext()) {
SectionFeature feature=collection.next();
PointFeatureCollection flattened=feature.flatten(null,nullrange);
if (DatasetHandlerAdapter.calcBounds(flattened)) {
if (start == null || start.isAfter(flattened.getCalendarDateRange().getStart())) {
start=flattened.getCalendarDateRange().getStart();
}
if (end == null || end.isBefore(flattened.getCalendarDateRange().getEnd())) {
end=flattened.getCalendarDateRange().getEnd();
}
this.stationDateRange.put(stationIndex,flattened.getCalendarDateRange());
this.stationBBox.put(stationIndex,flattened.getBoundingBox());
stationIndex++;
}
 else {
GetExtentsFromSubFeatures(flattened,stationIndex);
}
}
}
 catch (Exception ex) {
_log.error(ex.getMessage(),ex);
}
break;
case POINT:
_log.error("String_Node_Str");
formatter=new ErrorFormatter();
((ErrorFormatter)formatter).setException("String_Node_Str");
return;
default :
_log.error("String_Node_Str");
formatter=new ErrorFormatter();
((ErrorFormatter)formatter).setException("String_Node_Str");
return;
}
this.setStartDate=start;
this.setEndDate=end;
}
 else {
_log.error("String_Node_Str");
}
}

Fixed version (ground truth):
private void CalculateBoundsForFeatureSet() throws IOException {
  FeatureType featype=this.getDatasetFeatureType();
  if (featype != null) {
    this.stationDateRange=new HashMap<Integer,CalendarDateRange>();
    this.stationBBox=new HashMap<Integer,LatLonRect>();
    CalendarDate start=null, end=null;
    int stationIndex=0;
switch (featype) {
case TRAJECTORY:
      try {
        TrajectoryFeatureCollection collection=(TrajectoryFeatureCollection)getFeatureTypeDataSet();
        collection.resetIteration();
        while (collection.hasNext()) {
          TrajectoryFeature feature=collection.next();
          if (DatasetHandlerAdapter.calcBounds(feature)) {
            if (start == null || start.isAfter(feature.getCalendarDateRange().getStart())) {
              start=feature.getCalendarDateRange().getStart();
            }
            if (end == null || end.isBefore(feature.getCalendarDateRange().getEnd())) {
              end=feature.getCalendarDateRange().getEnd();
            }
            this.stationDateRange.put(stationIndex,feature.getCalendarDateRange());
            this.stationBBox.put(stationIndex,feature.getBoundingBox());
            stationIndex++;
          }
 else {
            GetExtentsFromSubFeatures(feature,stationIndex);
          }
        }
      }
 catch (      Exception ex) {
        _log.error(ex.getMessage(),ex);
      }
    break;
case STATION:
  try {
    StationTimeSeriesFeatureCollection collection=(StationTimeSeriesFeatureCollection)getFeatureTypeDataSet();
    collection.resetIteration();
    while (collection.hasNext()) {
      StationTimeSeriesFeature feature=collection.next();
      if (DatasetHandlerAdapter.calcBounds(feature)) {
        if (start == null || start.isAfter(feature.getCalendarDateRange().getStart())) {
          start=feature.getCalendarDateRange().getStart();
        }
        if (end == null || end.isBefore(feature.getCalendarDateRange().getEnd())) {
          end=feature.getCalendarDateRange().getEnd();
        }
        this.stationDateRange.put(stationIndex,feature.getCalendarDateRange());
        this.stationBBox.put(stationIndex,feature.getBoundingBox());
      }
 else {
        GetExtentsFromSubFeatures(feature,stationIndex);
      }
      stationIndex++;
    }
  }
 catch (  Exception ex) {
    _log.error(ex.getMessage(),ex);
  }
break;
case PROFILE:
try {
ProfileFeatureCollection collection=(ProfileFeatureCollection)getFeatureTypeDataSet();
collection.resetIteration();
while (collection.hasNext()) {
  ProfileFeature feature=collection.next();
  if (DatasetHandlerAdapter.calcBounds(feature)) {
    CalendarDate profileDate=CalendarDate.of(feature.getTime());
    if (start == null || start.isAfter(profileDate)) {
      start=profileDate;
    }
    if (end == null || end.isBefore(profileDate)) {
      end=profileDate;
    }
    this.stationDateRange.put(stationIndex,CalendarDateRange.of(profileDate,profileDate));
    this.stationBBox.put(stationIndex,new LatLonRect(feature.getLatLon(),feature.getLatLon()));
    stationIndex++;
  }
 else {
    GetExtentsFromSubFeatures(feature,stationIndex);
  }
}
}
 catch (Exception ex) {
_log.error(ex.getMessage(),ex);
}
break;
case GRID:
GridDataset gridData=getGridDataset();
start=gridData.getCalendarDateStart();
end=gridData.getCalendarDateEnd();
this.stationDateRange.put(0,CalendarDateRange.of(start,end));
this.stationBBox.put(0,gridData.getBoundingBox());
break;
case STATION_PROFILE:
try {
CalendarDateRange nullrange=null;
StationProfileFeatureCollection collection=(StationProfileFeatureCollection)getFeatureTypeDataSet();
collection.resetIteration();
while (collection.hasNext()) {
StationProfileFeature feature=collection.next();
PointFeatureCollection flattened=feature.flatten(null,nullrange);
if (DatasetHandlerAdapter.calcBounds(flattened)) {
if (start == null || start.isAfter(flattened.getCalendarDateRange().getStart())) {
start=flattened.getCalendarDateRange().getStart();
}
if (end == null || end.isBefore(flattened.getCalendarDateRange().getEnd())) {
end=flattened.getCalendarDateRange().getEnd();
}
this.stationDateRange.put(stationIndex,flattened.getCalendarDateRange());
this.stationBBox.put(stationIndex,flattened.getBoundingBox());
stationIndex++;
}
 else {
GetExtentsFromSubFeatures(flattened,stationIndex);
}
}
}
 catch (Exception ex) {
_log.error(ex.getMessage(),ex);
}
break;
case SECTION:
try {
CalendarDateRange nullrange=null;
SectionFeatureCollection collection=(SectionFeatureCollection)getFeatureTypeDataSet();
collection.resetIteration();
while (collection.hasNext()) {
SectionFeature feature=collection.next();
PointFeatureCollection flattened=feature.flatten(null,nullrange);
if (DatasetHandlerAdapter.calcBounds(flattened)) {
if (start == null || start.isAfter(flattened.getCalendarDateRange().getStart())) {
start=flattened.getCalendarDateRange().getStart();
}
if (end == null || end.isBefore(flattened.getCalendarDateRange().getEnd())) {
end=flattened.getCalendarDateRange().getEnd();
}
this.stationDateRange.put(stationIndex,flattened.getCalendarDateRange());
this.stationBBox.put(stationIndex,flattened.getBoundingBox());
stationIndex++;
}
 else {
GetExtentsFromSubFeatures(flattened,stationIndex);
}
}
}
 catch (Exception ex) {
_log.error(ex.getMessage(),ex);
}
break;
case POINT:
_log.error("String_Node_Str");
formatter=new ErrorFormatter();
((ErrorFormatter)formatter).setException("String_Node_Str");
return;
default :
_log.error("String_Node_Str");
formatter=new ErrorFormatter();
((ErrorFormatter)formatter).setException("String_Node_Str");
return;
}
this.setStartDate=start;
this.setEndDate=end;
}
 else {
_log.error("String_Node_Str");
}
}