[Biojava-dev] Serial confusion :)

Thomas Down td2@sanger.ac.uk
Wed, 23 Oct 2002 14:04:40 +0100


On Wed, Oct 23, 2002 at 01:50:03PM +0100, Keith James wrote:
> 
>     private RangeResolver resolver;
> 
> which is a reference to a non-serializable object. However, all
> supplied RangeResolvers are static and therefore don't get serialized.
> I've read up a bit on serialization, but can't find a definitive
> reference for what to expect in this situation.

This is very strange.  All I can think of is that the
FuzzyLocation$RangeResolvers don't actually have any
state fields (and thus have a very, very, simple serialized
form), and maybe this is short-circuiting the check that
the object implements Serializable.

Even stranger is the fact that your example fails.  Since
Foo implements FooI, which extends serializable, it really
OUGHT to work.  On the other hand, your Foo objects aren't
stateless, so it's not exactly analogous to the FuzzyLocation
case.

     Thomas (baffled, and off to do some testing...)

> class MyTest implements Serializable
> {
> 	public static final FooI FOO_A;
> 	public static final FooI FOO_B;
> 
> 	static
> 	{
> 		FOO_A = new Foo("a");
> 		FOO_B = new Foo("b");
> 	}
> 
> 	FooI my_foo;
> 
>     // Pass one of MyTest.FOO_A or MyTest.FOO_B
> 	MyTest(FooI foo)
> 	{
>         my_foo = foo;
> 	}
> 
> 	public static interface FooI extends Serializable { }
> 
> 	private static class Foo implements FooI
> 	{
> 		private String str;
> 
> 		Foo(String str)
> 		{
> 			this.str = str;
> 		}
> 
> 		public String toString()
> 		{
> 			return "Foo: " + str;
> 		}
> 	}
> }
> 
> I think MyTest/FooI are analagous to FuzzyLocation/RangeResolver, but
> MyTest is not serializable:
> 
> java.io.NotSerializableException: MyTest$Foo
> 
> So why can I serialize a FuzzyLocation?
> 
> cheers,
> 
> Keith