Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Duplicate
-
2.3.7, 2.4.0-rc-2, 2.4.0, 2.4.1, 2.4.2, 2.4.3, 2.4.4
-
None
-
None
-
None
Description
I noticed some strange behavior when closures inside a builder throw exceptions:
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()) } } }
Attachments
Attachments
Issue Links
- is related to
-
GROOVY-3341 MissingMethodException in Builder is misleading
- Closed