5

I currently doing a work with struts2 and this error suddenly appears. Some cache of my objects is not working.

I use JBoss 5 and struts2 : struts2-core-2.3.4.1.jar xwork-core-2.3.4.1.jar

The stack trace is here : http://pastebin.com/QpPV01wX

this is some snippet :

java.io.NotSerializableException: com.opensymphony.xwork2.inject.ContainerImpl$ConstructorInjector
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1164)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:330)
        at com.opensymphony.xwork2.inject.util.ReferenceMap.writeObject(ReferenceMap.java:595)
        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: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.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.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.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 java.util.HashMap.writeObject(HashMap.java:1001)
        at sun.reflect.GeneratedMethodAccessor413.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.writeObject(ObjectOutputStream.java:330)
        at java.util.HashMap.writeObject(HashMap.java:1001)
        at sun.reflect.GeneratedMethodAccessor413.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.writeObject(ObjectOutputStream.java:330)
        at org.jboss.ha.framework.server.SimpleCachableMarshalledValue.serialize(SimpleCachableMarshalledValue.java:271)
        at  

I would love suggestions or might be something wrong I did.

Thank you very much in advance,

** UPDATED

I tried to remove token session interceptor that I used in my struts.xml and the problem is gone. Still, I dont know why it went wrong if I use token. At least in my case, it is solved by removing token session interceptor.

I remove following line on struts.xml

<interceptor-ref name="tokenSession">
  <param name="excludeMethods">list</param>
  <param name="includeMethods">save,update</param>
</interceptor-ref>
Roman C
  • 49,761
  • 33
  • 66
  • 176
daimagine
  • 61
  • 2
  • 8
  • Have you migrated to 2.3.x from some older version? I saw that problem already but I'm not able to identify the source :\ It would be nice if you could describe what kind of actions/results do you use (execAndWait), as it looks like a struts2 problem. – Lukasz Lenart Mar 25 '13 at 10:13
  • Yes I did, I have migrated to the latest 2.3.12 with another related libs also. The actions I have is updating a user resource. And the problem raise after it. But, user is still updated though. Any suggest maybe? – daimagine Mar 26 '13 at 04:06
  • @LukaszLenart, here where I assume the problem cause was. `11:02:02,076 ERROR [CommandAwareRpcDispatcher] java.io.NotSerializableException: com.opensymphony.xwork2.inject.ContainerImpl$ConstructorInjector 11:02:02,076 WARN [/office] Failed to replicate session koY6yLeuKfHSBdQUfOJXBg__.node2` and com.opensymphony.xwork2.inject.ContainerImpl is not Serializable if I'm not wrong – daimagine Mar 26 '13 at 04:16
  • 1
    Yes, but it should not be put in the session. Is some how a side effect of some actions or results you use. In other words: S2 doesn't put Container in the session by itself. – Lukasz Lenart Mar 26 '13 at 10:44
  • As showed in the stack trace, I stored wrapper class containing Logged user and some menus that user has been authorized on. I will do double check of what I stored to session map. Thank you @LukaszLenart – daimagine Mar 27 '13 at 03:05
  • 2
    To be clear: it is a bug in S2 but I need your help to identify it. As I said it must be a side effect of your code - you put something in the Session which is connected with S2 internals and these internals contains reference to Container. – Lukasz Lenart Mar 27 '13 at 07:03
  • I tried to remove from my struts.xml and it works like a charm. but still I dont know why it went wrong when I used token interceptor – daimagine Mar 27 '13 at 09:45
  • as I understand that solved the problem? https://issues.apache.org/jira/browse/WW-4028 – Lukasz Lenart Mar 27 '13 at 11:16
  • presumably yes, it solved the problem for me. anyway, thanks for making a jira issue @LukaszLenart – daimagine Mar 27 '13 at 11:25
  • 2
    Ok, I have changed how ActionInvocation is stored in the HttpSession and as from 2.3.15 everything should work smoothly :-) https://issues.apache.org/jira/browse/WW-4028 – Lukasz Lenart May 17 '13 at 12:40
  • @LukaszLenart, I am seeing identical issues with the ExecuteAndWait interceptor in Struts 2.5.14.1. The Stackoverflow details are here: https://stackoverflow.com/questions/47660913/struts2-notserializableexception-occurs-with-executeandwaitinterceptor – Erica Kane Dec 05 '17 at 19:09
  • 1
    Thanks @EricaKane we are working on that :) – Lukasz Lenart Dec 08 '17 at 06:22

4 Answers4

4

Seems you have put Objects into the cache or your session that do not implement java.io.Serializable.

vhunsicker
  • 538
  • 6
  • 20
  • Thanks @vhunsicker. I have did some recheck to make sure all my session object is serializable. Could you mention where may I have missing? – daimagine Mar 22 '13 at 12:10
  • Make sure your session objects don't have fields that aren't serializable such as a reference to the Container. – rees Mar 22 '13 at 12:19
  • Yes right. Serializables should only contain primitive attributes or attributes which implement Serializable themself.For the case some attributes should not be serializable, you can make them transient. – vhunsicker Mar 22 '13 at 12:40
  • You can detect such problems by static code analysis. E.g. with help of PMD, findBugs etc.. – vhunsicker Mar 22 '13 at 12:43
  • I havent used any of them, PMD nor findBugs. Could it detect what field should be Serializable? btw, thanks for the suggestions – daimagine Mar 26 '13 at 04:10
  • 1
    As I know the tools indicate which fields are not serializable when a class implements Serializable. What classes should implememt Serializable you need to figure out yourself I guess. E.g. everything you put into a session map, Statefull SessionBeans, Entities, .. – vhunsicker Mar 26 '13 at 07:24
0

I also meet the same problem, but I finnaly find my struts2-spring-plugin-2.0.14.jar doesn't match my struts2-core.2.2.3.jar, so I replaced the struts2-spring-plugin with the corresponding version and it's working~ good luck~ hope this helpful for other people~

0

I solved that problem by switching to tokenInterceptor in place of tokenSessionInterceptor. tokenInterceptor is ok for most of the cases.

Shiva
  • 6,677
  • 4
  • 36
  • 61
0

Ran into this issue with struts-2.3.32 as well. The com.opensymphony.xwork2.DefaultActionInvocation class has a reference to the Action.
If your action extends com.opensymphony.xwork2.ActionSupport then it references the com.opensymphony.xwork2.inject.Container.
The workaround is to remove the dependency on ActionSupport.

David Lai
  • 9
  • 3