[jira] [Updated] (GROOVY-7156) Builders behave strange when closures throw exceptions

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Updated] (GROOVY-7156) Builders behave strange when closures throw exceptions

JIRA jira@apache.org

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

Jochen Kemnade updated GROOVY-7156:
-----------------------------------
    Affects Version/s: 2.4.3

> Builders behave strange when closures throw exceptions
> ------------------------------------------------------
>
>                 Key: GROOVY-7156
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7156
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.3.7, 2.4.0-rc-2, 2.4.0, 2.4.1, 2.4.2, 2.4.3
>            Reporter: Jochen Kemnade
>         Attachments: groovy-7156.zip
>
>
> I noticed some strange behavior when closures inside a builder throw exceptions:
> {code}
> import groovy.transform.TypeChecked
> @TypeChecked
> class TestBuilder extends BuilderSupport {
>   Object createNode(Object name, Map map){
>     println "Create node $name: $map"
>     new Node(null, name, map)
>   }
>   Object createNode(Object name){
>     println "Create node $name"
>     new Node(null, name)
>   }
>   Object createNode(Object name, Object value){
>     println "Create node $name, value $value"
>     new Node(null, name, value)
>   }
>   Object createNode(Object name, Map map, Object value){
>     println "Create node $name: $map, value $value"
>     new Node(null, name, map, value)
>   }
>   void setParent(Object parent, Object child){
>     println "set parent of $child to $parent"
>     ((Node)parent).append( (Node) child)
>   }
> }
> def builder = new TestBuilder()
> // First case
> // expected: MissingMethodException tring to call String.foo()
> // actual: MissingMethodException tring to call b(Closure)
> try {
>   builder.a {
>     b {
>       error('xy'.foo())
>     }
>   }
> }catch (e){
>   assert e instanceof MissingMethodException
>   assert e.method == "foo"
> }
> // Second case
> // expected: one call to buidler.createNode('b')
> // actual: two calls to buidler.createNode('b')
> builder.with {
>   a {
>     b {
>       error("xy".foo())
>     }
>   }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)