You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by GitBox <gi...@apache.org> on 2022/12/16 05:43:23 UTC

[GitHub] [avro] github-code-scanning[bot] commented on a diff in pull request #2017: AVRO-3685 Fix class cache load type

github-code-scanning[bot] commented on code in PR #2017:
URL: https://github.com/apache/avro/pull/2017#discussion_r1050390009


##########
lang/csharp/src/apache/main/Reflect/ClassCache.cs:
##########
@@ -300,5 +294,25 @@
                     break;
             }
         }
+
+        /// <summary>
+        /// If schema have to be loaded to cache
+        /// </summary>
+        /// <param name="schema"></param>
+        /// <returns></returns>
+        protected virtual bool IsLoadToCache(Schema schema)
+        {
+            switch (schema)
+            {
+                case RecordSchema rs:
+                case ArraySchema ars:
+                case MapSchema ms:

Review Comment:
   ## Useless assignment to local variable
   
   This assignment to [ms](1) is useless, since its value is never read.
   
   [Show more details](https://github.com/apache/avro/security/code-scanning/2954)



##########
lang/csharp/src/apache/main/Reflect/ClassCache.cs:
##########
@@ -300,5 +294,25 @@
                     break;
             }
         }
+
+        /// <summary>
+        /// If schema have to be loaded to cache
+        /// </summary>
+        /// <param name="schema"></param>
+        /// <returns></returns>
+        protected virtual bool IsLoadToCache(Schema schema)
+        {
+            switch (schema)
+            {
+                case RecordSchema rs:

Review Comment:
   ## Useless assignment to local variable
   
   This assignment to [rs](1) is useless, since its value is never read.
   
   [Show more details](https://github.com/apache/avro/security/code-scanning/2952)



##########
lang/csharp/src/apache/main/Reflect/ClassCache.cs:
##########
@@ -300,5 +294,25 @@
                     break;
             }
         }
+
+        /// <summary>
+        /// If schema have to be loaded to cache
+        /// </summary>
+        /// <param name="schema"></param>
+        /// <returns></returns>
+        protected virtual bool IsLoadToCache(Schema schema)
+        {
+            switch (schema)
+            {
+                case RecordSchema rs:
+                case ArraySchema ars:

Review Comment:
   ## Useless assignment to local variable
   
   This assignment to [ars](1) is useless, since its value is never read.
   
   [Show more details](https://github.com/apache/avro/security/code-scanning/2953)



##########
lang/csharp/src/apache/main/Reflect/ClassCache.cs:
##########
@@ -300,5 +294,25 @@
                     break;
             }
         }
+
+        /// <summary>
+        /// If schema have to be loaded to cache
+        /// </summary>
+        /// <param name="schema"></param>
+        /// <returns></returns>
+        protected virtual bool IsLoadToCache(Schema schema)
+        {
+            switch (schema)
+            {
+                case RecordSchema rs:
+                case ArraySchema ars:
+                case MapSchema ms:
+                case NamedSchema ns:

Review Comment:
   ## Useless assignment to local variable
   
   This assignment to [ns](1) is useless, since its value is never read.
   
   [Show more details](https://github.com/apache/avro/security/code-scanning/2955)



##########
lang/csharp/src/apache/test/Reflect/ClassCacheTests/LoadClassCacheTests.cs:
##########
@@ -0,0 +1,142 @@
+/**
+ * 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
+ *
+ *     https://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.
+ */
+
+using Avro.Reflect;
+using NUnit.Framework;
+
+namespace Avro.test.Reflect.ClassCacheTests
+{
+    public class LoadClassCacheTests
+    {
+        [TestCase]
+        public void WhenLoadTypeWithComplexTypeProperty_LoadTypeAndPropertyType()
+        {
+            //Arrange
+            var classCache = new ClassCache();
+
+            //Act
+            classCache.LoadClassCache(typeof(TestClass1), TestClass1.RootSchema);
+            var type = classCache.GetClass(TestClass1.RootSchema);
+            var propertyType = classCache.GetClass(TestClass1.ComplexTypeSchema);
+
+            //Assert
+            Assert.NotNull(type);
+            Assert.AreEqual(typeof(TestClass1), type.GetClassType());
+            Assert.NotNull(propertyType);
+            Assert.AreEqual(typeof(ComplexType1), propertyType.GetClassType());
+        }
+
+        [TestCase]
+        public void WhenLoadTwoTypesWithSameNameButDifferentComplexTypeProperties_LoadFourTypes()
+        {
+            //Arrange
+            var classCache = new ClassCache();
+
+            //Act
+            classCache.LoadClassCache(typeof(TestClass1), TestClass1.RootSchema);
+            var type1 = classCache.GetClass(TestClass1.RootSchema);
+            var propertyType1 = classCache.GetClass(TestClass1.ComplexTypeSchema);
+            classCache.LoadClassCache(typeof(TestClass2), TestClass2.RootSchema);
+            var type2 = classCache.GetClass(TestClass2.RootSchema);
+            var propertyType2 = classCache.GetClass(TestClass2.ComplexTypeSchema);
+
+            //Assert
+            Assert.NotNull(type1);
+            Assert.AreEqual(typeof(TestClass1), type1.GetClassType());
+            Assert.NotNull(propertyType1);
+            Assert.AreEqual(typeof(ComplexType1), propertyType1.GetClassType());
+            Assert.NotNull(type2);
+            Assert.AreEqual(typeof(TestClass2), type2.GetClassType());
+            Assert.NotNull(propertyType2);
+            Assert.AreEqual(typeof(ComplexType2), propertyType2.GetClassType());
+        }
+    }
+
+    public class TestClass1
+    {
+        public static RecordSchema RootSchema = (RecordSchema)Schema.Parse(@"
+{
+    ""type"" : ""record"",
+    ""name"" : ""TestClass1"",
+    ""namespace"" : ""Avro.test.Reflect.ClassCacheTests"",
+    ""fields"" :
+        [
+            {
+                ""name"" : ""ComplexType"",
+                ""type"" :
+                    {
+                        ""type"" : ""record"",
+                        ""name"" : ""ComplexType1"",
+                        ""fields"" :
+                            [
+                                {
+                                    ""name"" : ""IntProperty"",
+                                    ""type"" :""int""
+                                }
+                            ]
+                    }
+            }
+        ]
+}
+");
+        public static RecordSchema ComplexTypeSchema = (RecordSchema)((RecordSchema)RootSchema).Fields[0].Schema;
+
+        public ComplexType1 ComplexType { get; set; }
+    }
+
+    public class TestClass2
+    {
+        public static RecordSchema RootSchema = (RecordSchema)Schema.Parse(@"
+{
+    ""type"" : ""record"",
+    ""name"" : ""TestClass2"",
+    ""namespace"" : ""Avro.test.Reflect.ClassCacheTests"",
+    ""fields"" :
+        [
+            {
+                ""name"" : ""ComplexType"",
+                ""type"" :
+                    {
+                        ""type"" : ""record"",
+                        ""name"" : ""ComplexType2"",
+                        ""fields"" :
+                            [
+                                {
+                                    ""name"" : ""StringProperty"",
+                                    ""type"" : ""string""
+                                }
+                            ]
+                    }
+            }
+        ]
+}
+");
+        public static RecordSchema ComplexTypeSchema = (RecordSchema)((RecordSchema)RootSchema).Fields[0].Schema;

Review Comment:
   ## Cast to same type
   
   This cast is redundant because the expression already has type RecordSchema.
   
   [Show more details](https://github.com/apache/avro/security/code-scanning/2959)



##########
lang/csharp/src/apache/main/Reflect/ClassCache.cs:
##########
@@ -300,5 +294,25 @@
                     break;
             }
         }
+
+        /// <summary>
+        /// If schema have to be loaded to cache
+        /// </summary>
+        /// <param name="schema"></param>
+        /// <returns></returns>
+        protected virtual bool IsLoadToCache(Schema schema)
+        {
+            switch (schema)
+            {
+                case RecordSchema rs:
+                case ArraySchema ars:
+                case MapSchema ms:
+                case NamedSchema ns:
+                case UnionSchema us:

Review Comment:
   ## Useless assignment to local variable
   
   This assignment to [us](1) is useless, since its value is never read.
   
   [Show more details](https://github.com/apache/avro/security/code-scanning/2956)



##########
lang/csharp/src/apache/test/Reflect/ClassCacheTests/LoadClassCacheTests.cs:
##########
@@ -0,0 +1,142 @@
+/**
+ * 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
+ *
+ *     https://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.
+ */
+
+using Avro.Reflect;
+using NUnit.Framework;
+
+namespace Avro.test.Reflect.ClassCacheTests
+{
+    public class LoadClassCacheTests
+    {
+        [TestCase]
+        public void WhenLoadTypeWithComplexTypeProperty_LoadTypeAndPropertyType()
+        {
+            //Arrange
+            var classCache = new ClassCache();
+
+            //Act
+            classCache.LoadClassCache(typeof(TestClass1), TestClass1.RootSchema);
+            var type = classCache.GetClass(TestClass1.RootSchema);
+            var propertyType = classCache.GetClass(TestClass1.ComplexTypeSchema);
+
+            //Assert
+            Assert.NotNull(type);
+            Assert.AreEqual(typeof(TestClass1), type.GetClassType());
+            Assert.NotNull(propertyType);
+            Assert.AreEqual(typeof(ComplexType1), propertyType.GetClassType());
+        }
+
+        [TestCase]
+        public void WhenLoadTwoTypesWithSameNameButDifferentComplexTypeProperties_LoadFourTypes()
+        {
+            //Arrange
+            var classCache = new ClassCache();
+
+            //Act
+            classCache.LoadClassCache(typeof(TestClass1), TestClass1.RootSchema);
+            var type1 = classCache.GetClass(TestClass1.RootSchema);
+            var propertyType1 = classCache.GetClass(TestClass1.ComplexTypeSchema);
+            classCache.LoadClassCache(typeof(TestClass2), TestClass2.RootSchema);
+            var type2 = classCache.GetClass(TestClass2.RootSchema);
+            var propertyType2 = classCache.GetClass(TestClass2.ComplexTypeSchema);
+
+            //Assert
+            Assert.NotNull(type1);
+            Assert.AreEqual(typeof(TestClass1), type1.GetClassType());
+            Assert.NotNull(propertyType1);
+            Assert.AreEqual(typeof(ComplexType1), propertyType1.GetClassType());
+            Assert.NotNull(type2);
+            Assert.AreEqual(typeof(TestClass2), type2.GetClassType());
+            Assert.NotNull(propertyType2);
+            Assert.AreEqual(typeof(ComplexType2), propertyType2.GetClassType());
+        }
+    }
+
+    public class TestClass1
+    {
+        public static RecordSchema RootSchema = (RecordSchema)Schema.Parse(@"
+{
+    ""type"" : ""record"",
+    ""name"" : ""TestClass1"",
+    ""namespace"" : ""Avro.test.Reflect.ClassCacheTests"",
+    ""fields"" :
+        [
+            {
+                ""name"" : ""ComplexType"",
+                ""type"" :
+                    {
+                        ""type"" : ""record"",
+                        ""name"" : ""ComplexType1"",
+                        ""fields"" :
+                            [
+                                {
+                                    ""name"" : ""IntProperty"",
+                                    ""type"" :""int""
+                                }
+                            ]
+                    }
+            }
+        ]
+}
+");
+        public static RecordSchema ComplexTypeSchema = (RecordSchema)((RecordSchema)RootSchema).Fields[0].Schema;

Review Comment:
   ## Cast to same type
   
   This cast is redundant because the expression already has type RecordSchema.
   
   [Show more details](https://github.com/apache/avro/security/code-scanning/2958)



-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

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