Transient fields in session-scoped beans cannot fail over successfully

This rule flags fields with the transient modifier in classes that are annotated with @SessionScoped. In the Contexts and Dependency Injection (CDI) 1.0 OpenWebBeans implementation, an application can set transient fields directly on session-scoped beans. In the CDI 1.2 Weld implementation, setting the transient field directly does not result in the field being populated after the failover, which can cause unexpected behavior in your application.

Verify that each transient field that is flagged by this rule is only set by using a method provided by the containing class. If there is no set method for the field, add a set method and call it instead of setting the field directly.

In the following example, the UserBean class is annotated with@SessionScoped. The class also contains a field with a transient modifier that is set using a setter method.


@Named(value="userBean")
@SessionScoped
public class UserBean implements UserInterface, Serializable 
{
	String name;
	transient String nickName;

	...

	public void setNickName(String nick)
	{
	    nickName = nick;
	}
}

For more information about the Java Platform, Enterprise Edition (Java EE) 7 CDI 1.2 implementation, see Contexts and Dependency Injection 1.2 behavior changes.