Program: 184970
Project: 184970
Buggy source:
/** 
 * Restore from backup -- reads in the flattened bookmark file as supplied from the backup service, parses that out, and rebuilds the bookmarks table in the browser database from it.
 */
@Override public void onRestore(BackupDataInput data,int appVersionCode,ParcelFileDescriptor newState) throws IOException {
  long crc=-1;
  File tmpfile=File.createTempFile("String_Node_Str",null,getFilesDir());
  try {
    while (data.readNextHeader()) {
      if (BOOKMARK_KEY.equals(data.getKey())) {
        crc=copyBackupToFile(data,tmpfile,data.getDataSize());
        FileInputStream infstream=new FileInputStream(tmpfile);
        DataInputStream in=new DataInputStream(infstream);
        try {
          int count=in.readInt();
          ArrayList<Bookmark> bookmarks=new ArrayList<Bookmark>(count);
          for (int i=0; i < count; i++) {
            Bookmark mark=new Bookmark();
            mark.url=in.readUTF();
            mark.visits=in.readInt();
            mark.date=in.readLong();
            mark.created=in.readLong();
            mark.title=in.readUTF();
            bookmarks.add(mark);
          }
          int N=bookmarks.size();
          int nUnique=0;
          if (DEBUG)           Log.v(TAG,"String_Node_Str" + N + "String_Node_Str");
          String[] urlCol=new String[]{BookmarkColumns.URL};
          for (int i=0; i < N; i++) {
            Bookmark mark=bookmarks.get(i);
            Cursor cursor=getContentResolver().query(Browser.BOOKMARKS_URI,urlCol,BookmarkColumns.URL + "String_Node_Str" + mark.url+ "String_Node_Str"+ BookmarkColumns.BOOKMARK+ "String_Node_Str",null,null);
            if (cursor.getCount() <= 0) {
              if (DEBUG)               Log.v(TAG,"String_Node_Str" + mark.url);
              Bookmarks.addBookmark(null,getContentResolver(),mark.url,mark.title,null,false);
              nUnique++;
            }
 else {
              if (DEBUG)               Log.v(TAG,"String_Node_Str" + mark.url);
            }
            cursor.close();
          }
          Log.i(TAG,"String_Node_Str" + nUnique + "String_Node_Str"+ N+ "String_Node_Str");
        }
 catch (        IOException ioe) {
          Log.w(TAG,"String_Node_Str");
          crc=-1;
        }
      }
      writeBackupState(tmpfile.length(),crc,newState);
    }
  }
  finally {
    tmpfile.delete();
  }
}

Fixed version (ground truth):
/** 
 * Restore from backup -- reads in the flattened bookmark file as supplied from the backup service, parses that out, and rebuilds the bookmarks table in the browser database from it.
 */
@Override public void onRestore(BackupDataInput data,int appVersionCode,ParcelFileDescriptor newState) throws IOException {
  long crc=-1;
  File tmpfile=File.createTempFile("String_Node_Str",null,getFilesDir());
  try {
    while (data.readNextHeader()) {
      if (BOOKMARK_KEY.equals(data.getKey())) {
        crc=copyBackupToFile(data,tmpfile,data.getDataSize());
        FileInputStream infstream=new FileInputStream(tmpfile);
        DataInputStream in=new DataInputStream(infstream);
        try {
          int count=in.readInt();
          ArrayList<Bookmark> bookmarks=new ArrayList<Bookmark>(count);
          for (int i=0; i < count; i++) {
            Bookmark mark=new Bookmark();
            mark.url=in.readUTF();
            mark.visits=in.readInt();
            mark.date=in.readLong();
            mark.created=in.readLong();
            mark.title=in.readUTF();
            bookmarks.add(mark);
          }
          int N=bookmarks.size();
          int nUnique=0;
          if (DEBUG)           Log.v(TAG,"String_Node_Str" + N + "String_Node_Str");
          String[] urlCol=new String[]{BookmarkColumns.URL};
          for (int i=0; i < N; i++) {
            Bookmark mark=bookmarks.get(i);
            Cursor cursor=getContentResolver().query(Browser.BOOKMARKS_URI,urlCol,BookmarkColumns.URL + "String_Node_Str" + mark.url+ "String_Node_Str"+ BookmarkColumns.BOOKMARK+ "String_Node_Str",null,null);
            if (cursor.getCount() <= 0) {
              if (DEBUG)               Log.v(TAG,"String_Node_Str" + mark.url);
              Bookmarks.addBookmark(null,getContentResolver(),mark.url,mark.title,null,false);
              nUnique++;
            }
 else {
              if (DEBUG)               Log.v(TAG,"String_Node_Str" + mark.url);
            }
            cursor.close();
          }
          Log.i(TAG,"String_Node_Str" + nUnique + "String_Node_Str"+ N+ "String_Node_Str");
        }
 catch (        IOException ioe) {
          Log.w(TAG,"String_Node_Str");
          crc=-1;
        }
 finally {
          if (in != null) {
            in.close();
          }
        }
      }
      writeBackupState(tmpfile.length(),crc,newState);
    }
  }
  finally {
    tmpfile.delete();
  }
}