You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by mg...@apache.org on 2022/02/01 11:18:03 UTC

[avro] branch branch-1.11 updated: AVRO-3335 Evaluate input of GenerateNames (#1485)

This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a commit to branch branch-1.11
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/branch-1.11 by this push:
     new e679b1b  AVRO-3335 Evaluate input of GenerateNames (#1485)
e679b1b is described below

commit e679b1b05f5a212896b325e20ee786c35a7a4cd6
Author: Kyle Schoonover <ky...@minmaxcorp.com>
AuthorDate: Tue Feb 1 03:17:21 2022 -0800

    AVRO-3335 Evaluate input of GenerateNames (#1485)
    
    * AVRO-3335 Evaluate input of GenerateNames
    
    * Updated to include obsolete method calls.
    
    Co-authored-by: Kyle T. Schoonover <Ky...@nordstrom.com>
    (cherry picked from commit 9c2464ca2b76b914e3563e2b101752b59ebaf6ed)
---
 lang/csharp/src/apache/main/CodeGen/CodeGen.cs    | 37 +++++++++++++++++++++--
 lang/csharp/src/apache/test/CodGen/CodeGenTest.cs | 10 ++++++
 2 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/lang/csharp/src/apache/main/CodeGen/CodeGen.cs b/lang/csharp/src/apache/main/CodeGen/CodeGen.cs
index 042ea4f..88857e1 100644
--- a/lang/csharp/src/apache/main/CodeGen/CodeGen.cs
+++ b/lang/csharp/src/apache/main/CodeGen/CodeGen.cs
@@ -171,7 +171,7 @@ namespace Avro
         {
             foreach (Schema schema in this.Schemas)
             {
-                SchemaNames names = generateNames(schema);
+                SchemaNames names = GenerateNames(schema);
                 foreach (KeyValuePair<SchemaName, NamedSchema> sn in names)
                 {
                     switch (sn.Value.Tag)
@@ -194,7 +194,7 @@ namespace Avro
         {
             foreach (Protocol protocol in Protocols)
             {
-                SchemaNames names = generateNames(protocol);
+                SchemaNames names = GenerateNames(protocol);
                 foreach (KeyValuePair<SchemaName, NamedSchema> sn in names)
                 {
                     switch (sn.Value.Tag)
@@ -219,8 +219,28 @@ namespace Avro
         /// <returns>
         /// List of named schemas.
         /// </returns>
+        /// <exception cref="System.ArgumentNullException">protocol - Protocol can not be null.</exception>
+        [Obsolete("Use GenerateNames. This call will be deprecated in a future release.")]
         protected virtual SchemaNames generateNames(Protocol protocol)
         {
+            return GenerateNames(protocol);
+        }
+
+        /// <summary>
+        /// Generate list of named schemas from given protocol.
+        /// </summary>
+        /// <param name="protocol">protocol to process.</param>
+        /// <returns>
+        /// List of named schemas.
+        /// </returns>
+        /// <exception cref="System.ArgumentNullException">protocol - Protocol can not be null.</exception>
+        protected virtual SchemaNames GenerateNames(Protocol protocol)
+        {
+            if (protocol == null)
+            {
+                throw new ArgumentNullException(nameof(protocol), "Protocol can not be null");
+            }
+
             var names = new SchemaNames();
             foreach (Schema schema in protocol.Types)
             {
@@ -237,8 +257,21 @@ namespace Avro
         /// <returns>
         /// List of named schemas.
         /// </returns>
+        [Obsolete("Use GenerateNames.  This call will be deprecated in a future release.")]
         protected virtual SchemaNames generateNames(Schema schema)
         {
+            return GenerateNames(schema);
+        }
+
+        /// <summary>
+        /// Generate list of named schemas from given schema.
+        /// </summary>
+        /// <param name="schema">schema to process.</param>
+        /// <returns>
+        /// List of named schemas.
+        /// </returns>
+        protected virtual SchemaNames GenerateNames(Schema schema)
+        {
             var names = new SchemaNames();
             addName(schema, names);
             return names;
diff --git a/lang/csharp/src/apache/test/CodGen/CodeGenTest.cs b/lang/csharp/src/apache/test/CodGen/CodeGenTest.cs
index 86ca317..ea46c6b 100644
--- a/lang/csharp/src/apache/test/CodGen/CodeGenTest.cs
+++ b/lang/csharp/src/apache/test/CodGen/CodeGenTest.cs
@@ -196,5 +196,15 @@ namespace Avro.Test
             return compres;
         }
 #endif
+        [TestFixture]
+        public class CodeGenTestClass : CodeGen
+        {
+            [Test]
+            public void TestGenerateNamesException()
+            {
+                Protocol protocol = null;
+                Assert.Throws<ArgumentNullException>(() => this.GenerateNames(protocol));
+            }
+        }
     }
 }