Program: 8302
Project: 8302
Buggy source:
/** 
 * This method tries to import data from a provided database. The sole assumptions made on this db are that there is a key_rings table with a key_ring_data, a master_key_id and a type column, the latter of which should be 1 for secret keys and 0 for public keys.
 */
public void checkAndImportApg(Context context){
  boolean hasApgDb=false;
{
    String[] dbs=context.databaseList();
    for (    String db : dbs) {
      if (db.equals("String_Node_Str")) {
        hasApgDb=true;
      }
 else       if (db.equals("String_Node_Str")) {
        Log.d(Constants.TAG,"String_Node_Str");
        context.getDatabasePath("String_Node_Str").delete();
      }
    }
  }
  if (!hasApgDb) {
    return;
  }
  Log.d(Constants.TAG,"String_Node_Str");
  SQLiteDatabase db=new SQLiteOpenHelper(context,"String_Node_Str",null,1){
    @Override public void onCreate(    SQLiteDatabase db){
      throw new AssertionError();
    }
    @Override public void onDowngrade(    SQLiteDatabase db,    int old,    int nu){
    }
    @Override public void onUpgrade(    SQLiteDatabase db,    int old,    int nu){
    }
  }
.getReadableDatabase();
  Cursor cursor=null;
  ProviderHelper providerHelper=new ProviderHelper(context);
  try {
    cursor=db.rawQuery("String_Node_Str" + "String_Node_Str" + "String_Node_Str",null);
    if (cursor != null) {
      Log.d(Constants.TAG,"String_Node_Str" + cursor.getCount() + "String_Node_Str");
      for (int i=0; i < cursor.getCount(); i++) {
        cursor.moveToPosition(i);
        byte[] data=cursor.getBlob(0);
        try {
          UncachedKeyRing ring=UncachedKeyRing.decodeFromData(data);
          providerHelper.savePublicKeyRing(ring);
        }
 catch (        PgpGeneralException e) {
          Log.e(Constants.TAG,"String_Node_Str");
        }
      }
    }
    if (cursor != null) {
      cursor.close();
    }
    cursor=db.rawQuery("String_Node_Str" + "String_Node_Str" + "String_Node_Str",null);
    if (cursor != null) {
      Log.d(Constants.TAG,"String_Node_Str" + cursor.getCount() + "String_Node_Str");
      for (int i=0; i < cursor.getCount(); i++) {
        cursor.moveToPosition(i);
        byte[] data=cursor.getBlob(0);
        try {
          UncachedKeyRing ring=UncachedKeyRing.decodeFromData(data);
          providerHelper.savePublicKeyRing(ring);
        }
 catch (        PgpGeneralException e) {
          Log.e(Constants.TAG,"String_Node_Str");
        }
      }
    }
  }
 catch (  IOException e) {
    Log.e(Constants.TAG,"String_Node_Str",e);
  }
 finally {
    if (cursor != null) {
      cursor.close();
    }
    if (db != null) {
      db.close();
    }
  }
  context.getDatabasePath("String_Node_Str").delete();
}

Fixed version (ground truth):
/** 
 * This method tries to import data from a provided database. The sole assumptions made on this db are that there is a key_rings table with a key_ring_data, a master_key_id and a type column, the latter of which should be 1 for secret keys and 0 for public keys.
 */
public void checkAndImportApg(Context context){
  boolean hasApgDb=false;
{
    String[] dbs=context.databaseList();
    for (    String db : dbs) {
      if ("String_Node_Str".equals(db)) {
        hasApgDb=true;
      }
 else       if ("String_Node_Str".equals(db)) {
        Log.d(Constants.TAG,"String_Node_Str");
        context.getDatabasePath("String_Node_Str").delete();
      }
    }
  }
  if (!hasApgDb) {
    return;
  }
  Log.d(Constants.TAG,"String_Node_Str");
  SQLiteDatabase db=new SQLiteOpenHelper(context,"String_Node_Str",null,1){
    @Override public void onCreate(    SQLiteDatabase db){
      throw new AssertionError();
    }
    @Override public void onDowngrade(    SQLiteDatabase db,    int old,    int nu){
    }
    @Override public void onUpgrade(    SQLiteDatabase db,    int old,    int nu){
    }
  }
.getReadableDatabase();
  Cursor cursor=null;
  ProviderHelper providerHelper=new ProviderHelper(context);
  try {
    cursor=db.rawQuery("String_Node_Str" + "String_Node_Str" + "String_Node_Str",null);
    if (cursor != null) {
      Log.d(Constants.TAG,"String_Node_Str" + cursor.getCount() + "String_Node_Str");
      for (int i=0; i < cursor.getCount(); i++) {
        cursor.moveToPosition(i);
        byte[] data=cursor.getBlob(0);
        try {
          UncachedKeyRing ring=UncachedKeyRing.decodeFromData(data);
          providerHelper.savePublicKeyRing(ring);
        }
 catch (        PgpGeneralException e) {
          Log.e(Constants.TAG,"String_Node_Str");
        }
      }
    }
    if (cursor != null) {
      cursor.close();
    }
    cursor=db.rawQuery("String_Node_Str" + "String_Node_Str" + "String_Node_Str",null);
    if (cursor != null) {
      Log.d(Constants.TAG,"String_Node_Str" + cursor.getCount() + "String_Node_Str");
      for (int i=0; i < cursor.getCount(); i++) {
        cursor.moveToPosition(i);
        byte[] data=cursor.getBlob(0);
        try {
          UncachedKeyRing ring=UncachedKeyRing.decodeFromData(data);
          providerHelper.savePublicKeyRing(ring);
        }
 catch (        PgpGeneralException e) {
          Log.e(Constants.TAG,"String_Node_Str");
        }
      }
    }
  }
 catch (  IOException e) {
    Log.e(Constants.TAG,"String_Node_Str",e);
  }
 finally {
    if (cursor != null) {
      cursor.close();
    }
    if (db != null) {
      db.close();
    }
  }
  context.getDatabasePath("String_Node_Str").delete();
}