diff --git a/src/DotNetty.Common/Utilities/AttributeKey.cs b/src/DotNetty.Common/Utilities/AttributeKey.cs index 202f07935..4e06cf7a2 100644 --- a/src/DotNetty.Common/Utilities/AttributeKey.cs +++ b/src/DotNetty.Common/Utilities/AttributeKey.cs @@ -5,6 +5,18 @@ namespace DotNetty.Common.Utilities { using System; + internal static class AttributeKey + { + // Keep the instance of AttributeConstantPool out of generic classes, to make it an really singleton for different generic types. + // see https://github.com/Azure/DotNetty/issues/498 + public static readonly ConstantPool Pool = new AttributeConstantPool(); + + sealed class AttributeConstantPool : ConstantPool + { + protected override IConstant NewConstant(int id, string name) => new AttributeKey(id, name); + }; + } + /// /// Key which can be used to access out of the . Be aware that /// it is not be possible to have multiple keys with the same name. @@ -14,12 +26,7 @@ namespace DotNetty.Common.Utilities /// public sealed class AttributeKey : AbstractConstant> { - public static readonly ConstantPool Pool = new AttributeConstantPool(); - - sealed class AttributeConstantPool : ConstantPool - { - protected override IConstant NewConstant(int id, string name) => new AttributeKey(id, name); - }; + public static readonly ConstantPool Pool = AttributeKey.Pool; /// Returns the singleton instance of the {@link AttributeKey} which has the specified name. public static AttributeKey ValueOf(string name) => (AttributeKey)Pool.ValueOf(name);