When GetHashCode() is called from BsonElement with circular reference - overflow exception is thrown

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Won't Fix
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: BSON
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Please consider the following code:

      var item1 = new BsonDocument();
      var item2 = new BsonDocument();
      item1.Add(new BsonElement("cycle_1", item2));
      item2.Add(new BsonElement("cycle_2", item1));

      Now, If I call item1.GetHashCode(), the application will terminate due to stack overflow exception (in my case I tried to add item1 to HashSet).
      Sure an exception should be thrown, but stackoverflow exception terminates a .NET application. I looked in the source code, and saw that BsonDocument.GetHashCode also calls GetHashCode of inner elements, which in this case cause the infinite loop.
      Is this considered a bug, or should the programmer know he should avoid such scenarios?

            Assignee:
            Unassigned
            Reporter:
            Shay
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: