[#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:
parent
8583dd03fc
commit
d0f3bfd4cc
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user