Program: 188077
Project: 188077
Buggy source:
private Bundle insertComment(String accountName,Bundle extras){
  String body=getBodyExtra(extras);
  String parentThingId=getParentThingIdExtra(extras);
  String thingId=getThingIdExtra(extras);
  SQLiteDatabase db=helper.getWritableDatabase();
  SQLiteStatement updateNumComments=db.compileStatement(UPDATE_NUM_COMMENTS_STATEMENT);
  SQLiteStatement updateNumComments2=db.compileStatement(UPDATE_NUM_COMMENTS_STATEMENT_2);
  SQLiteStatement updateSequence=db.compileStatement(UPDATE_SEQUENCE_STATEMENT);
  db.beginTransaction();
  try {
    ContentValues values=new ContentValues(7);
    values.put(CommentActions.COLUMN_ACCOUNT,accountName);
    values.put(CommentActions.COLUMN_ACTION,CommentActions.ACTION_INSERT);
    values.put(CommentActions.COLUMN_PARENT_THING_ID,parentThingId);
    values.put(CommentActions.COLUMN_TEXT,body);
    values.put(CommentActions.COLUMN_THING_ID,thingId);
    long actionId=db.insert(CommentActions.TABLE_NAME,null,values);
    if (actionId == -1) {
      return null;
    }
    Cursor cursor=db.query(Sessions.TABLE_NAME,SESSION_ID_PROJECTION,Sessions.SELECT_BY_TYPE_AND_TAG,Array.of(Sessions.TYPE_COMMENTS,parentThingId),null,null,null);
    try {
      while (cursor.moveToNext()) {
        long sessionId=cursor.getLong(SESSION_INDEX_ID);
        long parentId=-1;
        int position=-1;
        int nesting=-1;
        int sequence=-1;
        Cursor c=db.query(Comments.TABLE_NAME,INSERT_COMMENT_PROJECTION,Comments.SELECT_BY_SESSION_ID,Array.of(sessionId),null,null,Comments.SORT_BY_SEQUENCE_AND_ID);
        try {
          while (c.moveToNext()) {
            if (c.getPosition() == 0) {
              parentId=c.getLong(INSERT_COMMENT_ID_INDEX);
            }
            String targetThingId=c.getString(INSERT_COMMENT_THING_INDEX);
            if (targetThingId.equals(parentThingId)) {
              position=c.getPosition();
              break;
            }
          }
          if (parentId == -1 || position == -1) {
            continue;
          }
          CursorCommentList cl=new CursorCommentList(c,INSERT_COMMENT_ID_INDEX,INSERT_COMMENT_NESTING_INDEX,INSERT_COMMENT_SEQUENCE_INDEX);
          nesting=CommentLogic.getInsertNesting(cl,position);
          sequence=CommentLogic.getInsertSequence(cl,position);
        }
  finally {
          c.close();
        }
        updateNumComments.bindLong(1,parentId);
        updateNumComments.executeUpdateDelete();
        updateNumComments2.bindString(1,accountName);
        updateNumComments2.bindString(2,parentThingId);
        updateSequence.bindLong(1,sessionId);
        updateSequence.bindLong(2,sequence);
        updateSequence.executeUpdateDelete();
        values.clear();
        values.put(Comments.COLUMN_ACCOUNT,accountName);
        values.put(Comments.COLUMN_AUTHOR,accountName);
        values.put(Comments.COLUMN_BODY,body);
        values.put(Comments.COLUMN_COMMENT_ACTION_ID,actionId);
        values.put(Comments.COLUMN_KIND,Kinds.KIND_COMMENT);
        values.put(Comments.COLUMN_NESTING,nesting);
        values.put(Comments.COLUMN_SEQUENCE,sequence);
        values.put(Comments.COLUMN_SESSION_ID,sessionId);
        long commentId=db.insert(Comments.TABLE_NAME,null,values);
        if (commentId == -1) {
          return null;
        }
      }
    }
  finally {
      cursor.close();
    }
    db.setTransactionSuccessful();
  }
  finally {
    db.endTransaction();
  }
  ContentResolver cr=getContext().getContentResolver();
  cr.notifyChange(COMMENT_ACTIONS_URI,null,SYNC);
  cr.notifyChange(COMMENTS_URI,null,NO_SYNC);
  cr.notifyChange(THINGS_URI,null,NO_SYNC);
  return Bundle.EMPTY;
}

Fixed version (ground truth):
private Bundle insertComment(String accountName,Bundle extras){
  String body=getBodyExtra(extras);
  String parentThingId=getParentThingIdExtra(extras);
  String thingId=getThingIdExtra(extras);
  SQLiteDatabase db=helper.getWritableDatabase();
  SQLiteStatement updateNumComments=db.compileStatement(UPDATE_NUM_COMMENTS_STATEMENT);
  SQLiteStatement updateNumComments2=db.compileStatement(UPDATE_NUM_COMMENTS_STATEMENT_2);
  SQLiteStatement updateSequence=db.compileStatement(UPDATE_SEQUENCE_STATEMENT);
  db.beginTransaction();
  try {
    ContentValues values=new ContentValues(7);
    values.put(CommentActions.COLUMN_ACCOUNT,accountName);
    values.put(CommentActions.COLUMN_ACTION,CommentActions.ACTION_INSERT);
    values.put(CommentActions.COLUMN_PARENT_THING_ID,parentThingId);
    values.put(CommentActions.COLUMN_TEXT,body);
    values.put(CommentActions.COLUMN_THING_ID,thingId);
    long actionId=db.insert(CommentActions.TABLE_NAME,null,values);
    if (actionId == -1) {
      return null;
    }
    Cursor cursor=db.query(Sessions.TABLE_NAME,SESSION_ID_PROJECTION,Sessions.SELECT_BY_TYPE_AND_TAG,Array.of(Sessions.TYPE_COMMENTS,parentThingId),null,null,null);
    try {
      while (cursor.moveToNext()) {
        long sessionId=cursor.getLong(SESSION_INDEX_ID);
        long headerDbId=-1;
        int position=-1;
        int nesting=-1;
        int sequence=-1;
        Cursor c=db.query(Comments.TABLE_NAME,INSERT_COMMENT_PROJECTION,Comments.SELECT_BY_SESSION_ID,Array.of(sessionId),null,null,Comments.SORT_BY_SEQUENCE_AND_ID);
        try {
          while (c.moveToNext()) {
            if (c.getPosition() == 0) {
              headerDbId=c.getLong(INSERT_COMMENT_INDEX_ID);
            }
            String rowThingId=c.getString(INSERT_COMMENT_INDEX_THING);
            if (thingId.equals(rowThingId)) {
              position=c.getPosition();
              break;
            }
          }
          if (headerDbId == -1 || position == -1) {
            continue;
          }
          CursorCommentList cl=new CursorCommentList(c,INSERT_COMMENT_INDEX_ID,INSERT_COMMENT_INDEX_NESTING,INSERT_COMMENT_INDEX_SEQUENCE);
          nesting=CommentLogic.getInsertNesting(cl,position);
          sequence=CommentLogic.getInsertSequence(cl,position);
        }
  finally {
          c.close();
        }
        updateNumComments.bindLong(1,headerDbId);
        updateNumComments.executeUpdateDelete();
        updateNumComments2.bindString(1,accountName);
        updateNumComments2.bindString(2,parentThingId);
        updateNumComments2.executeUpdateDelete();
        updateSequence.bindLong(1,sessionId);
        updateSequence.bindLong(2,sequence);
        updateSequence.executeUpdateDelete();
        values.clear();
        values.put(Comments.COLUMN_ACCOUNT,accountName);
        values.put(Comments.COLUMN_AUTHOR,accountName);
        values.put(Comments.COLUMN_BODY,body);
        values.put(Comments.COLUMN_COMMENT_ACTION_ID,actionId);
        values.put(Comments.COLUMN_KIND,Kinds.KIND_COMMENT);
        values.put(Comments.COLUMN_NESTING,nesting);
        values.put(Comments.COLUMN_SEQUENCE,sequence);
        values.put(Comments.COLUMN_SESSION_ID,sessionId);
        long commentId=db.insert(Comments.TABLE_NAME,null,values);
        if (commentId == -1) {
          return null;
        }
      }
    }
  finally {
      cursor.close();
    }
    db.setTransactionSuccessful();
  }
  finally {
    db.endTransaction();
  }
  ContentResolver cr=getContext().getContentResolver();
  cr.notifyChange(COMMENT_ACTIONS_URI,null,SYNC);
  cr.notifyChange(COMMENTS_URI,null,NO_SYNC);
  cr.notifyChange(THINGS_URI,null,NO_SYNC);
  return Bundle.EMPTY;
}