Repository: ignite Updated Branches: refs/heads/ignite-5075-cacheStart f5a5fa020 -> f9aa769ad
IGNITE-5213 .NET: Fix collection handling in reflective serializer Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/9e3af25e Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/9e3af25e Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/9e3af25e Branch: refs/heads/ignite-5075-cacheStart Commit: 9e3af25e1220e84cdeca2c24adfe8a964b933e60 Parents: 330d9ef Author: Pavel Tupitsyn <[email protected]> Authored: Mon May 15 13:13:24 2017 +0300 Committer: Pavel Tupitsyn <[email protected]> Committed: Mon May 15 13:13:24 2017 +0300 ---------------------------------------------------------------------- .../Binary/BinarySelfTest.cs | 26 ++++++++++++++++++++ .../Impl/Binary/BinaryReflectiveActions.cs | 6 ++--- .../BinaryReflectiveSerializerInternal.cs | 9 ++++--- .../Impl/Binary/BinaryUtils.cs | 9 ------- .../Binary/DeserializationCallbackProcessor.cs | 11 +++++++++ .../Impl/Binary/SerializableSerializer.cs | 10 +++----- 6 files changed, 49 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/9e3af25e/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs index 01f108e..4a0827b 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs @@ -30,6 +30,7 @@ namespace Apache.Ignite.Core.Tests.Binary using System.IO; using System.Linq; using System.Reflection; + using System.Runtime.Serialization; using Apache.Ignite.Core.Binary; using Apache.Ignite.Core.Cache.Configuration; using Apache.Ignite.Core.Common; @@ -1128,6 +1129,13 @@ namespace Apache.Ignite.Core.Tests.Binary Assert.AreEqual(obj, marsh.Unmarshal<CollectionsType>(marsh.Marshal(obj))); obj.Col2 = new TestList(); + obj.Hashtable = new TestHashTable(); + + Assert.AreEqual(obj, marsh.Unmarshal<CollectionsType>(marsh.Marshal(obj))); + + // Test custom collections. + obj.Col3 = new TestList {1, "2"}; + obj.Hashtable2 = new TestHashTable {{1, "2"}}; Assert.AreEqual(obj, marsh.Unmarshal<CollectionsType>(marsh.Marshal(obj))); } @@ -1697,9 +1705,13 @@ namespace Apache.Ignite.Core.Tests.Binary public ICollection Col1 { get; set; } public ArrayList Col2 { get; set; } + + public TestList Col3 { get; set; } public Hashtable Hashtable { get; set; } + public TestHashTable Hashtable2 { get; set; } + public Dictionary<int, string> Dict { get; set; } public InnerObjectType[] Arr { get; set; } @@ -1767,7 +1779,21 @@ namespace Apache.Ignite.Core.Tests.Binary public class TestList : ArrayList { + // No-op. + } + + public class TestHashTable : Hashtable + { + public TestHashTable() + { + // No-op. + } + // ReSharper disable once UnusedMember.Global + protected TestHashTable(SerializationInfo info, StreamingContext context) : base(info, context) + { + // No-op. + } } private static bool CompareCollections(ICollection col1, ICollection col2) http://git-wip-us.apache.org/repos/asf/ignite/blob/9e3af25e/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReflectiveActions.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReflectiveActions.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReflectiveActions.cs index 6aaf5f9..bdcdd09 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReflectiveActions.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReflectiveActions.cs @@ -483,8 +483,7 @@ namespace Apache.Ignite.Core.Impl.Binary : GetWriter<object>(field, (f, w, o) => w.WriteEnum(f, o), true); readAction = raw ? GetRawReader(field, MthdReadEnumRaw) : GetReader(field, MthdReadEnum); } - else if (type == BinaryUtils.TypDictionary || - type.GetInterface(BinaryUtils.TypDictionary.FullName) != null && !type.IsGenericType) + else if (type == typeof(IDictionary) || type == typeof(Hashtable)) { writeAction = raw ? GetRawWriter<IDictionary>(field, (w, o) => w.WriteDictionary(o)) @@ -493,8 +492,7 @@ namespace Apache.Ignite.Core.Impl.Binary ? GetRawReader(field, r => r.ReadDictionary()) : GetReader(field, (f, r) => r.ReadDictionary(f)); } - else if (type == BinaryUtils.TypCollection || - type.GetInterface(BinaryUtils.TypCollection.FullName) != null && !type.IsGenericType) + else if (type == typeof(ICollection) || type == typeof(ArrayList)) { writeAction = raw ? GetRawWriter<ICollection>(field, (w, o) => w.WriteCollection(o)) http://git-wip-us.apache.org/repos/asf/ignite/blob/9e3af25e/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReflectiveSerializerInternal.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReflectiveSerializerInternal.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReflectiveSerializerInternal.cs index e160559..b179f92 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReflectiveSerializerInternal.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReflectiveSerializerInternal.cs @@ -106,11 +106,14 @@ namespace Apache.Ignite.Core.Impl.Binary action(obj, reader); _serializableDescriptor.OnDeserialized(obj, ctx); - + + DeserializationCallbackProcessor.Pop(); } - finally + catch (Exception) { - DeserializationCallbackProcessor.Pop(); + // Clear callbacks on exception to avoid dangling objects. + DeserializationCallbackProcessor.Clear(); + throw; } return (T) obj; http://git-wip-us.apache.org/repos/asf/ignite/blob/9e3af25e/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs index 5bc68fe..977251c 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs @@ -206,15 +206,6 @@ namespace Apache.Ignite.Core.Impl.Binary /** Indicates object array. */ public const int ObjTypeId = -1; - /** Int type. */ - public static readonly Type TypInt = typeof(int); - - /** Collection type. */ - public static readonly Type TypCollection = typeof(ICollection); - - /** Dictionary type. */ - public static readonly Type TypDictionary = typeof(IDictionary); - /** Ticks for Java epoch. */ private static readonly long JavaDateTicks = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).Ticks; http://git-wip-us.apache.org/repos/asf/ignite/blob/9e3af25e/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/DeserializationCallbackProcessor.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/DeserializationCallbackProcessor.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/DeserializationCallbackProcessor.cs index 3b21946..a2bb43f 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/DeserializationCallbackProcessor.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/DeserializationCallbackProcessor.cs @@ -78,6 +78,17 @@ namespace Apache.Ignite.Core.Impl.Binary } /// <summary> + /// Clears all registered objects. + /// </summary> + public static void Clear() + { + var graph = Graph.Value; + + graph.Objects.Clear(); + graph.Depth = 0; + } + + /// <summary> /// Object graph. /// </summary> private class ObjectGraph http://git-wip-us.apache.org/repos/asf/ignite/blob/9e3af25e/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/SerializableSerializer.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/SerializableSerializer.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/SerializableSerializer.cs index 6c7076a..1e4af4b 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/SerializableSerializer.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/SerializableSerializer.cs @@ -91,7 +91,6 @@ namespace Apache.Ignite.Core.Impl.Binary { object res; var ctx = GetStreamingContext(reader); - var callbackPushed = false; // Read additional information from raw part, if flag is set. IEnumerable<string> fieldNames; @@ -129,7 +128,6 @@ namespace Apache.Ignite.Core.Impl.Binary reader.AddHandle(pos, res); DeserializationCallbackProcessor.Push(res); - callbackPushed = true; } else { @@ -138,7 +136,6 @@ namespace Apache.Ignite.Core.Impl.Binary _serializableTypeDesc.OnDeserializing(res, ctx); DeserializationCallbackProcessor.Push(res); - callbackPushed = true; reader.AddHandle(pos, res); @@ -148,11 +145,12 @@ namespace Apache.Ignite.Core.Impl.Binary } _serializableTypeDesc.OnDeserialized(res, ctx); + DeserializationCallbackProcessor.Pop(); } - finally + catch (Exception) { - if (callbackPushed) - DeserializationCallbackProcessor.Pop(); + DeserializationCallbackProcessor.Clear(); + throw; } return (T) res;
