I have a class which has a counter field.

public Class Foo implements Serializable {
   private static final long serialVersionUID = 1L;
   private int counter = 0;
   // getter and setter omitted for simplicity
}

And in my program I put a Foo instance into HttpSession.

HttpSession session = request.getSession(true);
Foo foo = (Foo)session.getAttribute("foo");
if (foo==null) {
        foo = new idv.Foo();
        session.setAttribute("foo", foo);
}
else
        foo.setCounter(foo.getCounter()+1);
// continue processing with foo

If session.setAttribute is executed, the session (and foo) is
serialized correctly and I can get the correct counter value at the
next request. But the counter value never gets increased at subsequent
requests.

If I move the session.setAttribute call to behind the if-else block
to force execution in every request, the counter value increases
correctly.

if (foo==null)
        foo = new idv.Foo();
else
        foo.setCounter(foo.getCounter()+1);
session.setAttribute("foo", foo);

I didn't see any doc about this. Is it a bug or a feature?

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to