Skip to content

Commit

Permalink
Fixed Option.when in case of a nullable supplier
Browse files Browse the repository at this point in the history
  • Loading branch information
Pap Lőrinc committed Apr 14, 2016
1 parent 71d4c3f commit 7e1e7f9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion javaslang/src/main/java/javaslang/control/Option.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static <T> Option<T> narrow(Option<? extends T> option) {
*/
static <T> Option<T> when(boolean condition, Supplier<? extends T> supplier) {
Objects.requireNonNull(supplier, "supplier is null");
return condition ? of(supplier.get()) : none();
return condition ? some(supplier.get()) : none();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion javaslang/src/test/java/javaslang/control/OptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void shouldCreateNothing() {

@Test
public void shouldWrapIfTrue() {
assertThat(Option.of(null)).isEqualTo(Option.when(true, () -> null));
assertThat(Option.some(null)).isEqualTo(Option.when(true, () -> null));
}

@Test
Expand Down

1 comment on commit 7e1e7f9

@danieldietrich
Copy link
Contributor

Choose a reason for hiding this comment

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

Fixes #1272

Please sign in to comment.