You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2022/10/12 18:17:00 UTC

[jira] [Resolved] (GROOVY-10717) Map to type coercion not working on abstract classes

     [ https://issues.apache.org/jira/browse/GROOVY-10717?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eric Milles resolved GROOVY-10717.
----------------------------------
    Resolution: Fixed

https://github.com/apache/groovy/commit/778124fa25a2a12229eb43fd5cd0fd71e86fb0aa

> Map to type coercion not working on abstract classes
> ----------------------------------------------------
>
>                 Key: GROOVY-10717
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10717
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 3.0.11, 4.0.2
>            Reporter: Josh DeWitt
>            Assignee: Eric Milles
>            Priority: Major
>
> I sometimes use maps as mock objects for test cases. One test case started failing with groovy 3.0.11 and 4.0.2 where a map was being used as a mock for an abstract class. Here is a simplified version of what is now failing. Note that it does not fail if A is *not* abstract:
> {code:java}
> abstract class A {
>     String b
> }
> def a = [getB: { 'string b' }] as A
> assert 'string b' ==  a.b{code}
>  
> I also noticed that I don't get an UnsupportedOperationException when calling functions that were not implemented in the map as described in [https://groovy-lang.org/semantics.html#_map_to_type_coercion]. MissingPropertyException seems to be working, though I can't seem to find a way to get MissingMethodException.
> {code:java}
> abstract class A {
>     String b
>     String c
> }
> def a = [getB: { 'string b' }, getD: { 'string d' }] as A
> assert null != a.c // Should get UnsupportedOperationException (doesn't work)
> assert null != a.d // Should get MissingPropertyException (works)
> assert null != a.getD() // Should get MissingMethodException (doesn't work) 
> {code}
>  
> Possibly related to GROOVY-8243?



--
This message was sent by Atlassian Jira
(v8.20.10#820010)