Com.couchbase.client.java.error.TranscodingException: Could not encode document with ID

Hi,

Could someone explain the reason behind the below exception while updating a Serializable Document (non-JSON) to Couchbase Bucket.

2016-03-16 14:10:50 ERROR : - com.couchbase.client.java.error.TranscodingException: Could not encode document with ID 96181FDE28610ABAABA6457FE30CF005.faresearch.response
at com.couchbase.client.java.transcoder.AbstractTranscoder.encode(AbstractTranscoder.java:68)
at com.couchbase.client.java.CouchbaseAsyncBucket.upsert(CouchbaseAsyncBucket.java:422)
at com.couchbase.client.java.CouchbaseBucket.upsert(CouchbaseBucket.java:268)
at com.couchbase.client.java.CouchbaseBucket.upsert(CouchbaseBucket.java:263)
at com.his.farebroker.interfaces.couchbase.FareProductBucket.putElementInBucket(FareProductBucket.java:74)
at com.his.farebroker.interfaces.couchbase.FBCouchbaseBucketFactory.putElementInBucket(FBCouchbaseBucketFactory.java:82)
at com.his.farebroker.cache.common.CouchbaseHelper.putElementInBucketAsync(CouchbaseHelper.java:35)
at com.his.farebroker.cache.common.CouchbaseHelper$$FastClassByCGLIB$$1c211194.invoke()
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:688)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.interceptor.AsyncExecutionInterceptor$1.call(AsyncExecutionInterceptor.java:80)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.util.ConcurrentModificationException
at java.util.ArrayList.writeObject(ArrayList.java:573)
at sun.reflect.GeneratedMethodAccessor173.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1469)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1400)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1518)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1483)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1400)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:330)
at com.couchbase.client.java.transcoder.TranscoderUtils.serialize(TranscoderUtils.java:224)
at com.couchbase.client.java.transcoder.SerializableTranscoder.doEncode(SerializableTranscoder.java:55)
at com.couchbase.client.java.transcoder.SerializableTranscoder.doEncode(SerializableTranscoder.java:39)
at com.couchbase.client.java.transcoder.AbstractTranscoder.encode(AbstractTranscoder.java:63)
… 14 more

The code snippet:

fareProductBucket.upsert(SerializableDocument.create(cacheKey,couchBaseExpiry,(Serializable) value));

Environment/Framework Details :

  • Jdk version is 1.6.
  • Tomcat 6 is the web server.
  • java-client 2.1.4 jar is used
  • couchbase-server-community-3.0.1-centos5.x86_64.rpm is used for Couchbase installation

If you look at the cause from the stack trace you can see that something is modifying the object you are trying to serialize right now. There are many similar questions on stack overflow, maybe start here: Java serialization causes concurrency modification exception - Stack Overflow - I don’t think this is couchbase related :slight_smile:

@daschl
Thank you for the update.
In fact from our code the update to Couchbase happens in an asynchronous thread and this could be the reason for this exception.

I came across the same error and use case is I am caching the resource which contain nested objects and does not implement Serializable, I fixed it implementing Serializable in all the classes.

Have written an article as well which describe my problem and fix for the same -
Fixing com.couchbase.client.java.error.TranscodingException: Could not encode document with ID cache:EMPLOYEE_:1 – Couchbase