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

Fix generate single sample with null value #136

Merged
merged 1 commit into from
Nov 26, 2020
Merged

Fix generate single sample with null value #136

merged 1 commit into from
Nov 26, 2020

Conversation

mhyeon-lee
Copy link
Contributor

@mhyeon-lee mhyeon-lee commented Nov 25, 2020

Overview

Arbitrary.sample throws NullPointException when generating null values.
Calling the findFirst method on Stream does not allow null values.

Details

To avoid handling null values, wrap it with Optional and handle it.


I hereby agree to the terms of the jqwik Contributor Agreement.

@jlink
Copy link
Collaborator

jlink commented Nov 25, 2020

@mhyeon-lee Thanks for the catch.

I cannot merge the PR, though, unless you add

---

I hereby agree to the terms of the [jqwik Contributor Agreement](https://github.com/jlink/jqwik/blob/master/CONTRIBUTING.md#jqwik-contributor-agreement).

to the buttom of the PRs description.

Thank you.

@mhyeon-lee
Copy link
Contributor Author

@jlink I added agreement description. thank you

@jlink
Copy link
Collaborator

jlink commented Nov 26, 2020

@mhyeon-lee Many thanks!

@jlink jlink merged commit c33ed01 into jqwik-team:main Nov 26, 2020
jlink added a commit that referenced this pull request Nov 26, 2020
@@ -441,8 +441,10 @@ public boolean isUnique() {
@API(status = MAINTAINED, since = "1.3.0")
default T sample() {
return this.sampleStream()
.findFirst()
.orElseThrow(() -> new JqwikException("Cannot generate a value"));
.map(Optional::ofNullable)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would be a little bit concerned about performance... On the other side, this method should not be called extensively. It is called only by user while experimenting, or perhaps from "normal" JUnit tests. Am I right?

@jlink
Copy link
Collaborator

jlink commented Nov 26, 2020

To be frank I'm not concerned. When generating values so much is going on that the little bit of overhead through mapping should be neglectible. But I didn't measure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants