Program: 60771
Project: 60771
Buggy source:
public static void mergeOldDB(Context context){
  sNewDB=false;
  OldDBHelper oldDBHelper=new OldDBHelper(context);
  SQLiteDatabase oldDB;
  try {
    oldDB=oldDBHelper.getReadableDatabase();
  }
 catch (  Exception e) {
    return;
  }
  SparseJLArray<GalleryInfo> map=new SparseJLArray<>();
  try {
    Cursor cursor=oldDB.rawQuery("String_Node_Str" + OldDBHelper.TABLE_GALLERY,null);
    if (cursor != null) {
      if (cursor.moveToFirst()) {
        while (!cursor.isAfterLast()) {
          GalleryInfo gi=new GalleryInfo();
          gi.gid=cursor.getInt(0);
          gi.token=cursor.getString(1);
          gi.title=cursor.getString(2);
          gi.posted=cursor.getString(3);
          gi.category=cursor.getInt(4);
          gi.thumb=cursor.getString(5);
          gi.uploader=cursor.getString(5);
          gi.rating=cursor.getFloat(6);
          map.put(gi.gid,gi);
          cursor.moveToNext();
        }
      }
      cursor.close();
    }
  }
 catch (  Exception e) {
  }
  try {
    Cursor cursor=oldDB.rawQuery("String_Node_Str" + OldDBHelper.TABLE_LOCAL_FAVOURITE,null);
    if (cursor != null) {
      LocalFavoritesDao dao=sDaoSession.getLocalFavoritesDao();
      if (cursor.moveToFirst()) {
        long i=0L;
        while (!cursor.isAfterLast()) {
          long gid=cursor.getInt(0);
          GalleryInfo gi=map.get(gid);
          if (gi == null) {
            Log.e(TAG,"String_Node_Str" + gid);
            cursor.moveToNext();
            continue;
          }
          LocalFavoriteInfo info=new LocalFavoriteInfo(gi);
          info.setTime(i);
          dao.insert(info);
          cursor.moveToNext();
          i++;
        }
      }
      cursor.close();
    }
  }
 catch (  Exception e) {
  }
  try {
    Cursor cursor=oldDB.rawQuery("String_Node_Str" + OldDBHelper.TABLE_TAG,null);
    if (cursor != null) {
      QuickSearchDao dao=sDaoSession.getQuickSearchDao();
      if (cursor.moveToFirst()) {
        while (!cursor.isAfterLast()) {
          QuickSearch quickSearch=new QuickSearch();
          int mode=cursor.getInt(2);
          String search=cursor.getString(4);
          String tag=cursor.getString(7);
          if (mode == ListUrlBuilder.MODE_UPLOADER && search != null && search.startsWith("String_Node_Str")) {
            search=search.substring("String_Node_Str".length());
          }
          quickSearch.setTime((long)cursor.getInt(0));
          quickSearch.setName(cursor.getString(1));
          quickSearch.setMode(mode);
          quickSearch.setCategory(cursor.getInt(3));
          quickSearch.setKeyword(mode == ListUrlBuilder.MODE_TAG ? tag : search);
          quickSearch.setAdvanceSearch(cursor.getInt(5));
          quickSearch.setMinRating(cursor.getInt(6));
          dao.insert(quickSearch);
          cursor.moveToNext();
        }
      }
      cursor.close();
    }
  }
 catch (  Exception e) {
  }
  try {
    Cursor cursor=oldDB.rawQuery("String_Node_Str" + OldDBHelper.TABLE_DOWNLOAD,null);
    if (cursor != null) {
      DownloadsDao dao=sDaoSession.getDownloadsDao();
      if (cursor.moveToFirst()) {
        long i=0L;
        while (!cursor.isAfterLast()) {
          long gid=cursor.getInt(0);
          GalleryInfo gi=map.get(gid);
          if (gi == null) {
            Log.e(TAG,"String_Node_Str" + gid);
            cursor.moveToNext();
            continue;
          }
          DownloadInfo info=new DownloadInfo(gi);
          int state=cursor.getInt(2);
          int legacy=cursor.getInt(3);
          if (state == DownloadInfo.STATE_FINISH && legacy > 0) {
            state=DownloadInfo.STATE_FAILED;
          }
          info.setState(state);
          info.setLegacy(legacy);
          if (cursor.getColumnCount() == 5) {
            info.setTime(cursor.getLong(4));
          }
 else {
            info.setTime(i);
          }
          dao.insert(info);
          cursor.moveToNext();
          i++;
        }
      }
      cursor.close();
    }
  }
 catch (  Exception e) {
  }
  try {
    Cursor cursor=oldDB.rawQuery("String_Node_Str" + OldDBHelper.TABLE_HISTORY,null);
    if (cursor != null) {
      HistoryDao dao=sDaoSession.getHistoryDao();
      if (cursor.moveToFirst()) {
        while (!cursor.isAfterLast()) {
          long gid=cursor.getInt(0);
          GalleryInfo gi=map.get(gid);
          if (gi == null) {
            Log.e(TAG,"String_Node_Str" + gid);
            cursor.moveToNext();
            continue;
          }
          HistoryInfo info=new HistoryInfo();
          info.setMode(cursor.getInt(1));
          info.setTime(cursor.getLong(2));
          dao.insert(info);
          cursor.moveToNext();
        }
      }
      cursor.close();
    }
  }
 catch (  Exception e) {
  }
  try {
    oldDBHelper.close();
  }
 catch (  Exception e) {
  }
}

Fixed version (ground truth):
public static void mergeOldDB(Context context){
  sNewDB=false;
  OldDBHelper oldDBHelper=new OldDBHelper(context);
  SQLiteDatabase oldDB;
  try {
    oldDB=oldDBHelper.getReadableDatabase();
  }
 catch (  Exception e) {
    return;
  }
  SparseJLArray<GalleryInfo> map=new SparseJLArray<>();
  try {
    Cursor cursor=oldDB.rawQuery("String_Node_Str" + OldDBHelper.TABLE_GALLERY,null);
    if (cursor != null) {
      if (cursor.moveToFirst()) {
        while (!cursor.isAfterLast()) {
          GalleryInfo gi=new GalleryInfo();
          gi.gid=cursor.getInt(0);
          gi.token=cursor.getString(1);
          gi.title=cursor.getString(2);
          gi.posted=cursor.getString(3);
          gi.category=cursor.getInt(4);
          gi.thumb=cursor.getString(5);
          gi.uploader=cursor.getString(6);
          gi.rating=cursor.getFloat(7);
          map.put(gi.gid,gi);
          cursor.moveToNext();
        }
      }
      cursor.close();
    }
  }
 catch (  Exception e) {
  }
  try {
    Cursor cursor=oldDB.rawQuery("String_Node_Str" + OldDBHelper.TABLE_LOCAL_FAVOURITE,null);
    if (cursor != null) {
      LocalFavoritesDao dao=sDaoSession.getLocalFavoritesDao();
      if (cursor.moveToFirst()) {
        long i=0L;
        while (!cursor.isAfterLast()) {
          long gid=cursor.getInt(0);
          GalleryInfo gi=map.get(gid);
          if (gi == null) {
            Log.e(TAG,"String_Node_Str" + gid);
            cursor.moveToNext();
            continue;
          }
          LocalFavoriteInfo info=new LocalFavoriteInfo(gi);
          info.setTime(i);
          dao.insert(info);
          cursor.moveToNext();
          i++;
        }
      }
      cursor.close();
    }
  }
 catch (  Exception e) {
  }
  try {
    Cursor cursor=oldDB.rawQuery("String_Node_Str" + OldDBHelper.TABLE_TAG,null);
    if (cursor != null) {
      QuickSearchDao dao=sDaoSession.getQuickSearchDao();
      if (cursor.moveToFirst()) {
        while (!cursor.isAfterLast()) {
          QuickSearch quickSearch=new QuickSearch();
          int mode=cursor.getInt(2);
          String search=cursor.getString(4);
          String tag=cursor.getString(7);
          if (mode == ListUrlBuilder.MODE_UPLOADER && search != null && search.startsWith("String_Node_Str")) {
            search=search.substring("String_Node_Str".length());
          }
          quickSearch.setTime((long)cursor.getInt(0));
          quickSearch.setName(cursor.getString(1));
          quickSearch.setMode(mode);
          quickSearch.setCategory(cursor.getInt(3));
          quickSearch.setKeyword(mode == ListUrlBuilder.MODE_TAG ? tag : search);
          quickSearch.setAdvanceSearch(cursor.getInt(5));
          quickSearch.setMinRating(cursor.getInt(6));
          dao.insert(quickSearch);
          cursor.moveToNext();
        }
      }
      cursor.close();
    }
  }
 catch (  Exception e) {
  }
  try {
    Cursor cursor=oldDB.rawQuery("String_Node_Str" + OldDBHelper.TABLE_DOWNLOAD,null);
    if (cursor != null) {
      DownloadsDao dao=sDaoSession.getDownloadsDao();
      if (cursor.moveToFirst()) {
        long i=0L;
        while (!cursor.isAfterLast()) {
          long gid=cursor.getInt(0);
          GalleryInfo gi=map.get(gid);
          if (gi == null) {
            Log.e(TAG,"String_Node_Str" + gid);
            cursor.moveToNext();
            continue;
          }
          DownloadInfo info=new DownloadInfo(gi);
          int state=cursor.getInt(2);
          int legacy=cursor.getInt(3);
          if (state == DownloadInfo.STATE_FINISH && legacy > 0) {
            state=DownloadInfo.STATE_FAILED;
          }
          info.setState(state);
          info.setLegacy(legacy);
          if (cursor.getColumnCount() == 5) {
            info.setTime(cursor.getLong(4));
          }
 else {
            info.setTime(i);
          }
          dao.insert(info);
          cursor.moveToNext();
          i++;
        }
      }
      cursor.close();
    }
  }
 catch (  Exception e) {
  }
  try {
    Cursor cursor=oldDB.rawQuery("String_Node_Str" + OldDBHelper.TABLE_HISTORY,null);
    if (cursor != null) {
      HistoryDao dao=sDaoSession.getHistoryDao();
      if (cursor.moveToFirst()) {
        while (!cursor.isAfterLast()) {
          long gid=cursor.getInt(0);
          GalleryInfo gi=map.get(gid);
          if (gi == null) {
            Log.e(TAG,"String_Node_Str" + gid);
            cursor.moveToNext();
            continue;
          }
          HistoryInfo info=new HistoryInfo();
          info.setMode(cursor.getInt(1));
          info.setTime(cursor.getLong(2));
          dao.insert(info);
          cursor.moveToNext();
        }
      }
      cursor.close();
    }
  }
 catch (  Exception e) {
  }
  try {
    oldDBHelper.close();
  }
 catch (  Exception e) {
  }
}