Fatal error in serialization of the application: Class must implement seri

Hello !

I have a problem when using Vaadin and I cannot figure out how to solve it.

I have a button and and I add a listener to it declared somehow like this:

Button delete = new Button("Delete");
delete.addListener(new Button.ClickListener() {
	
	@Override
	public void buttonClick(ClickEvent event) {
		// handle the event
	}
	
});

In the Eclipse Java console i keep getting messages like this:

System:
WinXP SP3
JRE/JDK v6u20
Apache Tomcat 6.0.x

Does anyone have a suggestion ?

Thanks in advance!

Does this actually break anything?

Unless you have something else in your environment that does require serializability, I think the messages you are seeing are harmless - this is probably Tomcat trying to serialize sessions when exiting etc. to reload them when restarted. Serializing sessions is the Tomcat default setting but usually not needed, you can disable it by uncommenting a line in Tomcat’s context.xml - look for other threads about this on the forum, or just google for disabling tomcat session serialization.

Thank you for your reply.

No, it does not break anything but it’s kind of annoying. I think you are right, it is a Tomcat message.
When I restarted Tomcat I got the following message:


SEVERE: IOException while loading persisted sessions: java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: com.example.vaadin001.data.Role
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: com.example.vaadin001.data.Role
	at java.io.ObjectInputStream.readObject0(Unknown Source)
	at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
	at java.io.ObjectInputStream.readSerialData(Unknown Source)
	at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
	at java.io.ObjectInputStream.readObject0(Unknown Source)
	at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
	at java.io.ObjectInputStream.defaultReadObject(Unknown Source)
....
[truncated]

I uncommented the following line from context.xml and it is fine now.

<Manager pathname="" />

So, if I may ask, can those messages be avoided in any way ? I mean, considering that the configuration line above would still be commented, how could I implement serialization for a class defined similar to the one in the first post in this thread ?

This message is about one of your data classes - for that, you need to implement the interface java.io.Serializable. Vaadin classes and interfaces are serializable, so extending them should result in serializable classes (but without an explicit serial UID, at least if you are using the default Eclipse settings). You can generate serial UIDs for your own classes with Eclipse quick fixes (Ctrl-1) if you want, or turn off the warnings about them.

If you are interested in learning more, I recommend you read about serialization in some Java book or search the web for articles about it, like
this one
,
this one
and
this one
(based on a quick google search).

That is the thing: I do implement the Seriallizable Interface, because the anonymous class about which Tomcat complains implements the Button.ClickListener Interface, which has the following definition:

public interface ClickListener extends Serializable {
        public void buttonClick(ClickEvent event);
    }

The definition of the anonymous class is the following:

Button delete = new Button("Delete");
delete.addListener(new Button.ClickListener() {
	
        private static final long serialVersionUID = 7201832606823775590L;
			
	@Override
	public void buttonClick(ClickEvent event) {
		// handle the event
	}
	
});

So I implement both the serialVersionUID from Seriallizable and public void buttonClick(ClickEvent event) from Button.ClickListener.

It should work, then, unless something referenced by the fields of the anonymous class is not serializable. In your example, there is only one field (this$0) pointing to the instance of the enclosing type in the context of which this anonymous class instance was created - do check that the enclosing class is fully serializable.

Other possibilities include a problems with stale compiled classes (clean your target folders, including any work directories on the application server), some classloading issue (the Serializable interface being loaded with a different classloader), a compiler bug or perhaps some hidden, compiler-generated synthetic (accessor) class if you are referencing private fields/methods.

Again, sorry to revive old threads, however, I had this issue. It turns out that my classes were holding onto proxied instances of EJB’s. Once I set them all to ‘transient’ all this went away. I especially had issues with anonymous inner classes - even though they were serializable. Have a quick look at that - just pay attention to your member variables.

However, I still cannot resume a session after a redeploy of the same app - but this may be due to many things besides Vaadin (like WELD/Glassfish/Vaadin mix). I’m not fussed about this, at this point :slight_smile: