[#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 c3bd7a8ff1.

Modification:
Correctly break out loop

Result:
No infinite-loop anymore.
This commit is contained in:
Norman Maurer 2014-06-01 13:06:50 +02:00
parent 0a4cade36a
commit 476c79c2e7
2 changed files with 15 additions and 0 deletions

View File

@ -90,6 +90,9 @@ public class DefaultAttributeMap implements AttributeMap {
DefaultAttribute<T> attr = new DefaultAttribute<T>(head, key);
curr.next = attr;
attr.prev = curr;
return attr;
} else {
curr = next;
}
}
}

View File

@ -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<Integer> 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());
}
}