-
Notifications
You must be signed in to change notification settings - Fork 534
clarify whether null
is a valid element
#204
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
Comments
Given that there is no provision in the spec prohibiting the use of null, I think the current status is that it is prohibited. @reactive-streams/contributors Thoughts? |
I believe it is currently not prohibited to use So this clarification needs no tck updates either way (as forbidding null would be a spec violation rule, so I'd assume we do not force subscribers to throw if someone signals a null value). // edited a bit to make it clearer, initial wording I used was confusing - sorry |
For implementors those nulls will be hellish, most of the concurrent queues dislike it. |
I don't see why it needs to be specified. The only method this could impact is onNext. Some (hopefully most) publishers will promise never to call onNext(null) because it would make no sense, and some (hopefully most) subscribers would treat them as indications that there is nothing-there, and either skip them or treat them as errors. |
@DougLea I suspect the problematic case will be the combination of null-publishing-publisher with non-null-receiving-subscriber. |
yes. but those null-tokens will be custom per library? |
or you mean that the users of a CLQ just do it internally |
@drewhk I mean that since it is the CLQ of the Subscriber, any such handling is purely local. |
Ah forget it, I am too tired to think, no problem there. |
To clarify: Banning nulls is a great policy because it avoids unsolvable issues about how to interpret them: In most concurrent settings, sending "nothing" makes no sense, so it is usually banned, which also simplifies APIs. But if nulls are allowed to be sent here, it ought to be legal for any receiving stage (including relays) to skip them. (Thus they never enter queues etc.) |
I'm all for banning |
In RxJava we have allowed it and use a NULL_SENTINEL whenever we are going via a queue. I don't have strong opinion either direction on allowing or banning it, just sharing that we did end up making the effort to support it, and we have had users over time who wanted the support (and have filed bugs when we didn't). |
FWIW, future-streams supports nulls (without any special treatment); I have no reason to disallow them. If a user doesn't realize nulls are disallowed and tries using them, maybe the spec should require immediate runtime failure on calling onNext(null). Otherwise the resulting error may be hard to understand for someone who isn't familiar with the implementation used. CLQ.add(null) throws a NullPointerException, but in theory an implementation could rely on the prohibition of nulls in a way that makes sending nulls a race condition or some other undefined, hard to debug behavior. @DougLea why are you suggesting subscribers skip nulls? In most cases I would expect an error instead of silently ignoring input. If I write a Processor that maps elements, and it happens to be implemented using CLQ inside my streams library (not manually by me as a user), and it encounters a null, then I would want it to signal an error, not silently drop input. |
@danarmak I just sent you 42 empty TCP packets as an answer. Again, the main problem here is that there is no single right way to process nulls, so users who care about quality won't use them. (The in-progress j.u.c SubmissionPublisher does not allow them to be sent.) But that's not necessarily a reason to ban them outright. |
@DougLea certainly, sometimes it's permissible or even expected to drop certain messages. But unless the subscriber understands the semantics of Also, "empty" elements are often represented by something other than null (e.g. I think we should do one of:
Do you think some other option involving dropping is better? |
My attitude is colored by a long history of dealing with this. I'd prefer to ban the use of null to mean anything other than "there is nothing here". But I settle for doing this only in components that I develop, and let people adapt to it using sentinels etc if they need to. Which amounts to your option (3). |
The problem here (that I see) is that if onNext-ing null is OK to be silently dropped, it needs to be specced so that demand counting doesn't go awry. I'm fine with either A) Explicitly mandate that @reactive-streams/contributors Thoughts? :) |
I vote for forbidding null. |
I don't have a strong opinion on this so I'm fine either way. Existing stream libraries supporting nulls will have to start throwing an NPE when bridging into Reactive Streams if we go that route, but I'm fine with that. |
Subscribe(null) has nowhere to go (can't throw, can't call null.onError). For the other methods, I think the cost of enforcing non-nullness is greater than using null-sentinels. The former need to be put on every subscriber frontend at every stage (increasing method bytecode length as well), whereas the latter need to be put in front and back of helper data structures (i.e., queues) only. Generally, the issue I see with forced onError based error reporting (since the 7 API methods mustn't throw) is that Subscribers need to be defensively serializing because rule violations happening on any thread has to be reported spec conformant. |
@akarnokd Indeed, the behavior of |
@viktorklang Same answer as onNext(null) (also for onSubscribe(null), onError(null)): Either say that behavior is undefined and implementation-dependent (thus allowing exceptions), or mandate that they cannot be null (thus requiring exceptions). Either approach conveys the message that reliable programs do not use nulls as sentinels. |
@DougLea having a ban on |
@reactive-streams/contributors Should we add a Rule requiring all signals to throw an NPE or (IAE?) if Ie. illegal: subscribe(null) (We should then update the TCK accordingly) |
I'll open a PR that can be voted upon. |
The text was updated successfully, but these errors were encountered: