Skip to content
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

FluxEmpty does not throw NoSuchElementException #1226

Closed
Danny02 opened this issue May 30, 2018 · 3 comments
Closed

FluxEmpty does not throw NoSuchElementException #1226

Danny02 opened this issue May 30, 2018 · 3 comments
Assignees
Labels
status/backported-3.1 backported in previous generation line (3.1) type/bug A general bug
Milestone

Comments

@Danny02
Copy link

Danny02 commented May 30, 2018

Expected behavior

The JavaDoc of Flux#last states:

[...] or emit NoSuchElementException error if the source was empty

Steps to reproduce

Flux.empty().last().block()

Flux.fromIterable(List.of()).block()

Actual behavior

The first line does not throw an Exception and returns null. The second example throws a NoSuchElementException.

Reactor Core version

3.1.6

JVM version (e.g. java -version)

9.0.4

@simonbasle
Copy link
Member

Thanks, indeed this is due to an overeager optimization that detect the Flux.empty() is a form of Callable and converts it to a Mono in a generic way, forgetting about the NoSuchElementException-on-empty aspect.

If you turn it into a Flux.empty().hide() it works as expected.

I'll prepare a fix for the 3.2.0 line

@simonbasle simonbasle self-assigned this May 31, 2018
@simonbasle simonbasle added the type/bug A general bug label May 31, 2018
@simonbasle
Copy link
Member

Note: I wonder if we should try to fix it in the 3.1.x line as well, people may have come to rely on this behavior so a fix during a maintenance release is maybe not ideal 🤔

@simonbasle simonbasle added the status/need-decision This needs a decision from the team label May 31, 2018
@smaldini
Copy link
Contributor

smaldini commented Jun 1, 2018

@simonbasle i think it should go to 3.1 too.

@simonbasle simonbasle added this to the Backlog milestone Jun 6, 2018
@simonbasle simonbasle added need-backport-3.1 and removed status/need-decision This needs a decision from the team labels Jun 6, 2018
@simonbasle simonbasle modified the milestones: Backlog, 3.2.0.M2 Jun 6, 2018
simonbasle added a commit that referenced this issue Jun 7, 2018
The operator Flux#last() used to skip the exception on empty source that
was also a Callable, due to an overeager optimization.

This is a backport of commit 2b09286, as tracked in #1198
@simonbasle simonbasle added status/backported-3.1 backported in previous generation line (3.1) and removed need-backport-3.1 labels Jun 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/backported-3.1 backported in previous generation line (3.1) type/bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants