Program: 142352
Project: 142352
Buggy source:
protected Integer doInBackground(Void... params){
  publishProgress(PROGRESS_STARTED);
  boolean loginNeeded=true;
  try {
    loginNeeded=!CommCareApplication._().getSession().isLoggedIn();
  }
 catch (  SessionUnavailableException sue) {
  }
  SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(c);
  prefs.edit().putLong("String_Node_Str",new Date().getTime()).commit();
  CommCareTransactionParserFactory factory=new CommCareTransactionParserFactory(c){
    @Override public void reportProgress(    int progress){
      DataPullTask.this.publishProgress(PROGRESS_AUTHED,progress);
    }
  }
;
  Logger.log(AndroidLogger.TYPE_USER,"String_Node_Str");
  HttpRequestGenerator requestor=new HttpRequestGenerator(username,password);
  try {
    SecretKeySpec spec=null;
    if (loginNeeded) {
      spec=generateTestKey();
      if (spec == null) {
        this.publishProgress(PROGRESS_DONE);
        return UNKNOWN_FAILURE;
      }
      byte[] wrappedKey=CryptUtil.wrapKey(spec,password);
      factory.initUserParser(wrappedKey);
    }
 else {
      factory.initUserParser(CommCareApplication._().getSession().getLoggedInUser().getWrappedKey());
    }
    if (loginNeeded) {
      CommCareApplication._().logIn(spec.getEncoded(),null);
    }
    purgeCases();
    this.publishProgress(PROGRESS_CLEANED);
    HttpResponse response=requestor.makeCaseFetchRequest(server);
    int responseCode=response.getStatusLine().getStatusCode();
    if (responseCode == 401) {
      if (loginNeeded) {
        CommCareApplication._().logout();
      }
      Logger.log(AndroidLogger.TYPE_USER,"String_Node_Str" + username);
      return AUTH_FAILED;
    }
 else     if (responseCode >= 200 && responseCode < 300) {
      this.publishProgress(PROGRESS_AUTHED,0);
      Logger.log(AndroidLogger.TYPE_USER,"String_Node_Str" + username);
      int dataSizeGuess=-1;
      if (response.containsHeader("String_Node_Str")) {
        String length=response.getFirstHeader("String_Node_Str").getValue();
        try {
          dataSizeGuess=Integer.parseInt(length);
        }
 catch (        Exception e) {
        }
      }
      BitCache cache=BitCacheFactory.getCache(c,dataSizeGuess);
      cache.initializeCache();
      try {
        OutputStream cacheOut=cache.getCacheStream();
        AndroidStreamUtil.writeFromInputToOutput(response.getEntity().getContent(),cacheOut);
        InputStream cacheIn=cache.retrieveCache();
        String syncToken=readInput(cacheIn,factory);
        updateUserSyncToken(syncToken);
        Editor e=prefs.edit();
        e.putLong("String_Node_Str",new Date().getTime());
        e.commit();
        Logger.log(AndroidLogger.TYPE_USER,"String_Node_Str" + username);
        this.publishProgress(PROGRESS_DONE);
        return DOWNLOAD_SUCCESS;
      }
 catch (      InvalidStructureException e) {
        e.printStackTrace();
        Logger.log(AndroidLogger.TYPE_USER,"String_Node_Str" + e.getMessage());
        return BAD_DATA;
      }
catch (      XmlPullParserException e) {
        e.printStackTrace();
        Logger.log(AndroidLogger.TYPE_USER,"String_Node_Str" + e.getMessage());
        return BAD_DATA;
      }
catch (      UnfullfilledRequirementsException e) {
        e.printStackTrace();
        Logger.log(AndroidLogger.TYPE_ERROR_ASSERTION,"String_Node_Str" + e.getMessage());
      }
catch (      IllegalStateException e) {
        e.printStackTrace();
        Logger.log(AndroidLogger.TYPE_ERROR_ASSERTION,"String_Node_Str" + e.getMessage());
      }
catch (      StorageFullException e) {
        e.printStackTrace();
        Logger.log(AndroidLogger.TYPE_ERROR_ASSERTION,"String_Node_Str" + e.getMessage());
      }
 finally {
        cache.release();
      }
    }
 else     if (responseCode == 412) {
      int returnCode=recover(requestor,factory);
      if (returnCode == PROGRESS_DONE) {
        this.publishProgress(PROGRESS_DONE);
        return DOWNLOAD_SUCCESS;
      }
 else       if (returnCode == PROGRESS_RECOVERY_FAIL_SAFE) {
        if (loginNeeded) {
          CommCareApplication._().logout();
        }
        this.publishProgress(PROGRESS_DONE);
        return UNKNOWN_FAILURE;
      }
 else       if (returnCode == PROGRESS_RECOVERY_FAIL_BAD) {
        if (loginNeeded) {
          CommCareApplication._().logout();
        }
        this.publishProgress(PROGRESS_DONE);
        return UNKNOWN_FAILURE;
      }
      if (loginNeeded) {
        CommCareApplication._().logout();
      }
    }
  }
 catch (  ClientProtocolException e) {
    e.printStackTrace();
    Logger.log(AndroidLogger.TYPE_WARNING_NETWORK,"String_Node_Str" + e.getMessage());
  }
catch (  UnknownHostException e) {
    this.publishProgress(PROGRESS_DONE);
    if (loginNeeded) {
      CommCareApplication._().logout();
    }
    Logger.log(AndroidLogger.TYPE_WARNING_NETWORK,"String_Node_Str");
    return UNREACHABLE_HOST;
  }
catch (  IOException e) {
    e.printStackTrace();
    Logger.log(AndroidLogger.TYPE_WARNING_NETWORK,"String_Node_Str" + e.getMessage());
  }
catch (  SessionUnavailableException sue) {
    sue.printStackTrace();
    CommCareApplication._().logout();
  }
  if (loginNeeded) {
    CommCareApplication._().logout();
  }
  this.publishProgress(PROGRESS_DONE);
  return UNKNOWN_FAILURE;
}

Fixed version (ground truth):
protected Integer doInBackground(Void... params){
  publishProgress(PROGRESS_STARTED);
  boolean loginNeeded=true;
  boolean useRequestFlags=false;
  try {
    loginNeeded=!CommCareApplication._().getSession().isLoggedIn();
  }
 catch (  SessionUnavailableException sue) {
  }
  SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(c);
  prefs.edit().putLong("String_Node_Str",new Date().getTime()).commit();
  CommCareTransactionParserFactory factory=new CommCareTransactionParserFactory(c){
    @Override public void reportProgress(    int progress){
      DataPullTask.this.publishProgress(PROGRESS_AUTHED,progress);
    }
  }
;
  Logger.log(AndroidLogger.TYPE_USER,"String_Node_Str");
  HttpRequestGenerator requestor=new HttpRequestGenerator(username,password);
  try {
    SecretKeySpec spec=null;
    if (loginNeeded) {
      spec=generateTestKey();
      if (spec == null) {
        this.publishProgress(PROGRESS_DONE);
        return UNKNOWN_FAILURE;
      }
      byte[] wrappedKey=CryptUtil.wrapKey(spec,password);
      factory.initUserParser(wrappedKey);
    }
 else {
      factory.initUserParser(CommCareApplication._().getSession().getLoggedInUser().getWrappedKey());
      purgeCases();
      useRequestFlags=true;
    }
    this.publishProgress(PROGRESS_CLEANED);
    if (loginNeeded) {
      CommCareApplication._().logIn(spec.getEncoded(),null);
    }
    HttpResponse response=requestor.makeCaseFetchRequest(server,useRequestFlags);
    int responseCode=response.getStatusLine().getStatusCode();
    if (responseCode == 401) {
      if (loginNeeded) {
        CommCareApplication._().logout();
      }
      Logger.log(AndroidLogger.TYPE_USER,"String_Node_Str" + username);
      return AUTH_FAILED;
    }
 else     if (responseCode >= 200 && responseCode < 300) {
      this.publishProgress(PROGRESS_AUTHED,0);
      Logger.log(AndroidLogger.TYPE_USER,"String_Node_Str" + username);
      int dataSizeGuess=-1;
      if (response.containsHeader("String_Node_Str")) {
        String length=response.getFirstHeader("String_Node_Str").getValue();
        try {
          dataSizeGuess=Integer.parseInt(length);
        }
 catch (        Exception e) {
        }
      }
      BitCache cache=BitCacheFactory.getCache(c,dataSizeGuess);
      cache.initializeCache();
      try {
        OutputStream cacheOut=cache.getCacheStream();
        AndroidStreamUtil.writeFromInputToOutput(response.getEntity().getContent(),cacheOut);
        InputStream cacheIn=cache.retrieveCache();
        String syncToken=readInput(cacheIn,factory);
        updateUserSyncToken(syncToken);
        Editor e=prefs.edit();
        e.putLong("String_Node_Str",new Date().getTime());
        e.commit();
        Logger.log(AndroidLogger.TYPE_USER,"String_Node_Str" + username);
        this.publishProgress(PROGRESS_DONE);
        return DOWNLOAD_SUCCESS;
      }
 catch (      InvalidStructureException e) {
        e.printStackTrace();
        Logger.log(AndroidLogger.TYPE_USER,"String_Node_Str" + e.getMessage());
        return BAD_DATA;
      }
catch (      XmlPullParserException e) {
        e.printStackTrace();
        Logger.log(AndroidLogger.TYPE_USER,"String_Node_Str" + e.getMessage());
        return BAD_DATA;
      }
catch (      UnfullfilledRequirementsException e) {
        e.printStackTrace();
        Logger.log(AndroidLogger.TYPE_ERROR_ASSERTION,"String_Node_Str" + e.getMessage());
      }
catch (      IllegalStateException e) {
        e.printStackTrace();
        Logger.log(AndroidLogger.TYPE_ERROR_ASSERTION,"String_Node_Str" + e.getMessage());
      }
catch (      StorageFullException e) {
        e.printStackTrace();
        Logger.log(AndroidLogger.TYPE_ERROR_ASSERTION,"String_Node_Str" + e.getMessage());
      }
 finally {
        cache.release();
      }
    }
 else     if (responseCode == 412) {
      int returnCode=recover(requestor,factory);
      if (returnCode == PROGRESS_DONE) {
        this.publishProgress(PROGRESS_DONE);
        return DOWNLOAD_SUCCESS;
      }
 else       if (returnCode == PROGRESS_RECOVERY_FAIL_SAFE) {
        if (loginNeeded) {
          CommCareApplication._().logout();
        }
        this.publishProgress(PROGRESS_DONE);
        return UNKNOWN_FAILURE;
      }
 else       if (returnCode == PROGRESS_RECOVERY_FAIL_BAD) {
        if (loginNeeded) {
          CommCareApplication._().logout();
        }
        this.publishProgress(PROGRESS_DONE);
        return UNKNOWN_FAILURE;
      }
      if (loginNeeded) {
        CommCareApplication._().logout();
      }
    }
  }
 catch (  ClientProtocolException e) {
    e.printStackTrace();
    Logger.log(AndroidLogger.TYPE_WARNING_NETWORK,"String_Node_Str" + e.getMessage());
  }
catch (  UnknownHostException e) {
    this.publishProgress(PROGRESS_DONE);
    if (loginNeeded) {
      CommCareApplication._().logout();
    }
    Logger.log(AndroidLogger.TYPE_WARNING_NETWORK,"String_Node_Str");
    return UNREACHABLE_HOST;
  }
catch (  IOException e) {
    e.printStackTrace();
    Logger.log(AndroidLogger.TYPE_WARNING_NETWORK,"String_Node_Str" + e.getMessage());
  }
catch (  SessionUnavailableException sue) {
    sue.printStackTrace();
    CommCareApplication._().logout();
  }
  if (loginNeeded) {
    CommCareApplication._().logout();
  }
  this.publishProgress(PROGRESS_DONE);
  return UNKNOWN_FAILURE;
}