Search
Calendar
July 2017
S M T W T F S
« Sep    
 1
2345678
9101112131415
16171819202122
23242526272829
3031  
Your widget title
Archives

PostHeaderIcon java.io.NotSerializableException: org.apache.log4j.Logger

Case

I use Oracle Coherence (Tangosol) as distributed cache for a given class. This class contains a non-static Log4J’s Logger as field.
(what a Logger does in an “POJO” is not obvious and requires further development ; let’s say it is used during the development phase, but has nothing to do in a POJO and should be removed later).
When Tangosol tries to put the object in cache, I get this error:

java.io.NotSerializableException: org.apache.log4j.Logger

Complete stacktrace

java.io.NotSerializableException: org.apache.log4j.Logger
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
        at com.tangosol.util.ExternalizableHelper.writeSerializable(ExternalizableHelper.java:2181)
        at com.tangosol.util.ExternalizableHelper.writeObjectInternal(ExternalizableHelper.java:2603)
        at com.tangosol.util.ExternalizableHelper.serializeInternal(ExternalizableHelper.java:2529)
        at com.tangosol.util.ExternalizableHelper.toBinary(ExternalizableHelper.java:206)
        at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$ConverterValueToBinary.convert(DistributedCache.CDB:3)
        at com.tangosol.util.ConverterCollections$ConverterMap.put(ConverterCollections.java:1566)
        at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$ViewMap.put(DistributedCache.CDB:1)
        at com.tangosol.coherence.component.util.SafeNamedCache.put(SafeNamedCache.CDB:1)
        at com.lalou.jonathan.business.cache.TypedEhCache.put(TypedEhCache.java:73)
        at com.lalou.jonathan.business.cache.TypedEhCache.setInCache(TypedEhCache.java:58)
        at com.lalou.jonathan.business.StringToRequestListTransformer.transform(JonathanTransformer.java:104)
        at org.mule.transformer.AbstractMessageAwareTransformer.doTransform(AbstractMessageAwareTransformer.java:68)
        at org.mule.transformer.AbstractTransformer.transform(AbstractTransformer.java:254)
        at org.mule.DefaultMuleMessage.applyAllTransformers(DefaultMuleMessage.java:621)
        at org.mule.DefaultMuleMessage.applyTransformers(DefaultMuleMessage.java:582)
        at org.mule.DefaultMuleMessage.applyTransformers(DefaultMuleMessage.java:575)
        at org.mule.DefaultMuleEvent.transformMessage(DefaultMuleEvent.java:326)
        at org.mule.DefaultMuleEvent.transformMessage(DefaultMuleEvent.java:321)
        at org.mule.component.simple.PassThroughComponent.doInvoke(PassThroughComponent.java:27)
        at org.mule.component.AbstractComponent.invokeInternal(AbstractComponent.java:133)
        at org.mule.component.AbstractComponent.invoke(AbstractComponent.java:161)
        at org.mule.service.AbstractService.invokeComponent(AbstractService.java:929)
        at org.mule.model.seda.SedaService.access$100(SedaService.java:56)
        at org.mule.model.seda.SedaService$ComponentStageWorker.run(SedaService.java:574)
        at org.mule.work.WorkerContext.run(WorkerContext.java:310)
        at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1061)
        at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:575)
        at java.lang.Thread.run(Thread.java:619)

Fix

Declare the Logger as static:

private final Logger LOG = Logger.getLogger(CsvFileObject.class);

In my case, the issue was fixed. If it is not, try to declare the Logger as static transient, I assume it could help.

Leave a Reply