Uploaded image for project: 'Couchbase .NET client library'
  1. Couchbase .NET client library
  2. NCBC-1150

Subdocument - Lookup fails when getting hierarchical subdocument

    XMLWordPrintable

Details

    • Task
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.3.1
    • 2.3.3
    • library
    • .NET, Windows

    Description

      Summary: When getting a subdocument that isn't a simple value, the .NET library fails with InvalidOperationException.

      Repro:

      1. Create document with at least one hierarchical property
      2. Perform a subdocument lookup on that property.
      (see attached code sample)

      Expected
      Success, the subdocument to be returned.

      Actual
      InvalidOperationException, no indication of what the user did wrong.

      Notes:
      I emailed this to Jeff:

      I’ve stepped through the code just to see if I could figure out what’s going on. I might have found a bug?

      In this line of MultiLookup.cs: https://github.com/couchbase/couchbase-net-client/blob/master/Src/Couchbase/IO/Operations/SubDocument/MultiLookup.cs#L103

      It’s passing the length of the body to IsJson. So if the byte array is 50, it passes 50.

      But in IsJSON, that parameter is called “endIndex”, and is passed directly to the byte array indexer: https://github.com/couchbase/couchbase-net-client/blob/master/Src/Couchbase/Utils/ArrayExtensions.cs#L184

      This means that in some situations (like the one I’m encountering, maybe), it will try “theArray[50]” on an array that is size 50. Hence the ‘out of range’ exception. It doesn’t ALWAYS happen because that code might short circuit. It also seems like an odd/imprecise way to determine if a byte array is JSON or not. I would assume you’d encode it to a string and use JSON.net to determine. But maybe it’s an optimization?

      Just for fun, I changed “endIndex” to “endIndex-1” inside of IsJSON, and now it works.

      I don’t know if that’s the right fix, but I think it must be a bug.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          There are no commits yet on this issue.

          People

            jmorris Jeff Morris
            matthew.groves Matthew Groves
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty