AnimatorProxy with Google App Engine

Hi folks,

I’m having problems trying to use the AnimatorProxy class inside a Google App Engine enviroment. The class I’m currently using is the Disclosure, and I get the following exception when I create the component:


com.vaadin.terminal.gwt.server.GAEApplicationServlet service
SEVERE: Not serializable!
java.io.NotSerializableException: java.util.WeakHashMap
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1180)
	at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493)
	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
	at java.util.LinkedList.writeObject(LinkedList.java:960)
	at sun.reflect.GeneratedMethodAccessor34.invoke(Unknown Source)
        ...

So I started to search for this java.util.WeakHashMap, and I found it in the AnimatorProxy class, at line 108:


/* Internal mapping to handle events from client side */
// TODO are the objects garbage collected ever?
private Map<Integer, Animation> animIdToRequest = new WeakHashMap<Integer, Animation>();

So, the question is, what can I do to solve the problem? Can I just switch the WeakHashMap to a regular HashMap (and pray for the god of RAM) ?

Thank you.

Ok, I fixed it with 2 lines of code:

At line 108, as I said above, I changed the WeakHashMap reference to a regular HashMap reference:

private Map<Integer, Animation> animIdToRequest = new HashMap<Integer, Animation>();

And at line 27, I made the class Animation implement java.io.Serializable:

public class Animation implements Serializable {

Now It’s working =)

Hi,
I have same problem but i can’t use your solution because I use a maven project and the Animator dependency. So I can’t modify the library because if someone import the project by command mvn eclipse:eclipse, maven will download the library without my modification. Is this an other solution ? Else I wait that the library author update his library fixed.

Thanks

I guess as a temporary workaround you could have a modified copy of the class in a package by the same name as the original in your project. Normally your project is first on the classpath, so the copy “overrides” the version in the JAR.

Not a good solution for maintainability, but maybe you can try to get the author’s attention on the forum while using the workaround.

Note that the change might not be good as is for the library - I believe there was a reason (probably related to avoiding memory leaks) to use WeakHashMap instead of HashMap.