You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Due to the LocalCache not being enabled when not setting deferred-write=true, subsequent calls to session.getAttribute("myKey") will neither return the same instance, nor will changes to the returned object be visible to subsequent calls.
session.setAttribute("myKey", new ArrayList()); // Will serialize the ArrayList
List list1 = session.getAttribute("myKey"); // Will deserialize the original List
list1.add("myValue"); // Will not be serialized
List list2 session.getAttribute("myKey"); // Will deserialize the original List again
System.out.println(list1 == list2); // false
System.out.println(list1.getSize()) // 1
System.out.println(list2.getSize()) // 0
After reading the Servlet Spec, I'm not sure if this behaviour is compliant. The spec is not very verbose regarding this topic. But: Since the behaviour differs when switching deferred-write parameter on and off, it should at least be clearly documented (with a big red warning sign).
Took me quite some time digging through Spring Web Flows source code.
I you want to provide a more transparent solution, you could think about returning java.lang.reflect.Proxy instances of the original session attribute values class, when deferred-write=false.
Whenever a Method of the Proxy instance is called, it would call
currentState = session.getAttribute(myKey)
to get the current object state, delegate to the object returned thereby
Thanks @BGehrels for the contribution. I have updated the doc.
Currently we are in a feature freeze phase so your request about java.lang.reflect.Proxy has been added to the backlog and will be considered in later releases.
Closing the issue as documentation is updated and the request about Proxy objects should not be implemented as it will hide the inherent network roundtrip from the application developer which will cause slow application performance. Application developers need to be aware that to store data in a session, you need to put the data you have modified back into the session.
From @BGehrels on August 14, 2014 18:39
Due to the LocalCache not being enabled when not setting
deferred-write=true
, subsequent calls tosession.getAttribute("myKey")
will neither return the same instance, nor will changes to the returned object be visible to subsequent calls.After reading the Servlet Spec, I'm not sure if this behaviour is compliant. The spec is not very verbose regarding this topic. But: Since the behaviour differs when switching deferred-write parameter on and off, it should at least be clearly documented (with a big red warning sign).
Took me quite some time digging through Spring Web Flows source code.
Copied from original issue: hazelcast/hazelcast#3269
The text was updated successfully, but these errors were encountered: