From 1347e7f31217d0b19640547674b74b499d5f10c9 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Sun, 1 Jun 2014 13:06:50 +0200 Subject: [PATCH] [#2523] Fix infinite-loop when remove attribute and create the same attribute again Motivation: The current DefaultAttributeMap cause an infinite-loop when the user removes an attribute and create the same attribute again. This regression was introduced by c3bd7a8ff10021026b0c223d36f022dbbf4fe397. Modification: Correctly break out loop Result: No infinite-loop anymore. --- .../main/java/io/netty/util/DefaultAttributeMap.java | 3 +++ .../java/io/netty/util/DefaultAttributeMapTest.java | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/common/src/main/java/io/netty/util/DefaultAttributeMap.java b/common/src/main/java/io/netty/util/DefaultAttributeMap.java index a2ec5ea57e..ebdbe105ae 100644 --- a/common/src/main/java/io/netty/util/DefaultAttributeMap.java +++ b/common/src/main/java/io/netty/util/DefaultAttributeMap.java @@ -90,6 +90,9 @@ public class DefaultAttributeMap implements AttributeMap { DefaultAttribute attr = new DefaultAttribute(head, key); curr.next = attr; attr.prev = curr; + return attr; + } else { + curr = next; } } } diff --git a/common/src/test/java/io/netty/util/DefaultAttributeMapTest.java b/common/src/test/java/io/netty/util/DefaultAttributeMapTest.java index 7fe574ce57..ce49bfbc42 100644 --- a/common/src/test/java/io/netty/util/DefaultAttributeMapTest.java +++ b/common/src/test/java/io/netty/util/DefaultAttributeMapTest.java @@ -67,4 +67,16 @@ public class DefaultAttributeMapTest { one.remove(); assertNull(one.get()); } + + // See https://github.com/netty/netty/issues/2523 + @Test + public void testSetRemove() { + AttributeKey key = AttributeKey.valueOf("key"); + + map.attr(key).set(1); + assertSame(1, map.attr(key).getAndRemove()); + + map.attr(key).set(2); + assertSame(2, map.attr(key).get()); + } }