From eb7352ab28b3f542c2408b38ac7835c33aba2a27 Mon Sep 17 00:00:00 2001 From: Steve Bohlen Date: Sat, 22 Dec 2012 14:11:02 -0500 Subject: [PATCH] SPRNET-1516 lock sync read-write of stateCache collection in ctor --- .../Reflection/Dynamic/DynamicMethod.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Spring/Spring.Core/Reflection/Dynamic/DynamicMethod.cs b/src/Spring/Spring.Core/Reflection/Dynamic/DynamicMethod.cs index 33e85267..6ae7f637 100644 --- a/src/Spring/Spring.Core/Reflection/Dynamic/DynamicMethod.cs +++ b/src/Spring/Spring.Core/Reflection/Dynamic/DynamicMethod.cs @@ -88,7 +88,7 @@ namespace Spring.Reflection.Dynamic private class IdentityTable : Hashtable { public IdentityTable() - {} + { } protected override int GetHash(object key) { @@ -118,14 +118,24 @@ namespace Spring.Reflection.Dynamic state = (SafeMethodState)stateCache[methodInfo]; if (state == null) { - state = new SafeMethodState(DynamicReflectionManager.CreateMethod(methodInfo), - new object[methodInfo.GetParameters().Length] + SafeMethodState newState = new SafeMethodState(DynamicReflectionManager.CreateMethod(methodInfo), + new object[methodInfo.GetParameters().Length] ); - stateCache[methodInfo] = state; + + lock (stateCache.SyncRoot) + { + if (stateCache[methodInfo] == null) + { + state = newState; + stateCache[methodInfo] = state; + } + } } + this.methodInfo = methodInfo; } + /// /// Invokes dynamic method. ///