Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for Portable Serialization incompatible class definition when nes…
…ted portables used Portable serialization is mistakenly reporting incompatible class-definitions when nested portables are used in certain scenarios. Details of failed scenario are as follows: Let's say, we have two Portables: `Parent` and `Child`. `Child` is a field of `Parent` class. Let's say we have two nodes. Node A and Node B. And both nodes are using a non-default both same portable version. - `Child` is serialized in Node B. This results with a class definition cached in Node B. - `Parent` is serialized in Node A and send to Node B. - When Node B is deserializing `Parent`, it reads the class definition of both `Parent` and `Child` from the wire. - In Node B, when reading the class definition of `Child`, the version of fields of `Child` class is read wrong. - We end up with the following exception when checking if the new class definition of `Child` is same as the cached one in Node B ``` Exception in thread "main" com.hazelcast.nio.serialization.HazelcastSerializationException: Incompatible class-definitions with same class-id: ClassDefinition{factoryId=1, classId=2, version=6, fieldDefinitions=[FieldDefinitionImpl{index=0, fieldName='name', type=UTF, classId=0, factoryId=0, version=0}]} VS ClassDefinition{factoryId=1, classId=2, version=6, fieldDefinitions=[FieldDefinitionImpl{index=0, fieldName='name', type=UTF, classId=0, factoryId=0, version=6}]} at com.hazelcast.internal.serialization.impl.PortableContextImpl$ClassDefinitionContext.register(PortableContextImpl.java:281) at com.hazelcast.internal.serialization.impl.PortableContextImpl.registerClassDefinition(PortableContextImpl.java:165) at com.hazelcast.internal.serialization.impl.PortableContextImpl.readClassDefinition(PortableContextImpl.java:158) at com.hazelcast.internal.serialization.impl.PortableContextImpl.readClassDefinition(PortableContextImpl.java:135) at com.hazelcast.internal.serialization.impl.PortableSerializer.setupPositionAndDefinition(PortableSerializer.java:156) at com.hazelcast.internal.serialization.impl.PortableSerializer.createReader(PortableSerializer.java:166) at com.hazelcast.internal.serialization.impl.PortableSerializer.read(PortableSerializer.java:90) at com.hazelcast.internal.serialization.impl.PortableSerializer.read(PortableSerializer.java:81) at com.hazelcast.internal.serialization.impl.PortableSerializer.read(PortableSerializer.java:34) at com.hazelcast.internal.serialization.impl.StreamSerializerAdapter.read(StreamSerializerAdapter.java:48) at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toObject(AbstractSerializationService.java:191) ``` This pr contains both fix and some cleanups. Fix is to use class version in fields when reading class definition from wire. In a couple places, fields are made private/final where applicable. fixes hazelcast#12733
- Loading branch information