8 Replies Latest reply on Jun 23, 2011 11:13 AM by manik

    org.infinispan.marshall.NotSerializableException: Object of type class java.lang.String expected to be marshallable

    jaysmith

      Hi,

       

      I have an infinispan cache that I'm trying to persist to a file store from but I'm getting this error:

       

      org.infinispan.marshall.NotSerializableException: Object of type class java.lang.String expected to be marshallable

       

      here is my config and code:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="urn:infinispan:config:4.2 http://www.infinispan.org/schemas/infinispan-config-4.2.xsd"
            xmlns="urn:infinispan:config:4.2">
          <global/>
          <default>
              <eviction wakeUpInterval="500" maxEntries="5000" strategy="LRU"/>
              <expiration lifespan="2000" maxIdle="1000"/>
          </default>
          <namedCache name="writeThroughToFile">
              <loaders passivation="false" shared="false" preload="false">
                  <loader class="org.infinispan.loaders.file.FileCacheStore" fetchPersistentState="true"
                      purgeOnStartup="true" ignoreModifications="false">
                      <properties>
                          <property name="location" value="/web/dev/jboss-cache"/>
                      </properties>
                      <async enabled="true"/>
                  </loader>
              </loaders>
          </namedCache>
      </infinispan>
      


      Code:

       

      package test.cache.loader;
      
      import org.infinispan.Cache;
      import org.infinispan.manager.DefaultCacheManager;
      import org.infinispan.manager.EmbeddedCacheManager;
      import org.junit.AfterClass;
      import org.junit.Assert;
      import org.junit.BeforeClass;
      import org.junit.Test;
      
      public class CustomCacheLoaderTest {
          /** cache. */
          private static Cache<String, String> cache = null;
      
          @AfterClass
          public final static void afterClass() throws Exception {
              cache.stop();
              cache = null;
          }
      
          @BeforeClass
          public final static void beforeClass() throws Exception {
              EmbeddedCacheManager cacheManager = new DefaultCacheManager("infinispan-cache-configuration.xml");
              cache = cacheManager.getCache("writeThroughToFile");
              cache.start();
          }
      
          @Test
          public final void put() throws Exception {
              cache.put("test", "this is a test");
              Assert.assertNotNull(cache.get("test"));
              System.out.println(cache.get("test"));
          }
      }
      
        • 1. org.infinispan.marshall.NotSerializableException: Object of type class java.lang.String expected to be marshallable
          jaysmith

          Finally found the problem, the river-1.2.3.GA.jar lib wasn't on the classpath and that screwed up the marshalling.  Only found that out when looking at the error listed here

           

          https://issues.jboss.org/browse/ISPN-699?page=com.atlassian.jira.plugin.system.issuetabpanels%3Achangehistory-tabpanel

           

          Right then, onto the next bit of grief with this questionable software!

          • 2. org.infinispan.marshall.NotSerializableException: Object of type class java.lang.String expected to be marshallable
            vblagojevic

            Jay,

             

            Glad you resolved the problem you encountered and thanks for the praise and the encouragement!

             

            Regards,

            Vladimir

            • 3. org.infinispan.marshall.NotSerializableException: Object of type class java.lang.String expected to be marshallable
              yangju

              Well, I got the same error and more. I upgraded the infinispan jars in jboss AS6 Final from 4.2.0.FIANL to lastest 5.0.0.CR.

               

              river-1.2.3.GA.jar is on my class path (it is in jboss AS 6's lib directory along with other jars).

               

              It seems if I just have one node, everything works fine. But as soon as I added another node in distributed mode, all sorts of errors popped out, including error thrown at deployment time: I don't understand why NodeKey is not serializable and also why org.infinispan.tree.NodeKey gets involved. I am not using tree cache.

               

              Caused by: java.io.NotSerializableException: org.infinispan.tree.NodeKey

                  at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:972) [:]

                  at org.jboss.marshalling.AbstractMarshaller.writeObject(AbstractMarshaller.java:423) [:]

                  at org.infinispan.container.entries.ImmortalCacheEntry$Externalizer.writeObject(ImmortalCacheEntry.java:126) [:5.0.0.CR1]

                  at org.infinispan.container.entries.ImmortalCacheEntry$Externalizer.writeObject(ImmortalCacheEntry.java:123) [:5.0.0.CR1]

                  at org.infinispan.marshall.jboss.ExternalizerTable$ExternalizerAdapter.writeObject(ExternalizerTable.java:361) [:5.0.0.CR1]

                  at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:147) [:]

                  at org.jboss.marshalling.AbstractMarshaller.writeObject(AbstractMarshaller.java:423) [:]

                  at org.infinispan.marshall.MarshallUtil.marshallCollection(MarshallUtil.java:49) [:5.0.0.CR1]

                  at org.infinispan.marshall.exts.SetExternalizer.writeObject(SetExternalizer.java:62) [:5.0.0.CR1]

                  at org.infinispan.marshall.exts.SetExternalizer.writeObject(SetExternalizer.java:47) [:5.0.0.CR1]

                  at org.infinispan.marshall.jboss.ExternalizerTable$ExternalizerAdapter.writeObject(ExternalizerTable.java:361) [:5.0.0.CR1]

                  at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:147) [:]

                  at org.jboss.marshalling.AbstractMarshaller.writeObject(AbstractMarshaller.java:423) [:]

                  at org.infinispan.marshall.jboss.GenericJBossMarshaller.objectToObjectStream(GenericJBossMarshaller.java:121) [:5.0.0.CR1]

                  at org.infinispan.marshall.VersionAwareMarshaller.objectToObjectStream(VersionAwareMarshaller.java:156) [:5.0.0.CR1]

                  at org.infinispan.statetransfer.StateTransferManagerImpl.generateInMemoryState(StateTransferManagerImpl.java:362) [:5.0.0.CR1]

                  ... 14 more

              Caused by: an exception which occurred:

                  in object org.infinispan.tree.NodeKey@ff816b1c

                      -> toString = NodeKey{contents=STRUCTURE, fqn=/}

                  in object org.infinispan.container.entries.ImmortalCacheEntry@f28dc3ea

                      -> toString = ImmortalCacheEntry{cacheValue=ImmortalCacheValue{value=AtomicHashMap{delegate=org.infinispan.util.FastCopyHashMap@1719c5f}}} ImmortalCacheEntry{key=NodeKey{contents=STRUCTURE, fqn=/}}

                  in object java.util.HashSet@e39ea0fd

                      -> toString = [ImmortalCacheEntry{cacheValue=ImmortalCacheValue{value=AtomicHashMap{delegate=org.infinispan.util.FastCopyHashMap@1719c5f}}} ImmortalCacheEntry{key=NodeKey{contents=STRUCTURE, fqn=/}}, ImmortalCacheEntry{cacheValue=ImmortalCacheValue{value=AtomicHashMap{delegate=org.infinispan.util.FastCopyHashMap@1d16256}}} ImmortalCacheEntry{key=NodeKey{contents=DATA, fqn=/}}]

               

               

               

              The also got errors like this:

              15:01:09,350 ERROR [AbstractKernelController] Error installing to Start: name=HAJNDI state=Create: org.infinispan.CacheException: Unable to invoke method public void org.infinispan.statetransfer.StateTransferManagerImpl.start() throws org.infinispan.statetransfer.StateTransferException on object

                  at org.infinispan.util.ReflectionUtil.invokeAccessibly(ReflectionUtil.java:175) [:5.0.0.CR1]

                  at org.infinispan.factories.AbstractComponentRegistry$PrioritizedMethod.invoke(AbstractComponentRegistry.java:908) [:5.0.0.CR1]

                  at org.infinispan.factories.AbstractComponentRegistry.internalStart(AbstractComponentRegistry.java:706) [:5.0.0.CR1]

                  at org.infinispan.factories.AbstractComponentRegistry.start(AbstractComponentRegistry.java:608) [:5.0.0.CR1]

                  at org.infinispan.factories.ComponentRegistry.start(ComponentRegistry.java:179) [:5.0.0.CR1]

                  at org.infinispan.CacheDelegate.start(CacheDelegate.java:349) [:5.0.0.CR1]

                  at org.infinispan.manager.DefaultCacheManager.createCache(DefaultCacheManager.java:546) [:5.0.0.CR1]

                  at org.infinispan.manager.DefaultCacheManager.getCache(DefaultCacheManager.java:444) [:5.0.0.CR1]

                  at org.jboss.ha.ispn.DefaultCacheContainer.getCache(DefaultCacheContainer.java:126) [:1.0.0.Final]

                  at org.jboss.ha.ispn.DefaultCacheContainer.getCache(DefaultCacheContainer.java:71) [:1.0.0.Final]

                  at org.jboss.ha.jndi.ispn.DistributedTreeManager.init(DistributedTreeManager.java:103) [:1.0.0.Final]

                  at org.jboss.ha.jndi.HAJNDI.init(HAJNDI.java:100) [:6.0.0.Final]

                  at org.jboss.ha.jndi.DetachedHANamingService.startService(DetachedHANamingService.java:387) [:6.0.0.Final]

                  at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:355) [:6.0.0.Final (Build SVNTag:JBoss_6.0.0.Final date: 20101228)]

                  at org.jboss.system.ServiceMBeanSupport.pojoStart(ServiceMBeanSupport.java:195) [:6.0.0.Final (Build SVNTag:JBoss_6.0.0.Final date: 20101228)]

                  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_24]

                  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [:1.6.0_24]

                  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [:1.6.0_24]

                  at java.lang.reflect.Method.invoke(Unknown Source) [:1.6.0_24]

              • 4. org.infinispan.marshall.NotSerializableException: Object of type class java.lang.String expected to be marshallable
                yangju

                This is how my default cache config looks like (the actual cache is created at runtime by calling embeddedCacheManager.getCache(newCacheName):

                <default>

                                <jmxStatistics enabled="true" />

                                <invocationBatching enabled="true" />

                                <indexing enabled="true" indexLocalOnly="true">

                                    <properties>

                                        <property name="hibernate.search.default.directory_provider"

                                            value="ram" />

                                    </properties>

                                </indexing>

                                <storeAsBinary enabled="true"/>

                                <locking isolationLevel="READ_COMMITTED"

                                    lockAcquisitionTimeout="20000" writeSkewCheck="false"

                                    concurrencyLevel="5000" useLockStriping="false" />

                                <transaction

                                    transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"

                                    syncRollbackPhase="false" syncCommitPhase="false" useEagerLocking="true"

                                    eagerLockSingleNode="true" />

                                <clustering mode="distribution">

                                    <l1 enabled="false" lifespan="60000" />

                                    <hash numOwners="2" rehashRpcTimeout="120000" />

                                    <sync />

                                </clustering>

                            </default>           

                 

                Example of object that is cached:

                @ProvidedId

                @Indexed(index = "responseRecord")

                public class MyObject implements Serializable {

                 

                 

                    private static final long serialVersionUID = 3387448277567400646L;

                    @Field(index = Index.UN_TOKENIZED, store = Store.NO)

                    long responseID = 0L;  

                   

                 

                    @Field(index = Index.UN_TOKENIZED, store = Store.NO)

                    int responseStateCode = 0;

                    @Field(index = Index.UN_TOKENIZED, store = Store.NO)

                    int priority = 0;   

                   

                public String toString() {      

                        return Long.toString(this.getResponseID());

                    }

                 

                }

                • 5. Re: org.infinispan.marshall.NotSerializableException: Object of type class java.lang.String expected to be marshallable
                  galder.zamarreno

                  That's weird. I can only assume the issue is due to AS6 still having some dependencies on Infinispan 4.2 and somehow not being able to read the Infinispan 5.0 version of NodeKey which in 5.0 is marshalled via the internal framework.

                  • 6. Re: org.infinispan.marshall.NotSerializableException: Object of type class java.lang.String expected to be marshallable
                    yangju

                    Galder,

                     

                    Could you please ask someone on AS team to give a simple instruction on how to upgrade jboss AS 6 final's infinispan to 5.x?

                    .As you suspect, there must be some jars in jboss as which contains NodeKey class which is loaded earlier than that from infinispan.

                     

                    We really need Infinispan 5 for query feature because we do not know the key and we have to query the cache for next available entry in a distrubuted mode. We have been stuck for months on this upgrading.

                     

                     

                    Thanks.

                     

                    Richard

                    • 7. Re: org.infinispan.marshall.NotSerializableException: Object of type class java.lang.String expected to be marshallable
                      manik

                      You should give JBoss AS 7 a try.  :-)

                      • 8. Re: org.infinispan.marshall.NotSerializableException: Object of type class java.lang.String expected to be marshallable
                        manik

                        Also, if you absolutely need this on JBoss AS 6, have you tried asking this question (about upgrading to Infinispan 5.x) on JBoss AS 6's user forums?