SPRNET-1334

clone dictionary before iterating through it to avoid iterator reentrancy
This commit is contained in:
sbohlen
2011-04-04 14:30:01 +00:00
parent 768f26559b
commit 6fd34b7664
2 changed files with 112 additions and 1 deletions

View File

@@ -446,11 +446,23 @@ namespace Spring.Objects.Factory.Support
/// </remarks>
public override void Dispose()
{
//TODO: fix the calls to GetObject(...) etc. so that they are invalid during container shutdown rather than attempting to resolve
// objects and permitting calling code to even get this far; considered too invasive a breaking change for 1.3.2; recommend impl
// of this change for the 2.0 release
base.Dispose();
foreach (object o in DisposableInnerObjects)
//have to clone the collection before iterating it to avoid arbitrary code in the objects' Dispose()
// that might permit re-entering the DisposableInnerObjects collections during the iteration to destroy them
// see https://jira.springframework.org/browse/SPRNET-1334
ISet clone = (ISet) DisposableInnerObjects.Clone();
foreach (object o in clone)
{
DestroyObject(string.Format(CultureInfo.InvariantCulture, "(Inner object of Type '{0}')", o.GetType().FullName), o);
}
DisposableInnerObjects.Clear();
}