[#5239] Allow adding handlers to pipeline with null name.

Motivation:

While doing 8fe3c83e4ca9a64c03f5adcb9f056d9e9440a389 I made a change which disallowed using null as name for handlers in the pipeline (this generated a new name before).

Modifications:

Revert to old behaviour and adding test case.

Result:

Allow null name again
This commit is contained in:
Norman Maurer 2016-05-23 19:01:15 +02:00
parent 6cb239e79e
commit 5ec15b3124
3 changed files with 40 additions and 19 deletions

View File

@ -227,7 +227,7 @@ public interface ChannelPipeline
* @throws IllegalArgumentException
* if there's an entry with the same name already in the pipeline
* @throws NullPointerException
* if the specified name or handler is {@code null}
* if the specified handler is {@code null}
*/
ChannelPipeline addFirst(String name, ChannelHandler handler);
@ -242,7 +242,7 @@ public interface ChannelPipeline
* @throws IllegalArgumentException
* if there's an entry with the same name already in the pipeline
* @throws NullPointerException
* if the specified name or handler is {@code null}
* if the specified handler is {@code null}
*/
ChannelPipeline addFirst(EventExecutorGroup group, String name, ChannelHandler handler);
@ -255,7 +255,7 @@ public interface ChannelPipeline
* @throws IllegalArgumentException
* if there's an entry with the same name already in the pipeline
* @throws NullPointerException
* if the specified name or handler is {@code null}
* if the specified handler is {@code null}
*/
ChannelPipeline addLast(String name, ChannelHandler handler);
@ -270,7 +270,7 @@ public interface ChannelPipeline
* @throws IllegalArgumentException
* if there's an entry with the same name already in the pipeline
* @throws NullPointerException
* if the specified name or handler is {@code null}
* if the specified handler is {@code null}
*/
ChannelPipeline addLast(EventExecutorGroup group, String name, ChannelHandler handler);
@ -287,7 +287,7 @@ public interface ChannelPipeline
* @throws IllegalArgumentException
* if there's an entry with the same name already in the pipeline
* @throws NullPointerException
* if the specified baseName, name, or handler is {@code null}
* if the specified baseName or handler is {@code null}
*/
ChannelPipeline addBefore(String baseName, String name, ChannelHandler handler);
@ -306,7 +306,7 @@ public interface ChannelPipeline
* @throws IllegalArgumentException
* if there's an entry with the same name already in the pipeline
* @throws NullPointerException
* if the specified baseName, name, or handler is {@code null}
* if the specified baseName or handler is {@code null}
*/
ChannelPipeline addBefore(EventExecutorGroup group, String baseName, String name, ChannelHandler handler);
@ -323,7 +323,7 @@ public interface ChannelPipeline
* @throws IllegalArgumentException
* if there's an entry with the same name already in the pipeline
* @throws NullPointerException
* if the specified baseName, name, or handler is {@code null}
* if the specified baseName or handler is {@code null}
*/
ChannelPipeline addAfter(String baseName, String name, ChannelHandler handler);
@ -342,7 +342,7 @@ public interface ChannelPipeline
* @throws IllegalArgumentException
* if there's an entry with the same name already in the pipeline
* @throws NullPointerException
* if the specified baseName, name, or handler is {@code null}
* if the specified baseName or handler is {@code null}
*/
ChannelPipeline addAfter(EventExecutorGroup group, String baseName, String name, ChannelHandler handler);
@ -458,7 +458,7 @@ public interface ChannelPipeline
* if a handler with the specified new name already exists in this
* pipeline, except for the handler to be replaced
* @throws NullPointerException
* if the specified old handler, new name, or new handler is
* if the specified old handler or new handler is
* {@code null}
*/
ChannelPipeline replace(ChannelHandler oldHandler, String newName, ChannelHandler newHandler);
@ -478,7 +478,7 @@ public interface ChannelPipeline
* if a handler with the specified new name already exists in this
* pipeline, except for the handler to be replaced
* @throws NullPointerException
* if the specified old handler, new name, or new handler is
* if the specified old handler or new handler is
* {@code null}
*/
ChannelHandler replace(String oldName, String newName, ChannelHandler newHandler);
@ -499,7 +499,7 @@ public interface ChannelPipeline
* if a handler with the specified new name already exists in this
* pipeline, except for the handler to be replaced
* @throws NullPointerException
* if the specified old handler, new name, or new handler is
* if the specified old handler or new handler is
* {@code null}
*/
<T extends ChannelHandler> T replace(Class<T> oldHandlerType, String newName,

View File

@ -134,8 +134,8 @@ public class DefaultChannelPipeline implements ChannelPipeline {
final AbstractChannelHandlerContext newCtx;
final EventExecutor executor;
synchronized (this) {
checkDuplicateName(name);
checkMultiplicity(handler);
name = filterName(name, handler);
newCtx = newContext(group, name, handler);
executor = executorSafe(newCtx.executor);
@ -182,10 +182,9 @@ public class DefaultChannelPipeline implements ChannelPipeline {
final EventExecutor executor;
final AbstractChannelHandlerContext newCtx;
synchronized (this) {
checkDuplicateName(name);
checkMultiplicity(handler);
newCtx = newContext(group, name, handler);
newCtx = newContext(group, filterName(name, handler), handler);
executor = executorSafe(newCtx.executor);
addLast0(newCtx);
@ -232,8 +231,8 @@ public class DefaultChannelPipeline implements ChannelPipeline {
final AbstractChannelHandlerContext ctx;
synchronized (this) {
checkMultiplicity(handler);
name = filterName(name, handler);
ctx = getContextOrDie(baseName);
checkDuplicateName(name);
newCtx = newContext(group, name, handler);
executor = executorSafe(newCtx.executor);
@ -269,6 +268,14 @@ public class DefaultChannelPipeline implements ChannelPipeline {
ctx.prev = newCtx;
}
private String filterName(String name, ChannelHandler handler) {
if (name == null) {
return generateName(handler);
}
checkDuplicateName(name);
return name;
}
@Override
public final ChannelPipeline addAfter(String baseName, String name, ChannelHandler handler) {
return addAfter(null, baseName, name, handler);
@ -276,15 +283,15 @@ public class DefaultChannelPipeline implements ChannelPipeline {
@Override
public final ChannelPipeline addAfter(
EventExecutorGroup group, String baseName, final String name, ChannelHandler handler) {
EventExecutorGroup group, String baseName, String name, ChannelHandler handler) {
final EventExecutor executor;
final AbstractChannelHandlerContext newCtx;
final AbstractChannelHandlerContext ctx;
synchronized (this) {
checkMultiplicity(handler);
name = filterName(name, handler);
ctx = getContextOrDie(baseName);
checkDuplicateName(name);
newCtx = newContext(group, name, handler);
executor = executorSafe(newCtx.executor);
@ -342,7 +349,7 @@ public class DefaultChannelPipeline implements ChannelPipeline {
for (int i = size - 1; i >= 0; i --) {
ChannelHandler h = handlers[i];
addFirst(executor, generateName(h), h);
addFirst(executor, null, h);
}
return this;
@ -363,7 +370,7 @@ public class DefaultChannelPipeline implements ChannelPipeline {
if (h == null) {
break;
}
addLast(executor, generateName(h), h);
addLast(executor, null, h);
}
return this;

View File

@ -866,6 +866,20 @@ public class DefaultChannelPipelineTest {
}
}
@Test
public void testNullName() {
ChannelPipeline pipeline = new LocalChannel().pipeline();
pipeline.addLast(newHandler());
pipeline.addLast(null, newHandler());
pipeline.addFirst(newHandler());
pipeline.addFirst(null, newHandler());
pipeline.addLast("test", newHandler());
pipeline.addAfter("test", null, newHandler());
pipeline.addBefore("test", null, newHandler());
}
private static final class TestTask implements Runnable {
private final ChannelPipeline pipeline;