Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
4.0.12
-
None
Description
The static compiler will accept a closure returning a non-boolean value as fulfilling a Predicate, but it does not coerce the return value using Groovy truth.
@CompileStatic class Bug { static void main(String[] args) { println new AtomicReference<Object>(null).stream() .filter( { it.get() } as Predicate<AtomicReference<?>>) // or .filter(AtomicReference::get as Predicate<AtomicReference<?>>) .findAny() } }
Expected result: Optional.empty
Actual result: NullPointerException on unboxing the null return value
Using an explicit as boolean inside the lambda works, but this doesn't work with method references. Coercion should work even without as Predicate if the compiler sees the functional return type is boolean/Boolean.
Attachments
Issue Links
- is related to
-
GROOVY-8168 When using Interface: BigDecimal cannot be cast to Double
- Closed
-
GROOVY-9971 @TypeChecked: Closure<String> no longer compatible with Closure<GString> argument
- Closed
-
GROOVY-10792 Declared generic parameter on method not transferred to Closure
- Closed