Program: 165356
Project: 165356
Buggy source:
protected void onHandleIntent(Intent intent){
  ResultReceiver receiver=intent.getParcelableExtra("String_Node_Str");
  long startTime=System.currentTimeMillis();
  String errmsg="String_Node_Str";
  try {
    SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    if (receiver == null) {
      long lastUpdate=prefs.getLong("String_Node_Str",System.currentTimeMillis());
      String sint=prefs.getString("String_Node_Str","String_Node_Str");
      int interval=Integer.parseInt(sint);
      if (interval == 0)       return;
      if (lastUpdate + (interval * 60 * 60) > System.currentTimeMillis())       return;
    }
    boolean notify=prefs.getBoolean("String_Node_Str",false);
    int prevUpdates=0;
    int newUpdates=0;
    Vector<DB.Repo> repos;
    try {
      DB db=DB.getDB();
      repos=db.getRepos();
    }
  finally {
      DB.releaseDB();
    }
    Vector<DB.App> apps=new Vector<DB.App>();
    Vector<String> keeprepos=new Vector<String>();
    boolean success=true;
    for (    DB.Repo repo : repos) {
      if (repo.inuse) {
        StringBuilder newetag=new StringBuilder();
        String err=RepoXMLHandler.doUpdate(getBaseContext(),repo,apps,newetag,keeprepos);
        if (err == null) {
          repo.lastetag=newetag.toString();
        }
 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 (success) {
      Vector<DB.App> acceptedapps=new Vector<DB.App>();
      Vector<DB.App> prevapps=((FDroidApp)getApplication()).getApps();
      DB db=DB.getDB();
      try {
        for (        String keep : keeprepos) {
          for (          DB.App app : prevapps) {
            boolean keepapp=false;
            for (            DB.Apk apk : app.apks) {
              if (apk.server.equals(keep)) {
                keepapp=true;
                break;
              }
            }
            if (keepapp) {
              DB.App app_k=null;
              for (              DB.App app2 : apps) {
                if (app2.id.equals(app.id)) {
                  app_k=app2;
                  break;
                }
              }
              if (app_k == null) {
                apps.add(app);
                app_k=app;
              }
              app_k.updated=true;
              if (!app_k.detail_Populated) {
                db.populateDetails(app_k,keep);
              }
              for (              DB.Apk apk : app.apks)               if (apk.server.equals(keep))               apk.updated=true;
            }
          }
        }
        prevUpdates=db.beginUpdate(prevapps);
        for (        DB.App app : apps) {
          if (db.updateApplication(app))           acceptedapps.add(app);
        }
        db.endUpdate();
        if (notify)         newUpdates=db.getNumUpdates();
        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) {
        for (        DB.App app : acceptedapps)         getIcon(app);
        ((FDroidApp)getApplication()).invalidateApps();
      }
    }
    if (success && notify) {
      Log.d("String_Node_Str","String_Node_Str" + prevUpdates + "String_Node_Str"+ newUpdates);
      if (newUpdates > prevUpdates) {
        NotificationManager n=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification=new Notification(R.drawable.icon,"String_Node_Str",System.currentTimeMillis());
        Context context=getApplicationContext();
        CharSequence contentTitle="String_Node_Str";
        CharSequence contentText="String_Node_Str";
        Intent notificationIntent=new Intent(UpdateService.this,FDroid.class);
        notificationIntent.putExtra(FDroid.EXTRA_TAB_UPDATE,true);
        PendingIntent contentIntent=PendingIntent.getActivity(UpdateService.this,0,notificationIntent,0);
        notification.setLatestEventInfo(context,contentTitle,contentText,contentIntent);
        notification.flags|=Notification.FLAG_AUTO_CANCEL;
        n.notify(1,notification);
      }
    }
    if (receiver != null) {
      Bundle resultData=new Bundle();
      if (!success) {
        if (errmsg.length() == 0)         errmsg="String_Node_Str";
        resultData.putString("String_Node_Str",errmsg);
        receiver.send(1,resultData);
      }
 else {
        receiver.send(0,resultData);
      }
    }
  }
 catch (  Exception e) {
    Log.e("String_Node_Str","String_Node_Str" + Log.getStackTraceString(e));
    if (receiver != null) {
      Bundle resultData=new Bundle();
      if (errmsg.length() == 0)       errmsg="String_Node_Str";
      resultData.putString("String_Node_Str",errmsg);
      receiver.send(1,resultData);
    }
  }
 finally {
    Log.d("String_Node_Str","String_Node_Str" + ((System.currentTimeMillis() - startTime) / 1000) + "String_Node_Str");
  }
}

Fixed version (ground truth):
protected void onHandleIntent(Intent intent){
  ResultReceiver receiver=intent.getParcelableExtra("String_Node_Str");
  long startTime=System.currentTimeMillis();
  String errmsg="String_Node_Str";
  try {
    SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    if (receiver == null) {
      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) {
        Log.d("String_Node_Str","String_Node_Str" + elapsed + "String_Node_Str"+ interval+ "String_Node_Str");
        return;
      }
    }
    boolean notify=prefs.getBoolean("String_Node_Str",false);
    int prevUpdates=0;
    int newUpdates=0;
    Vector<DB.Repo> repos;
    try {
      DB db=DB.getDB();
      repos=db.getRepos();
    }
  finally {
      DB.releaseDB();
    }
    Vector<DB.App> apps=new Vector<DB.App>();
    Vector<String> keeprepos=new Vector<String>();
    boolean success=true;
    for (    DB.Repo repo : repos) {
      if (repo.inuse) {
        StringBuilder newetag=new StringBuilder();
        String err=RepoXMLHandler.doUpdate(getBaseContext(),repo,apps,newetag,keeprepos);
        if (err == null) {
          repo.lastetag=newetag.toString();
        }
 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 (success) {
      Vector<DB.App> acceptedapps=new Vector<DB.App>();
      Vector<DB.App> prevapps=((FDroidApp)getApplication()).getApps();
      DB db=DB.getDB();
      try {
        for (        String keep : keeprepos) {
          for (          DB.App app : prevapps) {
            boolean keepapp=false;
            for (            DB.Apk apk : app.apks) {
              if (apk.server.equals(keep)) {
                keepapp=true;
                break;
              }
            }
            if (keepapp) {
              DB.App app_k=null;
              for (              DB.App app2 : apps) {
                if (app2.id.equals(app.id)) {
                  app_k=app2;
                  break;
                }
              }
              if (app_k == null) {
                apps.add(app);
                app_k=app;
              }
              app_k.updated=true;
              if (!app_k.detail_Populated) {
                db.populateDetails(app_k,keep);
              }
              for (              DB.Apk apk : app.apks)               if (apk.server.equals(keep))               apk.updated=true;
            }
          }
        }
        prevUpdates=db.beginUpdate(prevapps);
        for (        DB.App app : apps) {
          if (db.updateApplication(app))           acceptedapps.add(app);
        }
        db.endUpdate();
        if (notify)         newUpdates=db.getNumUpdates();
        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) {
        for (        DB.App app : acceptedapps)         getIcon(app);
        ((FDroidApp)getApplication()).invalidateApps();
      }
    }
    if (success && notify) {
      Log.d("String_Node_Str","String_Node_Str" + prevUpdates + "String_Node_Str"+ newUpdates);
      if (newUpdates > prevUpdates) {
        NotificationManager n=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification=new Notification(R.drawable.icon,"String_Node_Str",System.currentTimeMillis());
        Context context=getApplicationContext();
        CharSequence contentTitle="String_Node_Str";
        CharSequence contentText="String_Node_Str";
        Intent notificationIntent=new Intent(UpdateService.this,FDroid.class);
        notificationIntent.putExtra(FDroid.EXTRA_TAB_UPDATE,true);
        PendingIntent contentIntent=PendingIntent.getActivity(UpdateService.this,0,notificationIntent,0);
        notification.setLatestEventInfo(context,contentTitle,contentText,contentIntent);
        notification.flags|=Notification.FLAG_AUTO_CANCEL;
        n.notify(1,notification);
      }
    }
    if (receiver != null) {
      Bundle resultData=new Bundle();
      if (!success) {
        if (errmsg.length() == 0)         errmsg="String_Node_Str";
        resultData.putString("String_Node_Str",errmsg);
        receiver.send(1,resultData);
      }
 else {
        receiver.send(0,resultData);
      }
    }
  }
 catch (  Exception e) {
    Log.e("String_Node_Str","String_Node_Str" + Log.getStackTraceString(e));
    if (receiver != null) {
      Bundle resultData=new Bundle();
      if (errmsg.length() == 0)       errmsg="String_Node_Str";
      resultData.putString("String_Node_Str",errmsg);
      receiver.send(1,resultData);
    }
  }
 finally {
    Log.d("String_Node_Str","String_Node_Str" + ((System.currentTimeMillis() - startTime) / 1000) + "String_Node_Str");
  }
}