Program: 152444
Project: 152444
Buggy source:
protected void cleanupPhotoStore(){
  SQLiteDatabase db=mDbHelper.get().getWritableDatabase();
  Cursor c=db.query(Views.DATA,new String[]{Data._ID,Photo.PHOTO_FILE_ID},Data.MIMETYPE + "String_Node_Str" + Photo.MIMETYPE+ "String_Node_Str"+ Photo.PHOTO_FILE_ID+ "String_Node_Str",null,null,null,null);
  Set<Long> usedPhotoFileIds=Sets.newHashSet();
  Map<Long,Long> photoFileIdToDataId=Maps.newHashMap();
  try {
    while (c.moveToNext()) {
      long dataId=c.getLong(0);
      long photoFileId=c.getLong(1);
      usedPhotoFileIds.add(photoFileId);
      photoFileIdToDataId.put(photoFileId,dataId);
    }
  }
  finally {
    c.close();
  }
  c=db.query(Tables.STREAM_ITEM_PHOTOS,new String[]{StreamItemPhotos._ID,StreamItemPhotos.STREAM_ITEM_ID,StreamItemPhotos.PHOTO_FILE_ID},null,null,null,null,null);
  Map<Long,Long> photoFileIdToStreamItemPhotoId=Maps.newHashMap();
  Map<Long,Long> streamItemPhotoIdToStreamItemId=Maps.newHashMap();
  try {
    while (c.moveToNext()) {
      long streamItemPhotoId=c.getLong(0);
      long streamItemId=c.getLong(1);
      long photoFileId=c.getLong(2);
      usedPhotoFileIds.add(photoFileId);
      photoFileIdToStreamItemPhotoId.put(photoFileId,streamItemPhotoId);
      streamItemPhotoIdToStreamItemId.put(streamItemPhotoId,streamItemId);
    }
  }
  finally {
    c.close();
  }
  Set<Long> missingPhotoIds=mPhotoStore.get().cleanup(usedPhotoFileIds);
  if (!missingPhotoIds.isEmpty()) {
    ArrayList<ContentProviderOperation> ops=Lists.newArrayList();
    for (    long missingPhotoId : missingPhotoIds) {
      if (photoFileIdToDataId.containsKey(missingPhotoId)) {
        long dataId=photoFileIdToDataId.get(missingPhotoId);
        ContentValues updateValues=new ContentValues();
        updateValues.putNull(Photo.PHOTO_FILE_ID);
        ops.add(ContentProviderOperation.newUpdate(ContentUris.withAppendedId(Data.CONTENT_URI,dataId)).withValues(updateValues).build());
      }
      if (photoFileIdToStreamItemPhotoId.containsKey(missingPhotoId)) {
        long streamItemPhotoId=photoFileIdToStreamItemPhotoId.get(missingPhotoId);
        long streamItemId=streamItemPhotoIdToStreamItemId.get(streamItemPhotoId);
        ops.add(ContentProviderOperation.newDelete(StreamItems.CONTENT_URI.buildUpon().appendPath(String.valueOf(streamItemId)).appendPath(StreamItems.StreamItemPhotos.CONTENT_DIRECTORY).appendPath(String.valueOf(streamItemPhotoId)).build()).build());
      }
    }
    try {
      applyBatch(ops);
    }
 catch (    OperationApplicationException oae) {
      Log.e(TAG,"String_Node_Str",oae);
    }
  }
}

Fixed version (ground truth):
protected void cleanupPhotoStore(){
  SQLiteDatabase db=mDbHelper.get().getWritableDatabase();
  Cursor c=db.query(Views.DATA,new String[]{Data._ID,Photo.PHOTO_FILE_ID},Data.MIMETYPE + "String_Node_Str" + Photo.MIMETYPE+ "String_Node_Str"+ Photo.PHOTO_FILE_ID+ "String_Node_Str",null,null,null,null);
  Set<Long> usedPhotoFileIds=Sets.newHashSet();
  Map<Long,Long> photoFileIdToDataId=Maps.newHashMap();
  try {
    while (c.moveToNext()) {
      long dataId=c.getLong(0);
      long photoFileId=c.getLong(1);
      usedPhotoFileIds.add(photoFileId);
      photoFileIdToDataId.put(photoFileId,dataId);
    }
  }
  finally {
    c.close();
  }
  c=db.query(Tables.STREAM_ITEM_PHOTOS + "String_Node_Str" + Tables.STREAM_ITEMS+ "String_Node_Str"+ StreamItemPhotos.STREAM_ITEM_ID+ "String_Node_Str"+ StreamItemsColumns.CONCRETE_ID+ "String_Node_Str"+ Tables.RAW_CONTACTS+ "String_Node_Str"+ StreamItems.RAW_CONTACT_ID+ "String_Node_Str"+ RawContactsColumns.CONCRETE_ID,new String[]{StreamItemPhotosColumns.CONCRETE_ID,StreamItemPhotosColumns.CONCRETE_STREAM_ITEM_ID,StreamItemPhotos.PHOTO_FILE_ID,RawContacts.ACCOUNT_TYPE,RawContacts.ACCOUNT_NAME},null,null,null,null,null);
  Map<Long,Long> photoFileIdToStreamItemPhotoId=Maps.newHashMap();
  Map<Long,Long> streamItemPhotoIdToStreamItemId=Maps.newHashMap();
  Map<Long,Account> streamItemPhotoIdToAccount=Maps.newHashMap();
  try {
    while (c.moveToNext()) {
      long streamItemPhotoId=c.getLong(0);
      long streamItemId=c.getLong(1);
      long photoFileId=c.getLong(2);
      String accountType=c.getString(3);
      String accountName=c.getString(4);
      usedPhotoFileIds.add(photoFileId);
      photoFileIdToStreamItemPhotoId.put(photoFileId,streamItemPhotoId);
      streamItemPhotoIdToStreamItemId.put(streamItemPhotoId,streamItemId);
      Account account=new Account(accountName,accountType);
      streamItemPhotoIdToAccount.put(photoFileId,account);
    }
  }
  finally {
    c.close();
  }
  Set<Long> missingPhotoIds=mPhotoStore.get().cleanup(usedPhotoFileIds);
  if (!missingPhotoIds.isEmpty()) {
    ArrayList<ContentProviderOperation> ops=Lists.newArrayList();
    for (    long missingPhotoId : missingPhotoIds) {
      if (photoFileIdToDataId.containsKey(missingPhotoId)) {
        long dataId=photoFileIdToDataId.get(missingPhotoId);
        ContentValues updateValues=new ContentValues();
        updateValues.putNull(Photo.PHOTO_FILE_ID);
        ops.add(ContentProviderOperation.newUpdate(ContentUris.withAppendedId(Data.CONTENT_URI,dataId)).withValues(updateValues).build());
      }
      if (photoFileIdToStreamItemPhotoId.containsKey(missingPhotoId)) {
        long streamItemPhotoId=photoFileIdToStreamItemPhotoId.get(missingPhotoId);
        long streamItemId=streamItemPhotoIdToStreamItemId.get(streamItemPhotoId);
        Account account=streamItemPhotoIdToAccount.get(missingPhotoId);
        ops.add(ContentProviderOperation.newDelete(StreamItems.CONTENT_URI.buildUpon().appendPath(String.valueOf(streamItemId)).appendPath(StreamItems.StreamItemPhotos.CONTENT_DIRECTORY).appendPath(String.valueOf(streamItemPhotoId)).appendQueryParameter(RawContacts.ACCOUNT_NAME,account.name).appendQueryParameter(RawContacts.ACCOUNT_TYPE,account.type).build()).build());
      }
    }
    try {
      applyBatch(ops);
    }
 catch (    OperationApplicationException oae) {
      Log.e(TAG,"String_Node_Str",oae);
    }
  }
}