HashSet deserialization... bug?

44 views
Skip to first unread message

snic...@gmail.com

unread,
Jun 28, 2006, 7:05:29 PM6/28/06
to Google Web Toolkit
When trying to deserialize a HashSet (either from the client to the
server OR vice versa) I get an exception (pasted below). I believe this
to be a bug, as I've created a simple test case that works for
ArrayList, but not HashSet.

Am I doing something wrong? If not, is there a workaround?

Thanks!

-Seth

Exception I get:

[WARN] StandardContext[]Exception while dispatching incoming RPC call
com.google.gwt.user.client.rpc.SerializationException:
java.lang.reflect.InvocationTargetException
at
com.google.gwt.user.server.rpc.ServerSerializationStream.deserizeWithCustomSerializer(ServerSerializationStream.java:589)
at
com.google.gwt.user.server.rpc.ServerSerializationStream.deserialize(ServerSerializationStream.java:512)
at
com.google.gwt.user.server.rpc.ServerSerializationStream.readObject(ServerSerializationStream.java:443)
at
com.google.gwt.user.server.rpc.ServerSerializationStream.deserializeValue(ServerSerializationStream.java:411)
at
com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:290)
at
com.google.gwt.user.server.rpc.RemoteServiceServlet.doPost(RemoteServiceServlet.java:186)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at
com.google.gwt.dev.shell.GWTShellServlet.service(GWTShellServlet.java:113)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
Caused by: java.lang.reflect.InvocationTargetException: null
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
com.google.gwt.user.server.rpc.ServerSerializationStream.deserizeWithCustomSerializer(ServerSerializationStream.java:572)
at
com.google.gwt.user.server.rpc.ServerSerializationStream.deserialize(ServerSerializationStream.java:512)
at
com.google.gwt.user.server.rpc.ServerSerializationStream.readObject(ServerSerializationStream.java:443)
at
com.google.gwt.user.server.rpc.ServerSerializationStream.deserializeValue(ServerSerializationStream.java:411)
at
com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:290)
at
com.google.gwt.user.server.rpc.RemoteServiceServlet.doPost(RemoteServiceServlet.java:186)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
Caused by: java.lang.IndexOutOfBoundsException: Index: 16, Size: 16
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at
com.google.gwt.user.server.rpc.ServerSerializationStream.extract(ServerSerializationStream.java:133)
at
com.google.gwt.user.client.rpc.SerializationStream.readInt(SerializationStream.java:109)
at
com.google.gwt.user.client.rpc.core.java.util.HashSet_CustomFieldSerializer.deserialize(HashSet_CustomFieldSerializer.java:51)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
com.google.gwt.user.server.rpc.ServerSerializationStream.deserizeWithCustomSerializer(ServerSerializationStream.java:572)
at
com.google.gwt.user.server.rpc.ServerSerializationStream.deserialize(ServerSerializationStream.java:512)
at
com.google.gwt.user.server.rpc.ServerSerializationStream.readObject(ServerSerializationStream.java:443)
at
com.google.gwt.user.server.rpc.ServerSerializationStream.deserializeValue(ServerSerializationStream.java:411)
at
com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:290)

Paul Strack

unread,
Jun 28, 2006, 7:29:12 PM6/28/06
to Google Web Toolkit
HashSet is not supported by GWT. Move your data into an ArrayList.

snic...@gmail.com

unread,
Jun 28, 2006, 7:36:53 PM6/28/06
to Google Web Toolkit
According to:
http://code.google.com/webtoolkit/documentation/com.google.gwt.doc.DeveloperGuide.RemoteProcedureCalls.SerializableTypes.html

Objects with interface "java.util.Set and java.util.List" are both
passable through RPC, and since the only concrete classes that
instantiate those are HashSet and ArrayList, respectively, they would
seem to be on equal footing?

Also, according to
http://code.google.com/webtoolkit/documentation/java.util.html ,
HashSet is one of the JRE emulation classes supported by GWT.

That said, HashSet doesn't seem to work with RPC, so in some sense I
guess its not supported ;-)

Paul Strack

unread,
Jun 28, 2006, 7:55:24 PM6/28/06
to Google Web Toolkit
I looked it up, and I was wrong. According to the documentation,
HashSet should be serializable:

http://code.google.com/webtoolkit/documentation/com.google.gwt.doc.DeveloperGuide.RemoteProcedureCalls.SerializableTypes.html

Maybe you didn't set the "@gwt.typeArgs" value? Or maybe it is a bug? I
use ArrayList for all my serialization, so I haven't tried it.

snic...@gmail.com

unread,
Jun 28, 2006, 8:00:10 PM6/28/06
to Google Web Toolkit
I've tried it with typeArgs set and unset, same problem. Thanks though,
I'm just going back to ArrayList for now too.

georgeuoa

unread,
Jun 29, 2006, 2:20:53 AM6/29/06
to Google Web Toolkit
Yes, HashSet is serialisable, but I think there lies a more fundamental
issue with multiple references to objects. I reported a similar
behaviour a few days ago [1].

I found that when you have an object which contains both a normal
reference p to an object and a collection with a reference to the same
object then deserialisation breaks (look example [2]).


G.

[1]
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/1b29be75d1b47ed/879c8438d50072bc?q=georgeuoa&rnum=1#879c8438d50072bc

[2]
class A{
SomeType p = ...;
ArrayList list = ...;
}

A a = new A();
a.list.add(a.p);

Seth Nickell

unread,
Jun 29, 2006, 1:18:16 PM6/29/06
to Google-We...@googlegroups.com
I get this error deserializing, (new HashSet()), i.e. a totally blank
HashSet. Anyone succesfully doing RPC using a HashSet? I haven't been
able to make it work on even simple cases (except in the case that you
pass in "null" instead of a HashSet object, heh).
Reply all
Reply to author
Forward
0 new messages