Skip to content

Commit c011350

Browse files
yyjdeletenayato
authored andcommitted
Fix #498 (#507)
1 parent 780acdb commit c011350

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/DotNetty.Common/Utilities/AttributeKey.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ namespace DotNetty.Common.Utilities
55
{
66
using System;
77

8+
internal static class AttributeKey
9+
{
10+
// Keep the instance of AttributeConstantPool out of generic classes, to make it an really singleton for different generic types.
11+
// see https://github.com/Azure/DotNetty/issues/498
12+
public static readonly ConstantPool Pool = new AttributeConstantPool();
13+
14+
sealed class AttributeConstantPool : ConstantPool
15+
{
16+
protected override IConstant NewConstant<TValue>(int id, string name) => new AttributeKey<TValue>(id, name);
17+
};
18+
}
19+
820
/// <summary>
921
/// Key which can be used to access <seealso cref="Attribute" /> out of the <see cref="IAttributeMap" />. Be aware that
1022
/// it is not be possible to have multiple keys with the same name.
@@ -14,12 +26,7 @@ namespace DotNetty.Common.Utilities
1426
/// </typeparam>
1527
public sealed class AttributeKey<T> : AbstractConstant<AttributeKey<T>>
1628
{
17-
public static readonly ConstantPool Pool = new AttributeConstantPool();
18-
19-
sealed class AttributeConstantPool : ConstantPool
20-
{
21-
protected override IConstant NewConstant<TValue>(int id, string name) => new AttributeKey<TValue>(id, name);
22-
};
29+
public static readonly ConstantPool Pool = AttributeKey.Pool;
2330

2431
/// <summary>Returns the singleton instance of the {@link AttributeKey} which has the specified <c>name</c>.</summary>
2532
public static AttributeKey<T> ValueOf(string name) => (AttributeKey<T>)Pool.ValueOf<T>(name);

0 commit comments

Comments
 (0)