Fixed issue NETTY-148: ChannelLocal.initialValue() must return non-null
* Made ChannelLocal.initialValue() abstract * Null check in ChannelLocal
This commit is contained in:
parent
726ab5236b
commit
a24959b9ea
@ -33,7 +33,7 @@ import org.jboss.netty.util.internal.ConcurrentIdentityWeakKeyHashMap;
|
|||||||
*
|
*
|
||||||
* @apiviz.stereotype utility
|
* @apiviz.stereotype utility
|
||||||
*/
|
*/
|
||||||
public class ChannelLocal<T> {
|
public abstract class ChannelLocal<T> {
|
||||||
private final ConcurrentMap<Channel, T> map =
|
private final ConcurrentMap<Channel, T> map =
|
||||||
new ConcurrentIdentityWeakKeyHashMap<Channel, T>();
|
new ConcurrentIdentityWeakKeyHashMap<Channel, T>();
|
||||||
|
|
||||||
@ -44,14 +44,18 @@ public class ChannelLocal<T> {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected T initialValue(@SuppressWarnings("unused") Channel channel) {
|
protected abstract T initialValue(Channel channel);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T get(Channel channel) {
|
public T get(Channel channel) {
|
||||||
T value = map.get(channel);
|
T value = map.get(channel);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
value = initialValue(channel);
|
value = initialValue(channel);
|
||||||
|
if (value == null) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
ChannelLocal.class.getSimpleName() +
|
||||||
|
".initialValue() must return non-null.");
|
||||||
|
}
|
||||||
|
|
||||||
T oldValue = setIfAbsent(channel, value);
|
T oldValue = setIfAbsent(channel, value);
|
||||||
if (oldValue != null) {
|
if (oldValue != null) {
|
||||||
value = oldValue;
|
value = oldValue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user