You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2015/10/15 09:17:39 UTC
incubator-groovy git commit: GROOVY-3341: If an exception is thrown
from a builder closure, wrap it in a GroovyRuntimeException,
otherwise it would be reported as a missing methon on the closure (closes
#130)
Repository: incubator-groovy
Updated Branches:
refs/heads/master 8ff4623e7 -> 90ed7b26f
GROOVY-3341: If an exception is thrown from a builder closure, wrap it in a GroovyRuntimeException, otherwise it would be reported as a missing methon on the closure (closes #130)
Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/90ed7b26
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/90ed7b26
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/90ed7b26
Branch: refs/heads/master
Commit: 90ed7b26f25cb1532dc06eb32c58aed5b185713b
Parents: 8ff4623
Author: Jochen Kemnade <jo...@eddyson.de>
Authored: Thu Jul 23 11:02:48 2015 +0200
Committer: pascalschumacher <pa...@gmx.net>
Committed: Thu Oct 15 09:16:42 2015 +0200
----------------------------------------------------------------------
src/main/groovy/util/BuilderSupport.java | 7 ++++++-
src/test/groovy/util/BuilderSupportTest.groovy | 13 +++++++++++++
2 files changed, 19 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/90ed7b26/src/main/groovy/util/BuilderSupport.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/util/BuilderSupport.java b/src/main/groovy/util/BuilderSupport.java
index b09442f..f634f1f 100644
--- a/src/main/groovy/util/BuilderSupport.java
+++ b/src/main/groovy/util/BuilderSupport.java
@@ -20,6 +20,7 @@ package groovy.util;
import groovy.lang.Closure;
import groovy.lang.GroovyObjectSupport;
+import groovy.lang.GroovyRuntimeException;
import groovy.lang.MissingMethodException;
import org.codehaus.groovy.runtime.InvokerHelper;
@@ -142,7 +143,11 @@ public abstract class BuilderSupport extends GroovyObjectSupport {
setCurrent(node);
// let's register the builder as the delegate
setClosureDelegate(closure, node);
- closure.call();
+ try {
+ closure.call();
+ } catch (Exception e) {
+ throw new GroovyRuntimeException(e);
+ }
setCurrent(oldCurrent);
}
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/90ed7b26/src/test/groovy/util/BuilderSupportTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/util/BuilderSupportTest.groovy b/src/test/groovy/util/BuilderSupportTest.groovy
index cb62bd0..534810d 100644
--- a/src/test/groovy/util/BuilderSupportTest.groovy
+++ b/src/test/groovy/util/BuilderSupportTest.groovy
@@ -148,6 +148,19 @@ class BuilderSupportTest extends GroovyTestCase{
void nestedBuilderCall(builder) {
builder.inner()
}
+
+ // GROOVY-3341
+ void testSimpleNodeWithClosureThatThrowsAMissingMethodException() {
+ def builder = new SpoofBuilder()
+ String errorMessage = shouldFail(MissingMethodException, {
+ builder.a {
+ b {
+ error('xy'.foo())
+ }
+ }
+ })
+ assert errorMessage.contains('No signature of method: java.lang.String.foo()')
+ }
}
/**