Program: 142380
Project: 142380
Buggy source:
protected Integer doInBackground(Void... params){
  boolean loginNeeded=true;
  try {
    loginNeeded=!CommCareApplication._().getSession().isLoggedIn();
  }
 catch (  SessionUnavailableException sue) {
  }
  if (loginNeeded) {
    SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(c);
    if ("String_Node_Str".equals(prefs.getString("String_Node_Str","String_Node_Str"))) {
      Editor e=prefs.edit();
      e.putLong("String_Node_Str",new Date().getTime());
      e.commit();
    }
  }
  CommCareTransactionParserFactory factory=new CommCareTransactionParserFactory(c){
    @Override public void reportProgress(    int progress){
      DataPullTask.this.publishProgress(PROGRESS_AUTHED,progress);
    }
  }
;
  DefaultHttpClient client=new DefaultHttpClient();
  client.getCredentialsProvider().setCredentials(AuthScope.ANY,credentials);
  try {
    SecretKeySpec spec=null;
    if (loginNeeded) {
      spec=generateTestKey();
      if (spec == null) {
        this.publishProgress(PROGRESS_DONE);
        return UNKNOWN_FAILURE;
      }
      byte[] wrappedKey=CryptUtil.wrapKey(spec,credentials.getPassword());
      factory.initUserParser(wrappedKey);
    }
    HttpResponse response=client.execute(new HttpGet(server));
    int responseCode=response.getStatusLine().getStatusCode();
    if (responseCode == 401) {
      return AUTH_FAILED;
    }
    if (responseCode >= 200 && responseCode < 300) {
      this.publishProgress(PROGRESS_AUTHED,0);
      if (loginNeeded) {
        CommCareApplication._().logIn(spec.getEncoded(),null);
      }
      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();
        readInput(cacheIn,factory);
        this.publishProgress(PROGRESS_DONE);
        return DOWNLOAD_SUCCESS;
      }
 catch (      InvalidStructureException e) {
        e.printStackTrace();
        return BAD_DATA;
      }
catch (      XmlPullParserException e) {
        e.printStackTrace();
        return BAD_DATA;
      }
catch (      UnfullfilledRequirementsException e) {
        e.printStackTrace();
      }
catch (      IllegalStateException e) {
        e.printStackTrace();
      }
 finally {
        cache.release();
      }
    }
  }
 catch (  ClientProtocolException e) {
    e.printStackTrace();
  }
catch (  UnknownHostException e) {
    this.publishProgress(PROGRESS_DONE);
    return UNREACHABLE_HOST;
  }
catch (  IOException e) {
    e.printStackTrace();
  }
catch (  SessionUnavailableException sue) {
  }
  this.publishProgress(PROGRESS_DONE);
  return UNKNOWN_FAILURE;
}

Fixed version (ground truth):
protected Integer doInBackground(Void... params){
  boolean loginNeeded=true;
  try {
    loginNeeded=!CommCareApplication._().getSession().isLoggedIn();
  }
 catch (  SessionUnavailableException sue) {
  }
  if (loginNeeded) {
    SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(c);
    if ("String_Node_Str".equals(prefs.getString("String_Node_Str","String_Node_Str"))) {
      Editor e=prefs.edit();
      e.putLong("String_Node_Str",new Date().getTime());
      e.commit();
    }
  }
  CommCareTransactionParserFactory factory=new CommCareTransactionParserFactory(c){
    @Override public void reportProgress(    int progress){
      DataPullTask.this.publishProgress(PROGRESS_AUTHED,progress);
    }
  }
;
  DefaultHttpClient client=new DefaultHttpClient();
  client.getCredentialsProvider().setCredentials(AuthScope.ANY,credentials);
  try {
    SecretKeySpec spec=null;
    if (loginNeeded) {
      spec=generateTestKey();
      if (spec == null) {
        this.publishProgress(PROGRESS_DONE);
        return UNKNOWN_FAILURE;
      }
      byte[] wrappedKey=CryptUtil.wrapKey(spec,credentials.getPassword());
      factory.initUserParser(wrappedKey);
    }
    HttpResponse response=client.execute(new HttpGet(server));
    int responseCode=response.getStatusLine().getStatusCode();
    if (responseCode == 401) {
      return AUTH_FAILED;
    }
    if (responseCode >= 200 && responseCode < 300) {
      this.publishProgress(PROGRESS_AUTHED,0);
      if (loginNeeded) {
        CommCareApplication._().logIn(spec.getEncoded(),null);
      }
      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();
        readInput(cacheIn,factory);
        this.publishProgress(PROGRESS_DONE);
        return DOWNLOAD_SUCCESS;
      }
 catch (      InvalidStructureException e) {
        e.printStackTrace();
        return BAD_DATA;
      }
catch (      XmlPullParserException e) {
        e.printStackTrace();
        return BAD_DATA;
      }
catch (      UnfullfilledRequirementsException e) {
        e.printStackTrace();
      }
catch (      IllegalStateException e) {
        e.printStackTrace();
      }
 finally {
        cache.release();
      }
    }
  }
 catch (  ClientProtocolException e) {
    e.printStackTrace();
  }
catch (  UnknownHostException e) {
    this.publishProgress(PROGRESS_DONE);
    return UNREACHABLE_HOST;
  }
catch (  IOException e) {
    e.printStackTrace();
  }
catch (  SessionUnavailableException sue) {
    sue.printStackTrace();
  }
  this.publishProgress(PROGRESS_DONE);
  return UNKNOWN_FAILURE;
}