Program: 165330
Project: 165330
Buggy source:
protected void onHandleIntent(Intent intent){
  receiver=intent.getParcelableExtra("String_Node_Str");
  long startTime=System.currentTimeMillis();
  String errmsg="String_Node_Str";
  try {
    SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    if (isScheduledRun()) {
      long lastUpdate=prefs.getLong("String_Node_Str",0);
      String sint=prefs.getString("String_Node_Str","String_Node_Str");
      int interval=Integer.parseInt(sint);
      if (interval == 0) {
        Log.d("String_Node_Str","String_Node_Str");
        return;
      }
      long elapsed=System.currentTimeMillis() - lastUpdate;
      if (elapsed < interval * 60 * 60* 1000) {
        Log.d("String_Node_Str","String_Node_Str" + elapsed + "String_Node_Str"+ interval+ "String_Node_Str");
        return;
      }
    }
 else {
      Log.d("String_Node_Str","String_Node_Str");
    }
    boolean notify=prefs.getBoolean("String_Node_Str",false);
    int updates=0;
    List<DB.Repo> repos;
    try {
      DB db=DB.getDB();
      repos=db.getRepos();
    }
  finally {
      DB.releaseDB();
    }
    List<DB.App> updatingApps=new ArrayList<DB.App>();
    List<Integer> keeprepos=new ArrayList<Integer>();
    boolean success=true;
    boolean changes=false;
    for (    DB.Repo repo : repos) {
      if (repo.inuse) {
        sendStatus(STATUS_INFO,getString(R.string.status_connecting_to_repo,repo.address));
        StringBuilder newetag=new StringBuilder();
        String err=RepoXMLHandler.doUpdate(getBaseContext(),repo,updatingApps,newetag,keeprepos,this);
        if (err == null) {
          String nt=newetag.toString();
          if (!nt.equals(repo.lastetag)) {
            repo.lastetag=newetag.toString();
            changes=true;
          }
        }
 else {
          success=false;
          err="String_Node_Str" + repo.address + "String_Node_Str"+ err;
          Log.d("String_Node_Str",err);
          if (errmsg.length() == 0)           errmsg=err;
 else           errmsg+="String_Node_Str" + err;
        }
      }
    }
    if (!changes && success) {
      Log.d("String_Node_Str","String_Node_Str");
    }
 else     if (changes && success) {
      sendStatus(STATUS_INFO,getString(R.string.status_checking_compatibility));
      List<DB.App> apps=((FDroidApp)getApplication()).getApps();
      DB db=DB.getDB();
      try {
        for (        int keep : keeprepos) {
          for (          DB.App app : apps) {
            boolean keepapp=false;
            for (            DB.Apk apk : app.apks) {
              if (apk.repo == keep) {
                keepapp=true;
                break;
              }
            }
            if (keepapp) {
              DB.App app_k=null;
              for (              DB.App app2 : updatingApps) {
                if (app2.id.equals(app.id)) {
                  app_k=app2;
                  break;
                }
              }
              if (app_k == null) {
                updatingApps.add(app);
                app_k=app;
              }
              app_k.updated=true;
              db.populateDetails(app_k,keep);
              for (              DB.Apk apk : app.apks)               if (apk.repo == keep)               apk.updated=true;
            }
          }
        }
        db.beginUpdate(apps);
        for (        DB.App app : updatingApps) {
          db.updateApplication(app);
        }
        db.endUpdate();
        if (notify) {
          apps=((FDroidApp)getApplication()).getApps();
          updates=db.getNumUpdates(apps);
        }
        for (        DB.Repo repo : repos)         db.writeLastEtag(repo);
      }
 catch (      Exception ex) {
        db.cancelUpdate();
        Log.e("String_Node_Str","String_Node_Str" + Log.getStackTraceString(ex));
        errmsg="String_Node_Str" + ex.getMessage();
        success=false;
      }
 finally {
        DB.releaseDB();
      }
    }
    if (success && changes)     ((FDroidApp)getApplication()).invalidateAllApps();
    if (success && changes && notify&& updates > 0) {
      Log.d("String_Node_Str","String_Node_Str" + updates + "String_Node_Str");
      NotificationCompat.Builder mBuilder=new NotificationCompat.Builder(this).setSmallIcon(R.drawable.icon).setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.icon)).setAutoCancel(true).setContentTitle(getString(R.string.fdroid_updates_available));
      Intent notifyIntent=new Intent(this,FDroid.class).putExtra(FDroid.EXTRA_TAB_UPDATE,true);
      if (updates > 1) {
        mBuilder.setContentText(getString(R.string.many_updates_available,updates));
      }
 else {
        mBuilder.setContentText(getString(R.string.one_update_available));
      }
      TaskStackBuilder stackBuilder=TaskStackBuilder.create(this).addParentStack(FDroid.class).addNextIntent(notifyIntent);
      PendingIntent pendingIntent=stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
      mBuilder.setContentIntent(pendingIntent);
      NotificationManager mNotificationManager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
      mNotificationManager.notify(1,mBuilder.build());
    }
    if (!success) {
      if (errmsg.length() == 0)       errmsg="String_Node_Str";
      sendStatus(STATUS_ERROR,errmsg);
    }
 else {
      sendStatus(STATUS_COMPLETE);
      Editor e=prefs.edit();
      e.putLong("String_Node_Str",System.currentTimeMillis());
      e.commit();
    }
  }
 catch (  Exception e) {
    Log.e("String_Node_Str","String_Node_Str" + Log.getStackTraceString(e));
    if (errmsg.length() == 0)     errmsg="String_Node_Str";
    sendStatus(STATUS_ERROR,errmsg);
  }
 finally {
    Log.d("String_Node_Str","String_Node_Str" + ((System.currentTimeMillis() - startTime) / 1000) + "String_Node_Str");
    receiver=null;
  }
}

Fixed version (ground truth):
protected void onHandleIntent(Intent intent){
  receiver=intent.getParcelableExtra("String_Node_Str");
  long startTime=System.currentTimeMillis();
  String errmsg="String_Node_Str";
  try {
    SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    if (isScheduledRun()) {
      long lastUpdate=prefs.getLong("String_Node_Str",0);
      String sint=prefs.getString("String_Node_Str","String_Node_Str");
      int interval=Integer.parseInt(sint);
      if (interval == 0) {
        Log.d("String_Node_Str","String_Node_Str");
        return;
      }
      long elapsed=System.currentTimeMillis() - lastUpdate;
      if (elapsed < interval * 60 * 60* 1000) {
        Log.d("String_Node_Str","String_Node_Str" + elapsed + "String_Node_Str"+ interval+ "String_Node_Str");
        return;
      }
    }
 else {
      Log.d("String_Node_Str","String_Node_Str");
    }
    boolean notify=prefs.getBoolean("String_Node_Str",false);
    int updates=0;
    List<DB.Repo> repos;
    try {
      DB db=DB.getDB();
      repos=db.getRepos();
    }
  finally {
      DB.releaseDB();
    }
    List<DB.App> apps;
    List<DB.App> updatingApps=new ArrayList<DB.App>();
    List<Integer> keeprepos=new ArrayList<Integer>();
    boolean success=true;
    boolean changes=false;
    for (    DB.Repo repo : repos) {
      if (repo.inuse) {
        sendStatus(STATUS_INFO,getString(R.string.status_connecting_to_repo,repo.address));
        StringBuilder newetag=new StringBuilder();
        String err=RepoXMLHandler.doUpdate(getBaseContext(),repo,updatingApps,newetag,keeprepos,this);
        if (err == null) {
          String nt=newetag.toString();
          if (!nt.equals(repo.lastetag)) {
            repo.lastetag=newetag.toString();
            changes=true;
          }
        }
 else {
          success=false;
          err="String_Node_Str" + repo.address + "String_Node_Str"+ err;
          Log.d("String_Node_Str",err);
          if (errmsg.length() == 0)           errmsg=err;
 else           errmsg+="String_Node_Str" + err;
        }
      }
    }
    if (!changes && success) {
      Log.d("String_Node_Str","String_Node_Str");
    }
 else     if (changes && success) {
      sendStatus(STATUS_INFO,getString(R.string.status_checking_compatibility));
      apps=((FDroidApp)getApplication()).getApps();
      DB db=DB.getDB();
      try {
        for (        int keep : keeprepos) {
          for (          DB.App app : apps) {
            boolean keepapp=false;
            for (            DB.Apk apk : app.apks) {
              if (apk.repo == keep) {
                keepapp=true;
                break;
              }
            }
            if (keepapp) {
              DB.App app_k=null;
              for (              DB.App app2 : updatingApps) {
                if (app2.id.equals(app.id)) {
                  app_k=app2;
                  break;
                }
              }
              if (app_k == null) {
                updatingApps.add(app);
                app_k=app;
              }
              app_k.updated=true;
              db.populateDetails(app_k,keep);
              for (              DB.Apk apk : app.apks)               if (apk.repo == keep)               apk.updated=true;
            }
          }
        }
        db.beginUpdate(apps);
        for (        DB.App app : updatingApps) {
          db.updateApplication(app);
        }
        db.endUpdate();
        for (        DB.Repo repo : repos)         db.writeLastEtag(repo);
      }
 catch (      Exception ex) {
        db.cancelUpdate();
        Log.e("String_Node_Str","String_Node_Str" + Log.getStackTraceString(ex));
        errmsg="String_Node_Str" + ex.getMessage();
        success=false;
      }
 finally {
        DB.releaseDB();
      }
    }
    if (success && changes) {
      ((FDroidApp)getApplication()).invalidateAllApps();
      if (notify) {
        apps=((FDroidApp)getApplication()).getApps();
        updates=getNumUpdates(apps);
      }
    }
    if (success && changes && notify&& updates > 0) {
      Log.d("String_Node_Str","String_Node_Str" + updates + "String_Node_Str");
      NotificationCompat.Builder mBuilder=new NotificationCompat.Builder(this).setSmallIcon(R.drawable.icon).setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.icon)).setAutoCancel(true).setContentTitle(getString(R.string.fdroid_updates_available));
      Intent notifyIntent=new Intent(this,FDroid.class).putExtra(FDroid.EXTRA_TAB_UPDATE,true);
      if (updates > 1) {
        mBuilder.setContentText(getString(R.string.many_updates_available,updates));
      }
 else {
        mBuilder.setContentText(getString(R.string.one_update_available));
      }
      TaskStackBuilder stackBuilder=TaskStackBuilder.create(this).addParentStack(FDroid.class).addNextIntent(notifyIntent);
      PendingIntent pendingIntent=stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
      mBuilder.setContentIntent(pendingIntent);
      NotificationManager mNotificationManager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
      mNotificationManager.notify(1,mBuilder.build());
    }
    if (!success) {
      if (errmsg.length() == 0)       errmsg="String_Node_Str";
      sendStatus(STATUS_ERROR,errmsg);
    }
 else {
      sendStatus(STATUS_COMPLETE);
      Editor e=prefs.edit();
      e.putLong("String_Node_Str",System.currentTimeMillis());
      e.commit();
    }
  }
 catch (  Exception e) {
    Log.e("String_Node_Str","String_Node_Str" + Log.getStackTraceString(e));
    if (errmsg.length() == 0)     errmsg="String_Node_Str";
    sendStatus(STATUS_ERROR,errmsg);
  }
 finally {
    Log.d("String_Node_Str","String_Node_Str" + ((System.currentTimeMillis() - startTime) / 1000) + "String_Node_Str");
    receiver=null;
  }
}