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

2.x: additional warnings for fromPublisher() #5640

Merged
merged 2 commits into from
Oct 4, 2017

Conversation

akarnokd
Copy link
Member

@akarnokd akarnokd commented Oct 4, 2017

This PR adds JavaDoc warnings for fromPublisher as people still try to implement a source through it and fail to follow the specification like this:

// DON'T DO THIS!
Flowable.fromPublisher((Subscriber<Integer> s) -> s.onNext(1));

Even though Publisher is a single abstract method (SAM) type, it is almost never reasonable to write a source with it that doesn't require a per-subscriber state. The example above fails to setup backpressure properly and it didn't call s.onSubscribe() for that, causing NullPointerException whenever the Subscription would be needed (i.e., for cancellation and requesting) by the downstream operator.

Maybe doesn't have fromPublisher.

@akarnokd akarnokd added this to the 2.2 milestone Oct 4, 2017
@akarnokd akarnokd force-pushed the FromPublisherJavadoc branch from 2bc9f23 to 755937f Compare October 4, 2017 08:53
@akarnokd akarnokd force-pushed the FromPublisherJavadoc branch from 755937f to ef611ab Compare October 4, 2017 09:06
@codecov
Copy link

codecov bot commented Oct 4, 2017

Codecov Report

Merging #5640 into 2.x will decrease coverage by 0.05%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##                2.x    #5640      +/-   ##
============================================
- Coverage     96.27%   96.22%   -0.06%     
+ Complexity     5852     5844       -8     
============================================
  Files           634      634              
  Lines         41539    41539              
  Branches       5752     5752              
============================================
- Hits          39993    39972      -21     
- Misses          611      623      +12     
- Partials        935      944       +9
Impacted Files Coverage Δ Complexity Δ
src/main/java/io/reactivex/Flowable.java 100% <ø> (ø) 523 <0> (ø) ⬇️
src/main/java/io/reactivex/Completable.java 100% <ø> (ø) 113 <0> (ø) ⬇️
src/main/java/io/reactivex/Single.java 100% <ø> (ø) 135 <0> (ø) ⬇️
src/main/java/io/reactivex/Observable.java 100% <ø> (ø) 506 <0> (ø) ⬇️
...ava/io/reactivex/processors/BehaviorProcessor.java 88.49% <0%> (-4.87%) 62% <0%> (ø)
...reactivex/internal/operators/single/SingleAmb.java 96.36% <0%> (-3.64%) 9% <0%> (-1%)
...ternal/operators/observable/ObservablePublish.java 92.98% <0%> (-3.51%) 11% <0%> (ø)
.../io/reactivex/internal/schedulers/IoScheduler.java 89.24% <0%> (-3.23%) 9% <0%> (ø)
...a/io/reactivex/internal/util/QueueDrainHelper.java 61.7% <0%> (-2.84%) 33% <0%> (-2%)
...va/io/reactivex/internal/queue/SpscArrayQueue.java 97.61% <0%> (-2.39%) 22% <0%> (-1%)
... and 29 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3e11dc0...302bf3d. Read the comment docs.

* <p>
* Note that even though {@link Publisher} appears to be a functional interface, it
* is not recommended to implement it through a lambda as the specification requires
* state management not achievable with a stateless lambda.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add which is here? state management which is not achievable with a stateless lambda.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or that is. Grammarly doesn't complain about the PR's text.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is would also work.

@akarnokd akarnokd merged commit 89581b4 into ReactiveX:2.x Oct 4, 2017
@akarnokd akarnokd deleted the FromPublisherJavadoc branch October 4, 2017 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants