Likely serialization bugs related to use of Java keySets

I’ve been trying to track down some thorny serialization issues in a GAE app using Vaadin. One issue that I fixed involved a keySet() that is returned by various Map and other classes. It turns out that the Set returned by keySet is not itself Serializable, eventhough the Map it comes from is Serializable. (see: http://www.javaworld.com/community/node/5407 and http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4756277).

While that issue is fixed, I am still trying to track down another one that occurs when I call Table.refreshRenderedCells().

I am not sure it is the same issue, but while looking through Table, I found an instance of keySet(). Searching through all the Vaadin source, I found quite a few uses. Even if this issue isn’t the specific source of my problem, it is probably a ticking time bomb that should be fixed.

The solution is simple, just wrap the returned keySet() in a Serializable set like HashSet. So instead of:

map.keySet()

use

new HashSet(map.keySet())

A somewhat similar issue I encountered in my application (not in Vaadin) is that the java.lang.reflect.Method class is also not Serializable (see http://stackoverflow.com/questions/1769842/serialization-of-method-object-in-java-is-possible).

I searched the Vaadin source code and noticed this class is used a lot. This probably qualifies as another potential danger. The solution is to store the text description of the Method instead of the Method itself, and obtain the method via reflection only when needed.

Please ignore the comment RE Method Serialization. Comment RE keySet still stands. After digging deeper, I see a lot of work has been put into dealing with Method Serialization. My only comment is that you seem to have gone a really complicated route. You are changing the Method to a String right for Serialization write and reading it as a String and converting back to Method for Serialization read. This seems way more complicated than just storing it as a String in the first place and converting when needed.