[#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.
This commit is contained in:
parent
0a4cade36a
commit
476c79c2e7
@ -90,6 +90,9 @@ public class DefaultAttributeMap implements AttributeMap {
|
|||||||
DefaultAttribute<T> attr = new DefaultAttribute<T>(head, key);
|
DefaultAttribute<T> attr = new DefaultAttribute<T>(head, key);
|
||||||
curr.next = attr;
|
curr.next = attr;
|
||||||
attr.prev = curr;
|
attr.prev = curr;
|
||||||
|
return attr;
|
||||||
|
} else {
|
||||||
|
curr = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,4 +67,16 @@ public class DefaultAttributeMapTest {
|
|||||||
one.remove();
|
one.remove();
|
||||||
assertNull(one.get());
|
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…
x
Reference in New Issue
Block a user