From d530f044ba7bfacd28405c8cbbac338c591360ba Mon Sep 17 00:00:00 2001 From: Greg Jarzab Date: Mon, 12 Apr 2021 22:15:09 -0500 Subject: [PATCH 1/3] Add test to demonstrate failure when more than 124 arguments are passed to a MethodNode. --- .../Expressions/ExpressionEvaluatorTests.cs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/Spring/Spring.Core.Tests/Expressions/ExpressionEvaluatorTests.cs b/test/Spring/Spring.Core.Tests/Expressions/ExpressionEvaluatorTests.cs index baa489053..92ec44d85 100644 --- a/test/Spring/Spring.Core.Tests/Expressions/ExpressionEvaluatorTests.cs +++ b/test/Spring/Spring.Core.Tests/Expressions/ExpressionEvaluatorTests.cs @@ -27,6 +27,7 @@ using System.EnterpriseServices; using System.Globalization; using System.IO; +using System.Linq; using System.Reflection; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; @@ -2218,6 +2219,26 @@ public void TestMethodResolutionResolvesToExactMatchOfArgumentTypes() Assert.AreEqual("ExactMatch", ExpressionEvaluator.GetValue(foo, "MethodWithSimilarArguments(1, #bars)", args)); } + + /// + /// Test to show that a large number of parameters can be passed to methods + /// + [Test] + public void TestMethodResolutionWithLargeNumberOfParametersDoesNotThrow() + { + int expectedResult = 150; + int result = 0; + + Foo foo = new Foo(); + string expression = $"MethodWithParamArray({String.Join(", ", Enumerable.Range(0, expectedResult))})"; + + Assert.DoesNotThrow(() => + { + result = (int)ExpressionEvaluator.GetValue(foo, expression); + }); + + Assert.AreEqual(expectedResult, result); + } [Test] public void TestIndexerResolutionResolvesToExactMatchOfArgumentTypes() @@ -3057,6 +3078,11 @@ public string MethodWithParamArray(bool uppercase, params string[] values) string ret = string.Join("|", values); return (uppercase ? ret.ToUpper() : ret); } + + public int MethodWithParamArray(params int[] values) + { + return values.Length; + } } internal enum FooType From 3fde983d4b44fe0e70c4394f3925d2fbd9f9582b Mon Sep 17 00:00:00 2001 From: Greg Jarzab Date: Mon, 12 Apr 2021 22:17:11 -0500 Subject: [PATCH 2/3] Calculate method hash using HashCode instead of a using a fixed number of primes. --- .../Spring.Core/Expressions/MethodNode.cs | 31 ++++++------------- src/Spring/Spring.Core/Spring.Core.csproj | 1 + 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/src/Spring/Spring.Core/Expressions/MethodNode.cs b/src/Spring/Spring.Core/Expressions/MethodNode.cs index 079b71d65..2d275dfae 100644 --- a/src/Spring/Spring.Core/Expressions/MethodNode.cs +++ b/src/Spring/Spring.Core/Expressions/MethodNode.cs @@ -1,7 +1,7 @@ #region License /* - * Copyright © 2002-2011 the original author or authors. + * Copyright � 2002-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -170,14 +170,19 @@ protected override object Get(object context, EvaluationContext evalContext) private int CalculateMethodHash(Type contextType, object[] argValues) { - int hash = contextType.GetHashCode(); + HashCode hash = new HashCode(); + hash.Add(contextType.GetHashCode()); + for (int i = 0; i < argValues.Length; i++) { object arg = argValues[i]; if (arg != null) - hash += s_primes[i] * arg.GetType().GetHashCode(); + { + hash.Add(arg.GetType().GetHashCode()); + } } - return hash; + + return hash.ToHashCode(); } private void Initialize(string methodName, object[] argValues, object context) @@ -272,23 +277,5 @@ private static IList GetCandidateMethods(Type type, string methodNam return matches; } - - // used to calculate signature hash while caring for arg positions - private static readonly int[] s_primes = - { - 17, 19, 23, 29 - , 31, 37, 41, 43, 47, 53, 59, 61, 67, 71 - , 73, 79, 83, 89, 97, 101, 103, 107, 109, 113 - , 127, 131, 137, 139, 149, 151, 157, 163, 167, 173 - , 179, 181, 191, 193, 197, 199, 211, 223, 227, 229 - , 233, 239, 241, 251, 257, 263, 269, 271, 277, 281 - , 283, 293, 307, 311, 313, 317, 331, 337, 347, 349 - , 353, 359, 367, 373, 379, 383, 389, 397, 401, 409 - , 419, 421, 431, 433, 439, 443, 449, 457, 461, 463 - , 467, 479, 487, 491, 499, 503, 509, 521, 523, 541 - , 547, 557, 563, 569, 571, 577, 587, 593, 599, 601 - , 607, 613, 617, 619, 631, 641, 643, 647, 653, 659 - , 661, 673, 677, 683, 691, 701, 709, 719, 727, 733 - }; } } diff --git a/src/Spring/Spring.Core/Spring.Core.csproj b/src/Spring/Spring.Core/Spring.Core.csproj index 70dceef0f..c241d3896 100644 --- a/src/Spring/Spring.Core/Spring.Core.csproj +++ b/src/Spring/Spring.Core/Spring.Core.csproj @@ -21,6 +21,7 @@ + From 0def05f8bc0717e2cd953df06964a9005b349da6 Mon Sep 17 00:00:00 2001 From: Greg Jarzab Date: Mon, 12 Apr 2021 22:42:29 -0500 Subject: [PATCH 3/3] Add BOM and fix Copyright Sign --- src/Spring/Spring.Core/Expressions/MethodNode.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Spring/Spring.Core/Expressions/MethodNode.cs b/src/Spring/Spring.Core/Expressions/MethodNode.cs index 2d275dfae..5bdb26b7d 100644 --- a/src/Spring/Spring.Core/Expressions/MethodNode.cs +++ b/src/Spring/Spring.Core/Expressions/MethodNode.cs @@ -1,7 +1,7 @@ -#region License +#region License /* - * Copyright � 2002-2011 the original author or authors. + * Copyright © 2002-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.