You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2020/12/02 19:21:48 UTC

[GitHub] [geode-native] echobravopapa commented on a change in pull request #704: GEODE-8754: Fix uninitialized variable in DataInput::ReadInternalObject

echobravopapa commented on a change in pull request #704:
URL: https://github.com/apache/geode-native/pull/704#discussion_r534420160



##########
File path: tests/javaobject/cli/TestClassC.java
##########
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package javaobject.cli;
+
+import java.util.*;
+import java.io.*;
+import org.apache.geode.*;
+import org.apache.geode.cache.Declarable;
+
+public class TestClassC implements Declarable, Serializable, DataSerializable {
+  private String Color;
+  private String Make;
+  private int Year;
+
+  static {
+     Instantiator.register(new Instantiator(javaobject.cli.TestClassC.class, (byte) 102) {
+     public DataSerializable newInstance() {
+        return new TestClassC();
+     }
+   });
+  }
+
+
+
+/*

Review comment:
       dead code, pls remove

##########
File path: clicache/src/DataInput.cpp
##########
@@ -657,7 +657,7 @@ namespace Apache
           //Log::Debug("DataInput::ReadInternalObject m_cursor " + m_cursor);
           bool findinternal = false;
           int8_t typeId = ReadByte();
-          System::Int64 compId;
+          System::Int64 compId = 0;

Review comment:
       RAII FTW?!?

##########
File path: clicache/integration-test2/SerializationTests.cs
##########
@@ -25,7 +26,335 @@
 
 namespace Apache.Geode.Client.IntegrationTests
 {
-    public class Order : IDataSerializable
+	public class TestClassA : IDataSerializable
+	{
+		public int Id { get; set; }
+		public string Name { get; set; }
+		public short NumSides { get; set; }
+
+		// A default constructor is required for deserialization
+		public TestClassA() { }
+
+		public TestClassA(int id, string name, short numSides)
+		{
+			Id = id;
+			Name = name;
+			NumSides = numSides;
+		}
+
+		public override string ToString()
+		{
+			return string.Format("TestClassA: [{0}, {1}, {2}]", Id, Name, NumSides);
+		}
+
+		public void ToData(DataOutput output)
+		{
+			output.WriteInt32(Id);
+			output.WriteUTF(Name);
+			output.WriteInt16(NumSides);
+		}
+
+		public void FromData(DataInput input)
+		{
+			Id = input.ReadInt32();
+			Name = input.ReadUTF();
+			NumSides = input.ReadInt16();
+		}
+
+		public ulong ObjectSize
+		{
+			get { return 0; }
+		}
+
+		public static ISerializable CreateDeserializable()
+		{
+			return new TestClassA();
+		}
+
+		public override bool Equals(object obj)
+		{
+			if (obj == null)
+				return false;
+			if (obj == this)
+				return true;
+
+			var other = obj as TestClassA;
+
+			if (Id == other.Id &&
+				Name == other.Name &&
+				NumSides == other.NumSides)
+				return true;
+			else
+				return false;
+		}
+
+		public override int GetHashCode()
+		{
+			return base.GetHashCode();
+		}
+	}
+
+	public class TestClassB : IDataSerializable
+	{
+		public int Width { get; set; }
+		public int Height { get; set; }
+		public string Name { get; set; }
+
+		// A default constructor is required for deserialization
+		public TestClassB() { }
+
+		public TestClassB(int width, int height, string name)
+		{
+			Width = width;
+			Height = height;
+			Name = name;
+		}
+
+		public override string ToString()
+		{
+			return string.Format("TestClassB: [{0}, {1}, {2}]", Width, Height, Name);
+		}
+
+		public void ToData(DataOutput output)
+		{
+			output.WriteInt32(Width);
+			output.WriteInt32(Height);
+			output.WriteUTF(Name);
+		}
+
+		public void FromData(DataInput input)
+		{
+			Width = input.ReadInt32();
+			Height = input.ReadInt32();
+			Name = input.ReadUTF();
+		}
+
+		public ulong ObjectSize
+		{
+			get { return 0; }
+		}
+
+		public static ISerializable CreateDeserializable()
+		{
+			return new TestClassB();
+		}
+
+		public override bool Equals(object obj)
+		{
+			if (obj == null)
+				return false;
+			if (obj == this)
+				return true;
+
+			var other = obj as TestClassB;
+
+			if (Width == other.Width &&
+				Name == other.Name &&
+				Height == other.Height)
+				return true;
+			else
+				return false;
+		}
+
+		public override int GetHashCode()
+		{
+			return base.GetHashCode();
+		}
+	}
+
+	public class TestClassC : IDataSerializable
+	{
+		public string Color { get; set; }
+		public string Make { get; set; }
+		public int Year { get; set; }
+
+		// A default constructor is required for deserialization
+		public TestClassC() { }
+
+		public TestClassC(string color, string make, int year)
+		{
+			Color = color;
+			Make = make;
+			Year = year;
+		}
+
+		public override string ToString()
+		{
+			return string.Format("TestClassC: [{0}, {1}, {2}]", Color, Make, Year);
+		}
+
+		public void ToData(DataOutput output)
+		{
+			output.WriteUTF(Color);
+			output.WriteUTF(Make);
+			output.WriteInt32(Year);
+		}
+
+		public void FromData(DataInput input)
+		{
+			Color = input.ReadUTF();
+			Make = input.ReadUTF();
+			Year = input.ReadInt32();
+		}
+
+		public ulong ObjectSize
+		{
+			get { return 0; }
+		}
+
+		public static ISerializable CreateDeserializable()
+		{
+			return new TestClassC();
+		}
+
+		public override bool Equals(object obj)
+		{
+			if (obj == null)
+				return false;
+			if (obj == this)
+				return true;
+
+			var other = obj as TestClassC;
+
+			if (Color == other.Color &&
+				Make == other.Make &&
+				Year == other.Year)
+				return true;
+			else
+				return false;
+		}
+
+		public override int GetHashCode()
+		{
+			return base.GetHashCode();
+		}
+	}
+
+	public class CompositeClass : IDataSerializable
+    {
+        private TestClassA testclassA;
+		private List<TestClassB> testclassBs;
+		private List<TestClassC> testclassCs;
+
+		public CompositeClass()
+		{
+			testclassA = new TestClassA();
+			testclassBs = new List<TestClassB>();
+			testclassCs = new List<TestClassC>();
+		}
+
+		public TestClassA A
+		{
+			get
+			{
+				return testclassA;
+			}
+			set
+			{
+				testclassA = value;
+			}
+		}
+
+		public List<TestClassB> Bs
+		{
+			get
+			{
+				return testclassBs;
+			}
+			set
+			{
+				testclassBs = value;
+			}
+		}
+
+		public List<TestClassC> Cs
+		{
+			get
+			{
+				return testclassCs;
+			}
+			set
+			{
+				testclassCs = value;
+			}
+		}
+
+		public void ToData(DataOutput output)
+		{
+			testclassA.ToData(output);
+			output.WriteObject(testclassBs);
+			output.WriteObject(testclassCs);
+		}
+
+		//private unsafe void fillstack(Int64[] val)
+		//{
+  //          return;
+		//}
+		public void FromData(DataInput input)
+		{
+			testclassA.FromData(input);
+
+			// Fill the stack with Order typeid: 66

Review comment:
       dead code?

##########
File path: clicache/integration-test2/SerializationTests.cs
##########
@@ -510,5 +823,119 @@ public void PutGetCustomSerializableTypes()
                 cache.Close();
             }
         }
-    }
-}
+
+		[Fact]
+		public void CompositeClassWithClassAsKey()

Review comment:
       Good addition.   Does a non-composite class used as a key exercise the same code paths?  if not, be great to add a test for that too...




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org