7 Replies Latest reply on Sep 1, 2005 9:01 PM by Ben Wang

    A simple example of self-referencing objects problem

    renata roginsky Newbie

      I have a very simple example that illustrates the problem I described in my previous question (Posted: Fri Aug 19, 2005 21:08 PM Post subject: Problem with caching an object with a complex object graph).

      Here is the cached class:
      --------------------------------------------------------------------
      package cachetest;

      import java.util.ArrayList;
      import java.util.List;

      public class MySimpleObject {

      private String id = null;
      private List decendants = new ArrayList(); // reference to objects of the same class

      public String getId() {
      return id;
      }

      public void setId(String anID) {
      id = anID;
      }

      public MySimpleObject setCrossReferences() {
      MySimpleObject retVal = new MySimpleObject();
      retVal.setId(getId() + "_copy");
      decendants.add(retVal);
      return retVal;
      }
      }
      --------------------------------------------------------------------
      And the test:
      --------------------------------------------------------------------
      package cachetest;

      import org.jboss.cache.PropertyConfigurator;
      import org.jboss.cache.aop.TreeCacheAop;
      import org.jboss.cache.Fqn;

      public class SelfReferencingObjectsCacheTest {

      public static void main(String[] args) throws Exception {

      TreeCacheAop cache = new TreeCacheAop();
      PropertyConfigurator config = new PropertyConfigurator();
      config.configure(cache, "tree-cache.xml");
      cache.startService();

      try {
      MySimpleObject o = new MySimpleObject();
      o.setId("1");
      cache.putObject(Fqn.fromString("/MyObject/1"), o);

      MySimpleObject newObject = o.setCrossReferences();
      cache.putObject(Fqn.fromString("/MyObject/" + newObject.getId()), newObject);
      }
      catch (Exception e) {
      e.printStackTrace();
      }
      }
      }

      I aspectize MySimpleObject class using Aopc (it generates a "get" and "set" class per each property, so seems to be working properly).

      --------------------------------------------------------
      And the stack trace:
      --------------------------------------------------------
      java.lang.RuntimeException: InternalDelegate.incrementRefCount(): REF_COUNT for reference counting is null at: /__JBossInternal__/MyObject/1/decendants/0
      at org.jboss.cache.aop.InternalDelegate.incrementRefCount(InternalDelegate.java:73)
      at org.jboss.cache.aop.TreeCacheAopDelegate.addRefFqn(TreeCacheAopDelegate.java:592)
      at org.jboss.cache.aop.TreeCacheAopDelegate.getObjectGraphInternalFqn(TreeCacheAopDelegate.java:571)
      at org.jboss.cache.aop.TreeCacheAopDelegate.handleObjectGraph(TreeCacheAopDelegate.java:513)
      at org.jboss.cache.aop.TreeCacheAopDelegate._putObject(TreeCacheAopDelegate.java:171)
      at org.jboss.cache.aop.TreeCacheAop._putObject(TreeCacheAop.java:376)
      at org.jboss.cache.aop.TreeCacheAop.putObject(TreeCacheAop.java:255)
      at cachetest.SelfReferencingObjectsCacheTest.main(SelfReferencingObjectsCacheTest.java:22)
      org.jboss.util.NestedRuntimeException: TreeCacheAop.putObject(): ; - nested throwable: (java.lang.RuntimeException: InternalDelegate.incrementRefCount(): REF_COUNT for reference counting is null at: /__JBossInternal__/MyObject/1/decendants/0)
      at org.jboss.cache.aop.TreeCacheAop.putObject(TreeCacheAop.java:270)
      at cachetest.SelfReferencingObjectsCacheTest.main(SelfReferencingObjectsCacheTest.java:22)
      Caused by: java.lang.RuntimeException: InternalDelegate.incrementRefCount(): REF_COUNT for reference counting is null at: /__JBossInternal__/MyObject/1/decendants/0
      at org.jboss.cache.aop.InternalDelegate.incrementRefCount(InternalDelegate.java:73)
      at org.jboss.cache.aop.TreeCacheAopDelegate.addRefFqn(TreeCacheAopDelegate.java:592)
      at org.jboss.cache.aop.TreeCacheAopDelegate.getObjectGraphInternalFqn(TreeCacheAopDelegate.java:571)
      at org.jboss.cache.aop.TreeCacheAopDelegate.handleObjectGraph(TreeCacheAopDelegate.java:513)
      at org.jboss.cache.aop.TreeCacheAopDelegate._putObject(TreeCacheAopDelegate.java:171)
      at org.jboss.cache.aop.TreeCacheAop._putObject(TreeCacheAop.java:376)
      at org.jboss.cache.aop.TreeCacheAop.putObject(TreeCacheAop.java:255)
      ... 1 more


      If I don't aspectize the class, but declare is "Serializable", this example works, I don't get an exception.