1 2 Previous Next 20 Replies Latest reply: Feb 25, 2006 1:37 PM by Scott Marlow RSS

random removing from Map (AOP-Cache)

Daniel Zwicker Newbie

Hi all,

when I delete a random Object from a Map that is inside of an POJO I get the following exection.

Exception in thread "main" java.lang.reflect.InvocationTargetException
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:585)
 at org.jboss.cache.aop.collection.CollectionInterceptorUtil.invoke(CollectionInterceptorUtil.java:122)
 at org.jboss.cache.aop.collection.CachedListInterceptor.invoke(CachedListInterceptor.java:125)
 at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
 at AOPClassProxy$0.remove(AOPClassProxy$0.java)
 at de.lgf.labconn.anf.model.persistance.DayNode.removePatientfromArray(DayNode.java:74)
 at de.lgf.labconn.anf.model.persistance.DayNode.removePatient(DayNode.java:82)
 at de.lgf.labconn.anf.tree.node.anforderungen.WarteListenPatient.dispose(WarteListenPatient.java:39)
 at de.lgf.labconn.anf.tree.node.anforderungen.AbstractAnforderungsTeeNode.remove(AbstractAnforderungsTeeNode.java:108)
 at de.lgf.labconn.anf.plugin.standart.action.DeletePatAction.handleEvent(DeletePatAction.java:21)
 at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
 at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:843)
 at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3125)
 at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2758)
 at de.lgf.labconn.anf.Main.main(Main.java:47)
Caused by: org.jboss.util.NestedRuntimeException: InternalDelegate.resetRefCount(). Ref counter not -1 but 0 at fqn: /warteliste/children/0; - nested throwable: (java.lang.IllegalStateException: InternalDelegate.resetRefCount(). Ref counter not -1 but 0 at fqn: /warteliste/children/0)
 at org.jboss.cache.aop.collection.CachedListImpl.remove(CachedListImpl.java:155)
 at org.jboss.cache.aop.collection.CachedListAbstract.remove(CachedListAbstract.java:74)
 ... 18 more
Caused by: java.lang.IllegalStateException: InternalDelegate.resetRefCount(). Ref counter not -1 but 0 at fqn: /warteliste/children/0
 at org.jboss.cache.aop.InternalDelegate.resetRefCount(InternalDelegate.java:59)
 at org.jboss.cache.aop.CollectionClassHandler.collectionObjectPut(CollectionClassHandler.java:68)
 at org.jboss.cache.aop.TreeCacheAopDelegate._putObject(TreeCacheAopDelegate.java:184)
 at org.jboss.cache.aop.TreeCacheAop._putObject(TreeCacheAop.java:503)
 at org.jboss.cache.aop.TreeCacheAop.putObject(TreeCacheAop.java:345)
 at org.jboss.cache.aop.collection.CachedListImpl.remove(CachedListImpl.java:151)
 ... 19 more



I don't know what I'm doing wrong? Objects inside the Map are just Strings and when I'm removing the last Object added everything works fine. It only appers when you try to delete a random Object except for the last one added.

  • 1. Re: random removing from Map (AOP-Cache)
    Scott Marlow Master

    Are you using a Map or a List? The stack trace indicates a list (CachedListImpl). I cannot imagine that this has anything to do with the problem but thought I would mention it.

    Give me a testcase that shows the problem. I'm looking for something that could easily fit into the unit test suite. Perhaps something like this from org.jboss.cache.aop.collection.CachedListAopTest:

    public void testAddAndRemoveIndex() throws Throwable
    {
    stage();

    languages.add(1, "Taiwanese");
    assertEquals("Languages size ", 4, languages.size());
    assertEquals("Language ", (Object)"Taiwanese", (Object)languages.get(1));
    languages.remove(2);
    assertEquals("Languages size ", 3, languages.size());
    assertEquals("Language ", (Object)"English", (Object)languages.get(2));

    languages.add("Mandarin");
    assertEquals("Languages size ", 4, languages.size());
    languages.remove("Mandarin");
    assertEquals("Languages size ", 3, languages.size());
    }

    protected void stage() throws Throwable
    {
    languages = new ArrayList();
    languages.add("English");
    languages.add("French");
    languages.add("English");
    cache_.putObject("/person/test6", languages);
    languages = (List)cache_.getObject("/person/test6");
    int size = languages.size();
    assertEquals("Size of list ", 3, size);
    }

  • 2. Re: random removing from Map (AOP-Cache)
    Scott Marlow Master

    Another example from the same class:

    public void testPojoAttachAndDetach() throws Exception
    {
    Address add1 = new Address();
    add1.setCity("San Jose");
    add1.setZip(95123);

    Address add2 = new Address();
    add1.setCity("Sunnyvale");
    add1.setZip(94086);

    Address add3 = new Address();
    add1.setCity("Santa Clara");
    add1.setZip(951131);

    List list = new ArrayList();
    list.add(add1);
    list.add(add2);
    list.add(add3);

    cache_.putObject("/test", list); // attach
    list = (List)cache_.getObject("/test");
    assertEquals("Size ", 3, list.size());

    list = (List)cache_.removeObject("/test");
    assertEquals("Size ", 3, list.size());

    System.out.println(cache_.printDetails());
    System.out.println("**** End of cache content **** ");
    list.remove(2);
    list.add(add2);
    assertEquals("Size ", 3, list.size());
    assertEquals("Content ", add2, list.get(2));

    // Try to re-attach
    cache_.putObject("/test", list);
    list.remove(2);
    assertEquals("Size ", 2, list.size());
    System.out.println(cache_.printDetails());
    }

  • 3. Re: random removing from Map (AOP-Cache)
    Daniel Zwicker Newbie

    Ok, you're right . It's a Collection, my mistake.
    I'll try to find a simple testcase

  • 4. Re: random removing from Map (AOP-Cache)
    Scott Marlow Master

    Can you also let me know which version of JBoss Cache you are using?

  • 5. Re: random removing from Map (AOP-Cache)
    Daniel Zwicker Newbie

    In a simple example no exception is been thrown. But I've noticed that I've user an ENUM in my Class! I have changed to String and it seams to work.

  • 6. Re: random removing from Map (AOP-Cache)
    Daniel Zwicker Newbie

    But thank you for your quick response.

  • 7. Re: random removing from Map (AOP-Cache)
    Daniel Zwicker Newbie

    I'm sorry but the problem occure again. This time I'm able to give you a testcase. The exception has something to do witch the transactions inside the Cachloader's. So here's the testcase.

    First the Pojo:

    public class TestObject {
     private Collection<String> list;
    
     public TestObject(){
     }
    
     public void init(){
     this.list=new Vector<String>();
     }
    
     public void add(String value){
     this.list.add(value);
     }
    
     public void remove(String value){
     this.list.remove(value);
     }
    }


    It's quite simple. Know the test:

    public class Test {
    
     private TreeCacheAop treeCache;
    
     public Test() throws Exception {
     this.treeCache = new TreeCacheAop();
     PropertyConfigurator config = new PropertyConfigurator();
     InputStream input = new FileInputStream("replSync-service-persistent.xml");
     config.configure(this.treeCache, input);
     input.close();
     this.treeCache.start();
     }
    
     private void addObject(String key, TestObject pojo) throws CacheException {
     this.treeCache.putObject(key, pojo);
     }
    
     private void removeObject(String key) throws CacheException {
     this.treeCache.removeObject(key);
     }
    
     public static void main(String[] args) throws Exception {
     UserTransaction tx = new DummyUserTransaction(DummyTransactionManager
     .getInstance());
     Test server = new Test();
     TestObject pojo = new TestObject();
     pojo.init();
     tx.begin();
     server.addObject("/pojo", pojo);
     tx.commit();
     String id1 = "/test1";
     String id2 = "/test2";
     String id3 = "/test3";
     tx.begin();
     pojo.add(id1);
     tx.commit();
     tx.begin();
     pojo.add(id2);
     tx.commit();
     tx.begin();
     pojo.add(id3);
     tx.commit();
     tx.begin();
     pojo.remove(id2);
     tx.commit();
     tx.begin();
     server.removeObject("/pojo");
     tx.commit();
     System.out.println("ALL DONE");
     }
    }


    And the configurationfiles.
    jboss-aop.xml:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <aop>
     <prepare
     expr="field(* TestObject->*)" />
    </aop>


    the cach-config:
    <?xml version="1.0" encoding="UTF-8"?>
    <server>
     <classpath codebase="../lib" archives="jboss-cache.jar, jgroups.jar" />
     <mbean code="org.jboss.cache.aop.TreeCacheAop" name="jboss.cache:service=LabconnTreeCacheAop">
     <depends>jboss:service=Naming</depends>
     <depends>jboss:service=TransactionManager</depends>
     <attribute name="TransactionManagerLookupClass">org.jboss.cache.DummyTransactionManagerLookup</attribute>
     <attribute name="IsolationLevel">READ_COMMITTED</attribute>
     <attribute name="CacheMode">REPL_SYNC</attribute>
     <attribute name="UseReplQueue">false</attribute>
     <attribute name="ReplQueueInterval">0</attribute>
     <attribute name="ReplQueueMaxElements">0</attribute>
     <attribute name="ClusterName">LabconnCache</attribute>
     <attribute name="DeadlockDetection">true</attribute>
     <attribute name="ClusterConfig">
     <config>
     <UDP mcast_addr="228.1.2.3" mcast_port="48866" ip_ttl="64" ip_mcast="true" mcast_send_buf_size="150000" mcast_recv_buf_size="80000" ucast_send_buf_size="150000" ucast_recv_buf_size="80000" loopback="true" discard_incompatibe_packets="true"/>
     <PING timeout="2000" num_initial_members="3" up_thread="false" down_thread="false" />
     <MERGE2 min_interval="10000" max_interval="20000" />
     <!--<FD shun="true" up_thread="true" down_thread="true" />-->
     <FD_SOCK />
     <VERIFY_SUSPECT timeout="1500" up_thread="false" down_thread="false" />
     <pbcast.NAKACK gc_lag="50" retransmit_timeout="600,1200,2400,4800" max_xmit_size="8192" up_thread="false" down_thread="false" />
     <UNICAST timeout="600,1200,2400" window_size="100" min_threshold="10" down_thread="false" />
     <pbcast.STABLE desired_avg_gossip="20000" up_thread="false" down_thread="false" />
     <FRAG frag_size="8192" down_thread="false" up_thread="false" />
     <pbcast.GMS join_timeout="5000" join_retry_timeout="2000" shun="true" print_local_addr="true" />
     <pbcast.STATE_TRANSFER up_thread="true" down_thread="true" />
     </config>
     </attribute>
     <attribute name="FetchStateOnStartup">true</attribute>
     <attribute name="InitialStateRetrievalTimeout">60000</attribute>
     <attribute name="SyncReplTimeout">30000</attribute>
     <attribute name="LockAcquisitionTimeout">20000</attribute>
     <attribute name="UseMarshalling">false</attribute>
     <!-- <attribute name="InactiveOnStartup">true</attribute> -->
     <attribute name="CacheLoaderClass">org.jboss.cache.loader.bdbje.BdbjeCacheLoader</attribute>
     <attribute name="CacheLoaderConfig" replace="false">location=../bdbje</attribute>
     <attribute name="CacheLoaderPreload">/</attribute>
     <attribute name="CacheLoaderShared">false</attribute>
     <attribute name="CacheLoaderPassivation">false</attribute>
     <attribute name="CacheLoaderAsynchronous">false</attribute>
     <attribute name="CacheLoaderFetchTransientState">true</attribute>
     <attribute name="CacheLoaderFetchPersistentState">true</attribute>
     </mbean>
    </server>


    The resulting stacktrace:
    Exception in thread "main" java.lang.IllegalStateException: InternalDelegate.resetRefCount(). Ref counter not -1 but 0 at fqn: /pojo
     at org.jboss.cache.aop.InternalDelegate.resetRefCount(InternalDelegate.java:59)
     at org.jboss.cache.aop.TreeCacheAopDelegate._regularPutObject(TreeCacheAopDelegate.java:207)
     at org.jboss.cache.aop.TreeCacheAopDelegate._putObject(TreeCacheAopDelegate.java:177)
     at org.jboss.cache.aop.TreeCacheAop._putObject(TreeCacheAop.java:503)
     at org.jboss.cache.aop.TreeCacheAop.putObject(TreeCacheAop.java:345)
     at org.jboss.cache.aop.TreeCacheAop.putObject(TreeCacheAop.java:325)
     at Test.addObject(Test.java:26)
     at Test.main(Test.java:40)


  • 8. Re: random removing from Map (AOP-Cache)
    Scott Marlow Master

    Can you also let me know which version of JBoss Cache you are using?

  • 9. Re: random removing from Map (AOP-Cache)
    Daniel Zwicker Newbie

    I have used all versions of 1.2.4, it's the same even with sp2.

  • 10. Re: random removing from Map (AOP-Cache)
    Daniel Zwicker Newbie

    In Version 1.3 DR1 it's the same. If you have a clean started DB you'll get the a stacktrace similar to the first one.

    Exception in thread "main" org.jboss.util.NestedRuntimeException: InternalDelegate.resetRefCount(). Ref counter not -1 but 0 at fqn: /pojo/list/1; - nested throwable: (java.lang.IllegalStateException: InternalDelegate.resetRefCount(). Ref counter not -1 but 0 at fqn: /pojo/list/1)
     at org.jboss.cache.aop.collection.CachedListImpl.remove(CachedListImpl.java:155)
     at org.jboss.cache.aop.collection.CachedListAbstract.remove(CachedListAbstract.java:74)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     at java.lang.reflect.Method.invoke(Unknown Source)
     at org.jboss.cache.aop.collection.CollectionInterceptorUtil.invoke(CollectionInterceptorUtil.java:124)
     at org.jboss.cache.aop.collection.CachedListInterceptor.invoke(CachedListInterceptor.java:125)
     at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
     at AOPClassProxy$0.remove(AOPClassProxy$0.java)
     at TestObject.remove(TestObject.java:19)
     at Test.main(Test.java:55)
    Caused by: java.lang.IllegalStateException: InternalDelegate.resetRefCount(). Ref counter not -1 but 0 at fqn: /pojo/list/1
     at org.jboss.cache.aop.InternalDelegate.resetRefCount(InternalDelegate.java:59)
     at org.jboss.cache.aop.CollectionClassHandler.collectionObjectPut(CollectionClassHandler.java:68)
     at org.jboss.cache.aop.TreeCacheAopDelegate._putObject(TreeCacheAopDelegate.java:184)
     at org.jboss.cache.aop.TreeCacheAop._putObject(TreeCacheAop.java:502)
     at org.jboss.cache.aop.TreeCacheAop.putObject(TreeCacheAop.java:344)
     at org.jboss.cache.aop.collection.CachedListImpl.remove(CachedListImpl.java:151)
     ... 11 more
    

    I have played with the Isolationlevel and with the position of the tx.commit(). If the remove isn't in a transaction it works.
    Perhaps my code is wrong, but for me it seems ok. It should work even witch a "remove-tx"?

  • 11. Re: random removing from Map (AOP-Cache)
    Scott Marlow Master

    Can you create a Jira issue for this? I've recreated a failure with the remove operation but haven't gotten the same exception as you.

  • 12. Re: random removing from Map (AOP-Cache)
    Scott Marlow Master

    I spoke too soon, I misread my debug output information.

    I noticed in the test code that you put the POJO in the cache but you don't retrieve it. I think you should try retrieving it after putting it in and use the retrieved copy instead of the original.

    I believe that once you put the POJO in the cache, it belongs to the cache (you shouldn't operate on it directly).

    Change your code from:

    TestObject pojo = new TestObject();
    pojo.init();
    tx.begin();
    server.addObject("/pojo", pojo);
    tx.commit();

    to:

    TestObject pojo = new TestObject();
    pojo.init();
    tx.begin();
    server.addObject("/pojo", pojo);
    pojo = (TestObject)server.getObject("/pojo"); // get ref to proxied object
    tx.commit();

    Please let me know if this helps.

  • 13. Re: random removing from Map (AOP-Cache)
    Daniel Zwicker Newbie

    No, it's the same as before.

  • 14. Re: random removing from Map (AOP-Cache)
    Scott Marlow Master

    I still haven't reproduced with running it as part of a unit test.

    I'll try using your cach-config file next.

1 2 Previous Next