Program: 19152
Project: 19152
Buggy source:
private File downloadCaches(@NonNull Coordinates coordinates) throws GeocachingApiException, NoResultFoundException {
  AuthenticatorHelper authenticatorHelper=App.get(this).getAuthenticatorHelper();
  if (!authenticatorHelper.hasAccount())   throw new InvalidCredentialsException("String_Node_Str");
  if (isCanceled())   return null;
  ACRA.getErrorReporter().putCustomData("String_Node_Str","String_Node_Str" + coordinates.toString(CoordinatesFormatter.LAT_LON_DECDEGREE_COMMA));
  GeocachingApi api=GeocachingApiFactory.create();
  GeocachingApi.ResultQuality resultQuality=authenticatorHelper.getRestrictions().isPremiumMember() ? GeocachingApi.ResultQuality.FULL : GeocachingApi.ResultQuality.SUMMARY;
  if (simpleCacheData) {
    resultQuality=GeocachingApi.ResultQuality.LITE;
    logCount=0;
  }
  StoreableListFileOutput slfo=null;
  try {
    File dataFile=ActionDisplayPointsExtended.getCacheFileName(this);
    login(api);
    String username=authenticatorHelper.getAccount().name;
    slfo=new StoreableListFileOutput(ActionDisplayPointsExtended.getCacheFileOutputStream(this));
    slfo.beginList();
    sendProgressUpdate();
    current=0;
    int cachesPerRequest=AppConstants.CACHES_PER_REQUEST;
    while (current < count) {
      long startTime=System.currentTimeMillis();
      List<Geocache> cachesToAdd;
      if (current == 0) {
        cachesToAdd=api.searchForGeocaches(resultQuality,Math.min(cachesPerRequest,count - current),logCount,0,Arrays.asList(new PointRadiusFilter(coordinates,(long)(distance * 1000)),new GeocacheTypeFilter(cacheTypes),new GeocacheContainerSizeFilter(containerTypes),new GeocacheExclusionsFilter(false,showDisabled ? null : true,null),new NotFoundByUsersFilter(showFound ? null : username),new NotHiddenByUsersFilter(showOwn ? null : username),new DifficultyFilter(difficultyMin,difficultyMax),new TerrainFilter(terrainMin,terrainMax),new BookmarksExcludeFilter(excludeIgnoreList)),null);
      }
 else {
        cachesToAdd=api.getMoreGeocaches(resultQuality,current,Math.min(cachesPerRequest,count - current),logCount,0);
      }
      if (!simpleCacheData)       authenticatorHelper.getRestrictions().updateLimits(api.getLastCacheLimits());
      if (isCanceled())       return null;
      if (cachesToAdd.size() == 0)       break;
      if (computeDistance(coordinates,cachesToAdd.get(cachesToAdd.size() - 1)) > distance) {
        removeCachesOverDistance(cachesToAdd,coordinates,distance);
        if (cachesToAdd.size() == 0)         break;
      }
      PackWaypoints pw=new PackWaypoints(PACK_WAYPOINT);
      List<Waypoint> waypoints=LocusDataMapper.toLocusPoints(this,cachesToAdd);
      for (      Waypoint wpt : waypoints) {
        if (simpleCacheData) {
          wpt.setExtraOnDisplay(getPackageName(),UpdateActivity.class.getName(),UpdateActivity.PARAM_SIMPLE_CACHE_ID,wpt.gcData.getCacheID());
        }
        pw.addWaypoint(wpt);
      }
      slfo.write(pw);
      current+=cachesToAdd.size();
      sendProgressUpdate();
      long requestDuration=System.currentTimeMillis() - startTime;
      cachesPerRequest=computeCachesPerRequest(cachesPerRequest,requestDuration);
    }
    slfo.endList();
    Timber.i("String_Node_Str" + current);
    if (current > 0) {
      return dataFile;
    }
 else {
      throw new NoResultFoundException();
    }
  }
 catch (  InvalidSessionException e) {
    Timber.e(e,e.getMessage());
    authenticatorHelper.invalidateAuthToken();
    throw e;
  }
catch (  IOException e) {
    Timber.e(e,e.getMessage());
    throw new GeocachingApiException(e.getMessage(),e);
  }
 finally {
    Utils.closeStream(slfo);
  }
}

Fixed version (ground truth):
private File downloadCaches(@NonNull Coordinates coordinates) throws GeocachingApiException, NoResultFoundException {
  AuthenticatorHelper authenticatorHelper=App.get(this).getAuthenticatorHelper();
  if (!authenticatorHelper.hasAccount())   throw new InvalidCredentialsException("String_Node_Str");
  if (isCanceled())   return null;
  ACRA.getErrorReporter().putCustomData("String_Node_Str","String_Node_Str" + coordinates.toString(CoordinatesFormatter.LAT_LON_DECDEGREE_COMMA));
  GeocachingApi api=GeocachingApiFactory.create();
  GeocachingApi.ResultQuality resultQuality=authenticatorHelper.getRestrictions().isPremiumMember() ? GeocachingApi.ResultQuality.FULL : GeocachingApi.ResultQuality.SUMMARY;
  if (simpleCacheData) {
    resultQuality=GeocachingApi.ResultQuality.LITE;
    logCount=0;
  }
  StoreableListFileOutput slfo=null;
  try {
    File dataFile=ActionDisplayPointsExtended.getCacheFileName(this);
    login(api);
    String username=authenticatorHelper.getAccount().name;
    slfo=new StoreableListFileOutput(ActionDisplayPointsExtended.getCacheFileOutputStream(this));
    slfo.beginList();
    sendProgressUpdate();
    current=0;
    int cachesPerRequest=AppConstants.CACHES_PER_REQUEST;
    while (current < count) {
      long startTime=System.currentTimeMillis();
      List<Geocache> cachesToAdd;
      if (current == 0) {
        cachesToAdd=api.searchForGeocaches(resultQuality,Math.min(cachesPerRequest,count - current),logCount,0,Arrays.asList(new PointRadiusFilter(coordinates,(long)(distance * 1000)),new GeocacheTypeFilter(cacheTypes),new GeocacheContainerSizeFilter(containerTypes),new GeocacheExclusionsFilter(false,showDisabled ? null : true,null),new NotFoundByUsersFilter(showFound ? null : username),new NotHiddenByUsersFilter(showOwn ? null : username),new DifficultyFilter(difficultyMin,difficultyMax),new TerrainFilter(terrainMin,terrainMax),new BookmarksExcludeFilter(excludeIgnoreList)),null);
      }
 else {
        cachesToAdd=api.getMoreGeocaches(resultQuality,current,Math.min(cachesPerRequest,count - current),logCount,0);
      }
      if (!simpleCacheData)       authenticatorHelper.getRestrictions().updateLimits(api.getLastGeocacheLimits());
      if (isCanceled())       return null;
      if (cachesToAdd.size() == 0)       break;
      if (computeDistance(coordinates,cachesToAdd.get(cachesToAdd.size() - 1)) > distance) {
        removeCachesOverDistance(cachesToAdd,coordinates,distance);
        if (cachesToAdd.size() == 0)         break;
      }
      PackWaypoints pw=new PackWaypoints(PACK_WAYPOINT);
      List<Waypoint> waypoints=LocusDataMapper.toLocusPoints(this,cachesToAdd);
      for (      Waypoint wpt : waypoints) {
        if (simpleCacheData) {
          wpt.setExtraOnDisplay(getPackageName(),UpdateActivity.class.getName(),UpdateActivity.PARAM_SIMPLE_CACHE_ID,wpt.gcData.getCacheID());
        }
        pw.addWaypoint(wpt);
      }
      slfo.write(pw);
      current+=cachesToAdd.size();
      sendProgressUpdate();
      long requestDuration=System.currentTimeMillis() - startTime;
      cachesPerRequest=computeCachesPerRequest(cachesPerRequest,requestDuration);
    }
    slfo.endList();
    Timber.i("String_Node_Str" + current);
    if (current > 0) {
      return dataFile;
    }
 else {
      throw new NoResultFoundException();
    }
  }
 catch (  InvalidSessionException e) {
    Timber.e(e,e.getMessage());
    authenticatorHelper.invalidateAuthToken();
    throw e;
  }
catch (  IOException e) {
    Timber.e(e,e.getMessage());
    throw new GeocachingApiException(e.getMessage(),e);
  }
 finally {
    Utils.closeStream(slfo);
  }
}