Skip to content

Commit

Permalink
[netty#2523] Fix infinite-loop when remove attribute and create the s…
Browse files Browse the repository at this point in the history
…ame 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 c3bd7a8.

Modification:
Correctly break out loop

Result:
No infinite-loop anymore.
  • Loading branch information
Norman Maurer committed Jun 1, 2014
1 parent 2c38e6b commit 1347e7f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions common/src/main/java/io/netty/util/DefaultAttributeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ public <T> Attribute<T> attr(AttributeKey<T> key) {
DefaultAttribute<T> attr = new DefaultAttribute<T>(head, key);
curr.next = attr;
attr.prev = curr;
return attr;
} else {
curr = next;
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions common/src/test/java/io/netty/util/DefaultAttributeMapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,16 @@ public void testGetSetInt() {
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());
}
}

0 comments on commit 1347e7f

Please sign in to comment.