[
https://issues.apache.org/jira/browse/GROOVY-11414?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Eric Milles resolved GROOVY-11414.
----------------------------------
Fix Version/s: 4.0.22
Resolution: Fixed
https://github.com/apache/groovy/commit/5a51d5f44911cce95fc722593fd7ae25dbd3df08
> Compiler does not promote/check lambda results when required
> ------------------------------------------------------------
>
> Key: GROOVY-11414
> URL: https://issues.apache.org/jira/browse/GROOVY-11414
> Project: Groovy
> Issue Type: Bug
> Components: Compiler
> Affects Versions: 4.0.21
> Reporter: Christopher Smith
> Assignee: Eric Milles
> Priority: Major
> Fix For: 4.0.22
>
>
> Given this code, the Groovy compiler compiles it and happily inserts a
> {{java.lang.Integer}} into a {{Map<String, Long}}. The Java compiler produces
> a compile-time error for the same code, complaining that {{1}} is not a
> {{Long}}. The result is the same for static and dynamic compilation: heap
> pollution.
> {code:groovy}
> class Repro {
> static Map<String, Long> map = new HashMap()
> static void main(String... args) {
> println map.computeIfAbsent('key', (__) -> 1)
> println map.key.class
> println map.compute('key', (__, Long existing) -> (existing ?: 0L) +
> 2)
> }
> }
> {code}
> {code}
> import java.util.HashMap;
> import java.util.Map;
> class ReproJava {
> static Map<String, Long> map = new HashMap<>();
> static void main(String... args) {
> map.computeIfAbsent("key", (__) -> 1);
> map.compute("key", (__, existing) -> (existing != null ? existing :
> 0L) + 2);
> }
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)