From e057bdaf596efef585797b758aeb3cfc1ecf77e4 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 13 Jul 2017 15:26:22 +0200 Subject: [PATCH] slowCheck: expect flatMap argument function to always return non-null --- slowCheck/src/slowCheck/Generator.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/slowCheck/src/slowCheck/Generator.java b/slowCheck/src/slowCheck/Generator.java index decec98e0e95..48671d7808f2 100644 --- a/slowCheck/src/slowCheck/Generator.java +++ b/slowCheck/src/slowCheck/Generator.java @@ -39,7 +39,12 @@ public final class Generator { } public Generator flatMap(@NotNull Function> fun) { - return from(data -> fun.apply(generateValue(data)).generateValue(data)); + return from(data -> { + T value = generateValue(data); + Generator result = fun.apply(value); + if (result == null) throw new NullPointerException(fun + " returned null on " + value); + return result.generateValue(data); + }); } public Generator noShrink() {