Junfeic / kryo

Automatically exported from code.google.com/p/kryo
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

GenericType not reset when collection size 0 #82

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
CollectionSerializer and MapSerializer use the fields "genericType" and 
"keyGenericType", "valueGenericType" respectively to lookup serializers. These 
fields are then reset back to null.

When the collection length is 0, it returns out of the write method immediately 
without ever resetting the genericType. This causes situations where the wrong 
serializer is fetched due to wrong genericType on subsequent calls to write. 
Here is some code that will reproduce the issue:

    public class NonFinalClass{

    }

    public class CollectionRoot{
        private List<String> aStringCollection;
        private List<NonFinalClass> nonFinalClasses;

        public CollectionRoot() {
            super();
            aStringCollection = new ArrayList<String>();
            nonFinalClasses = new ArrayList<CollectionSerializerTest.NonFinalClass>();
            nonFinalClasses.add(new NonFinalClass());
        }

    }

    public void test_generic_type_not_reset_with_empty_collection(){
        Kryo kryo = new Kryo();
        Output output  = new Output(100, 4096);
        kryo.writeClassAndObject(output, new CollectionRoot());
    }

Original issue reported on code.google.com by dtabu...@gmail.com on 8 Aug 2012 at 3:32

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r334.

Original comment by nathan.s...@gmail.com on 17 Aug 2012 at 6:07

GoogleCodeExporter commented 9 years ago
Thanks! Sorry for the delay.

Original comment by nathan.s...@gmail.com on 17 Aug 2012 at 6:08