-
-
Notifications
You must be signed in to change notification settings - Fork 15.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider treating null as "none" in ChannelPipeline#add(..) functionality #10728
Comments
yeah sounds a good idea...can you do a PR against master ? |
Bennett-Lynch
added a commit
to Bennett-Lynch/netty
that referenced
this issue
Oct 29, 2020
Motivation Allowing null handlers allows for more convenient idioms in conditionally adding handlers, e.g., ch.pipeline().addLast( new FooHandler(), condition ? new BarHandler() : null, new BazHandler() ); Modifications * Change addFirst(..) and addLast(..) to skip null handlers, rather than break or short-circuit. * Add new unit tests. Result * Makes addFirst(..) and addLast(..) behavior more consistent * Resolves netty#10728
Bennett-Lynch
added a commit
to Bennett-Lynch/netty
that referenced
this issue
Oct 30, 2020
Motivation Allowing null handlers allows for more convenient idioms in conditionally adding handlers, e.g., ch.pipeline().addLast( new FooHandler(), condition ? new BarHandler() : null, new BazHandler() ); Modifications * Change addFirst(..) and addLast(..) to skip null handlers, rather than break or short-circuit. * Add new unit tests. Result * Makes addFirst(..) and addLast(..) behavior more consistent * Resolves netty#10728
normanmaurer
pushed a commit
that referenced
this issue
Nov 3, 2020
…10751) Motivation: Allowing null handlers allows for more convenient idioms in conditionally adding handlers, e.g., ch.pipeline().addLast( new FooHandler(), condition ? new BarHandler() : null, new BazHandler() ); Modifications: * Change addFirst(..) and addLast(..) to skip null handlers, rather than break or short-circuit. * Add new unit tests. Result: * Makes addFirst(..) and addLast(..) behavior more consistent * Resolves #10728
Bennett-Lynch
added a commit
to Bennett-Lynch/netty
that referenced
this issue
Nov 4, 2020
Motivation Allowing null handlers allows for more convenient idioms in conditionally adding handlers, e.g., ch.pipeline().addLast( new FooHandler(), condition ? new BarHandler() : null, new BazHandler() ); Modifications * Change addFirst(..) and addLast(..) to skip null handlers, rather than break or short-circuit. * Add new unit tests. Result * Makes addFirst(..) and addLast(..) behavior more consistent * Resolves netty#10728
Bennett-Lynch
added a commit
to Bennett-Lynch/netty
that referenced
this issue
Nov 4, 2020
Motivation Allowing null handlers allows for more convenient idioms in conditionally adding handlers, e.g., ch.pipeline().addLast( new FooHandler(), condition ? new BarHandler() : null, new BazHandler() ); Modifications * Change addFirst(..) and addLast(..) to skip null handlers, rather than break or short-circuit. * Add new unit tests. Result * Makes addFirst(..) and addLast(..) behavior more consistent * Resolves netty#10728
Bennett-Lynch
added a commit
to Bennett-Lynch/netty
that referenced
this issue
Jan 19, 2021
Motivation Allowing null handlers allows for more convenient idioms in conditionally adding handlers, e.g., ch.pipeline().addLast( new FooHandler(), condition ? new BarHandler() : null, new BazHandler() ); Modifications * Change addFirst(..) and addLast(..) to skip null handlers, rather than break or short-circuit. * Add new unit tests. Result * Makes addFirst(..) and addLast(..) behavior more consistent * Resolves netty#10728
Bennett-Lynch
added a commit
to Bennett-Lynch/netty
that referenced
this issue
Jan 28, 2021
Motivation Allowing null handlers allows for more convenient idioms in conditionally adding handlers, e.g., ch.pipeline().addLast( new FooHandler(), condition ? new BarHandler() : null, new BazHandler() ); Modifications * Change addFirst(..) and addLast(..) to skip null handlers, rather than break or short-circuit. * Add new unit tests. Result * Makes addFirst(..) and addLast(..) behavior more consistent * Resolves netty#10728
chrisvest
pushed a commit
that referenced
this issue
Jan 29, 2021
…ndlers (#10776) Allow and skip null handlers when adding a vararg list of handlers Motivation Allowing null handlers allows for more convenient idioms in conditionally adding handlers, e.g., ch.pipeline().addLast( new FooHandler(), condition ? new BarHandler() : null, new BazHandler() ); Modifications * Change addFirst(..) and addLast(..) to skip null handlers, rather than break or short-circuit. * Add new unit tests. Result * Makes addFirst(..) and addLast(..) behavior more consistent * Resolves #10728
raidyue
pushed a commit
to raidyue/netty
that referenced
this issue
Jul 8, 2022
…etty#10751) Motivation: Allowing null handlers allows for more convenient idioms in conditionally adding handlers, e.g., ch.pipeline().addLast( new FooHandler(), condition ? new BarHandler() : null, new BazHandler() ); Modifications: * Change addFirst(..) and addLast(..) to skip null handlers, rather than break or short-circuit. * Add new unit tests. Result: * Makes addFirst(..) and addLast(..) behavior more consistent * Resolves netty#10728
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When adding handlers to a pipeline using the varargs methods, if Netty encounters a handler that is null, it will cease the insertion logic:
netty/transport/src/main/java/io/netty/channel/DefaultChannelPipeline.java
Lines 374 to 382 in 1ca7d5d
I propose that it would be more intuitive to use
continue
here, rather thanbreak
.This would allow for handlers to be conditionally added with ease. E.g.,
This is technically a behavior change so I'm not sure if it would be allowed in Netty 4 or not, but it seems reasonably safe.
The text was updated successfully, but these errors were encountered: