Program: 198614
Project: 198614
Buggy source:
private void onUpdateEntry(Uri uri,long channelId,long time,SessionState sessionState){
  String[] projection={TvContract.WatchedPrograms.COLUMN_WATCH_START_TIME_UTC_MILLIS,TvContract.WatchedPrograms.COLUMN_WATCH_END_TIME_UTC_MILLIS,TvContract.WatchedPrograms.COLUMN_TITLE,TvContract.WatchedPrograms.COLUMN_START_TIME_UTC_MILLIS,TvContract.WatchedPrograms.COLUMN_END_TIME_UTC_MILLIS,TvContract.WatchedPrograms.COLUMN_DESCRIPTION};
  Cursor cursor=null;
  try {
    cursor=mContentResolver.query(uri,projection,null,null,null);
    if (cursor != null && cursor.moveToNext()) {
      long watchStartTime=cursor.getLong(0);
      long watchEndTime=cursor.getLong(1);
      String title=cursor.getString(2);
      long startTime=cursor.getLong(3);
      long endTime=cursor.getLong(4);
      String description=cursor.getString(5);
      if (watchEndTime > 0) {
        return;
      }
      ContentValues values=new ContentValues();
      values.put(TvContract.WatchedPrograms.COLUMN_WATCH_START_TIME_UTC_MILLIS,watchStartTime);
      values.put(TvContract.WatchedPrograms.COLUMN_WATCH_END_TIME_UTC_MILLIS,time);
      values.put(TvContract.WatchedPrograms.COLUMN_CHANNEL_ID,channelId);
      values.put(TvContract.WatchedPrograms.COLUMN_TITLE,title);
      values.put(TvContract.WatchedPrograms.COLUMN_START_TIME_UTC_MILLIS,startTime);
      values.put(TvContract.WatchedPrograms.COLUMN_END_TIME_UTC_MILLIS,endTime);
      values.put(TvContract.WatchedPrograms.COLUMN_DESCRIPTION,description);
      mContentResolver.insert(TvContract.WatchedPrograms.CONTENT_URI,values);
    }
  }
  finally {
    if (cursor != null) {
      cursor.close();
    }
  }
  onOpenEntry(uri,channelId,time,sessionState);
}

Fixed version (ground truth):
private void onUpdateEntry(Uri uri,long channelId,long time,SessionState sessionState){
  String[] projection={TvContract.WatchedPrograms.COLUMN_WATCH_END_TIME_UTC_MILLIS};
  Cursor cursor=null;
  try {
    cursor=mContentResolver.query(uri,projection,null,null,null);
    if (cursor != null && cursor.moveToNext()) {
      long watchEndTime=cursor.getLong(0);
      if (watchEndTime > 0) {
        return;
      }
      ContentValues values=new ContentValues();
      values.put(TvContract.WatchedPrograms.COLUMN_WATCH_END_TIME_UTC_MILLIS,time);
      int c=mContentResolver.update(uri,values,null,null);
    }
 else {
synchronized (mLock) {
        if (!uri.equals(sessionState.mLogUri)) {
          return;
        }
      }
    }
    if (cursor != null) {
      cursor.close();
      cursor=null;
    }
    uri=ContentUris.withAppendedId(TvContract.Channels.CONTENT_URI,channelId);
    projection=new String[]{TvContract.Channels.COLUMN_PACKAGE_NAME};
    cursor=mContentResolver.query(uri,projection,null,null,null);
    if (cursor != null && cursor.moveToNext()) {
      ContentValues values=new ContentValues();
      values.put(TvContract.WatchedPrograms.COLUMN_PACKAGE_NAME,cursor.getString(0));
      values.put(TvContract.WatchedPrograms.COLUMN_WATCH_START_TIME_UTC_MILLIS,time);
      values.put(TvContract.WatchedPrograms.COLUMN_WATCH_END_TIME_UTC_MILLIS,0);
      values.put(TvContract.WatchedPrograms.COLUMN_CHANNEL_ID,channelId);
      Uri newUri=mContentResolver.insert(TvContract.WatchedPrograms.CONTENT_URI,values);
synchronized (mLock) {
        sessionState.mLogUri=newUri;
      }
      onOpenEntry(newUri,channelId,time,sessionState);
    }
  }
  finally {
    if (cursor != null) {
      cursor.close();
    }
  }
}