migrator / guava-libraries-2

Guava: Google Core Libraries for Java 1.6+
0 stars 0 forks source link

RegularImmutableAsList CustomFieldSerializer depends on RegularImmutableSet but did not include it into Serializationpolicy #43

Open migrator opened 9 years ago

migrator commented 9 years ago

if you have a RemoteService with only 1 method and the signature:

void testImmutableList(ImmutableList<String> list);

and you call it with

testImmutableList(ImmutableSet.of("a", "b").asList())

you will get an exception:

com.google.gwt.user.client.rpc.SerializationException: Type 'com.google.common.collect.RegularImmutableSet' was not included in the set of types which can be deserialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be deserialized.
    at com.google.gwt.user.server.rpc.impl.StandardSerializationPolicy.validateDeserialize(StandardSerializationPolicy.java:158)

this happens because the delegate of RegularImmutableAsList is a RegularImmutableSet which is not included into the serialization policy but is written by the RegularImmutableAsList_CustomFieldSerializer

writer.writeObject(instance.delegateCollection());
writer.writeObject(instance.delegateList());

relevance: 2

migrator commented 9 years ago

summary: Not Defined

you have to call the RemoteServiceAsync which looks like

testImmutableList(ImmutableSet.of("a", "b").asList(), new AsyncCallbacl<Void>() { ... });

status Not Defined creator: jbj...@gmail.com created at: Sep 3, 2014

migrator commented 9 years ago

summary: Not Defined

That's bad :(

The workaround is to do something like ImmutableList.copyOf(new ArrayList<>(set)), but of course that's not something that we should make you do.

Under the current GWT serialization implementation, this is hard (impossible?) to fix without requiring everyone who serializes ImmutableList to have every possible implementation available on the client side. Some clients don't like the resulting bloat. To avoid that, we'd ideally like for GWT to implement https://code.google.com/p/google-web-toolkit/issues/detail?id=8844

A possible alternative that I've been considering is for us to have a single ImmutableList class that delegates all its implementation to an ImmutableListImpl class. This would allow us to have a single ImmutableList serializer for all ImmutableLists. The downside is indirection and extra memory on the server. It's hard to know how much that would cost. One day I hope to look into this. Until then, we're unlikely to do much here, barring new ideas. Sorry that I don't have something more immediate for you.

status Not Defined creator: cpov...@google.com created at: Sep 3, 2014

migrator commented 9 years ago

summary: Not Defined

We have overriden the CustomFieldSerializer with our own implementation and the problem is solved.

status Not Defined creator: jbj...@gmail.com created at: Sep 8, 2014

migrator commented 9 years ago

summary: Not Defined

Clever! I think we'll do it.

status Not Defined creator: cpov...@google.com created at: Sep 8, 2014

migrator commented 9 years ago

summary: Not Defined

I'd be happy to take the revised version directly, but we'd need your legal permission:

https://developers.google.com/open-source/cla/individual or: https://developers.google.com/open-source/cla/corporate

Let me know whether you'd like to do that. Otherwise, I'll figure out what we can do to implement things from scratch.

status Not Defined creator: cpov...@google.com created at: Sep 8, 2014

migrator commented 9 years ago

summary: Not Defined

Have you found any decision on whether the patch is something you can officially/legally contribute? Thanks.

status Not Defined creator: cpov...@google.com created at: Oct 1, 2014

migrator commented 9 years ago

summary: Not Defined

It can be contributed, with your own header, sorry for the late answer

status Not Defined creator: jbj...@gmail.com created at: Oct 25 (2 days ago)