Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-607

Stackoverflow when querying document with cycle reference using DBRef

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.7.1
    • Component/s: API
    • Labels:
    • Environment:
      MongoDB 2.0.4, Linux Mint 13

      I first created an issue at spring-data-mongo https://jira.springsource.org/browse/DATAMONGO-488 and it appears that the issue come from the mongo Java Driver.

      Following my test code :

      Mongo mongo = new Mongo("localhost" , 27017);
      DB db = mongo.getDB("test");
      
      DBCollection sites = db.getCollection("sites");
      DBCollection users = db.getCollection("users");
      
      BasicDBObject site = new BasicDBObject();
      ObjectId siteId = new ObjectId();
      site.put("_id", site);
      site.put("name", "site");
      WriteResult result = sites.insert(site);
      
      BasicDBObject user = new BasicDBObject();
      ObjectId userId = new ObjectId();
      user.put("_id", userId);
      user.put("name", "user");
      user.put("site", new DBRef(db, site)); // throws a StackoverflowError
      

      Is this a proper use of DBRef or does cycle reference not allowed ?

      The incriminated stacktrace :

      java.lang.StackOverflowError
      	at java.util.LinkedHashMap$LinkedHashIterator.<init>(LinkedHashMap.java:362)
      	at java.util.LinkedHashMap$LinkedHashIterator.<init>(LinkedHashMap.java:362)
      	at java.util.LinkedHashMap$KeyIterator.<init>(LinkedHashMap.java:400)
      	at java.util.LinkedHashMap$KeyIterator.<init>(LinkedHashMap.java:400)
      	at java.util.LinkedHashMap.newKeyIterator(LinkedHashMap.java:413)
      	at java.util.HashMap$KeySet.iterator(HashMap.java:887)
      	at com.mongodb.DBCollection._checkKeys(DBCollection.java:1170)
      	at com.mongodb.DBCollection._checkKeys(DBCollection.java:1174)
      	at com.mongodb.DBCollection._checkKeys(DBCollection.java:1174)
      	at com.mongodb.DBCollection._checkKeys(DBCollection.java:1174)
      	at com.mongodb.DBCollection._checkKeys(DBCollection.java:1174)
      	at com.mongodb.DBCollection._checkKeys(DBCollection.java:1174)
      	at com.mongodb.DBCollection._checkKeys(DBCollection.java:1174)
              ...
      

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            ludovic.praud Ludovic PRAUD
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: