• Post Reply Bookmark Topic Watch Topic
  • New Topic

Set a non-serializable object to null in @PrePassivate?  RSS feed

 
Himai Minh
Ranch Hand
Posts: 1573
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On p.22 of Frits notes,

... dealing with non-serializable object:
1. set them to null in the PrePassivate method.... and recreate them in PostActivate ...


As I read the Enthuware forum, the admin says it is not a requirement to set those non-serializable object to null.
It depends on what the bean provider decides.

Maybe, we only need to recreate the instance with a value in PostActivate.

Reference :http://enthuware.com/forum/viewtopic.php?f=4&t=861
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Posts: 3015
236
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I read the Enthuware forum, the admin says it is not a requirement to set those non-serializable object to null.

True, but call it best practice.

The argument that you should always do it is because there is an exception to the standard Java Serialization protocol: containers are not required to reset the value of transient fields during activation.

4.2.1 Instance Passivation and Conversational State
While the container is not required to use the Serialization protocol for the Java programming language to store the state of a passivated session instance, it must achieve the equivalent result. The one exception is that containers are not required to reset the value of transient fields during activation
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 4106
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question is talking about PostActivate, while you are asking about PrePassivate.
There is no requirement to set all non-serializable fields to null in PostActivate. On the contrary, if your bean contains a non-serializable field that is initialized using some computation, why would you set it to null in PostActivate? The bean needs to be made "read to use" in the PostActivate method. So you will actually need to recompute the value and set the field to that value, and not to null.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!