[concurrency-interest] subList, subMap and navigable

Stanimir Simeonoff stanimir at riflexo.com
Wed Jul 25 10:42:42 EDT 2012

> A SerializableList interface would help at this point to explicitly only
> allow Lists which are Serializable and making it clear which objects can be
> passed in and handled as expected.
> The List/Collection/Map can be buried anywhere in the object graph, not
just the front method of a "service". The provided case was trivial just to
illustrate the issue. "replaceObject" receives any interesting object about
to be serialized and effectively adds writeReplace, if needed. Hence, the
user space code is left alone and happy.
In order to take use of SerializableList, the entire object model has to be
declared like that which is cumbersome, probably in that case using plain
arrays[] would be easier&faster, just not elegant and defeats the purpose
of the collection framework. Overall java.io.Serializable is a tagging
interface and it should not be used as a parameter/type explicitly. And it
doesn't help, it won't matter if an object implements java.io.Serializable
but any of its non-transient/standard-serialized fields does not.

The issue stems from the fact that not all collection views are
serializable but some are. That leads to wrong expectations/observations,
etc. Some views even do the right thing and serialize only the objects
being viewed (TreeSet), so the behavior is not consistent and not mentioned
in the docs.


But as there is no such interface, creating a new interface and
> object/proxy might not be worth it and does not really make a difference to
> your approach with ObjectOutputStream.**replaceObject.
> public interface SerializableList<E> extends Serializable, List<E> {
>  public static class Factory {
>   private Factory() {
>   }
>   public static <E> SerializableList<E> create(List<E> list) {
>    if (Serializable.class.**isInstance(list)) {
>     return createProxy(list);
>    } else {
>     return createProxy(new ArrayList<E>(list));
>    }
>   }
>   @SuppressWarnings("unchecked") private static <E> SerializableList<E>
> createProxy(List<E> list) {
>    return (SerializableList<E>) Proxy.newProxyInstance(**
> Factory.class.getClassLoader()**, new Class[] {Serializable.class,
> List.class, SerializableList.class}, new SerializableListProxy(list));
>   }
>  }
>  public static class SerializableListProxy implements InvocationHandler {
>   private final List<?> delegate;
>   public SerializableListProxy(List<?> delegate) {
>    this.delegate = delegate;
>   }
>   @Override public Object invoke(Object proxy, Method method, Object[]
> args) throws Throwable {
>    return method.invoke(this.delegate, args);
>   }
>  }
> }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20120725/706c866c/attachment-0001.html>

More information about the Concurrency-interest mailing list