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 2019/01/28 01:26:50 UTC
[groovy] branch master updated: GROOVY-8238: multiple-catch
statement behaves strangely
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 86724d8 GROOVY-8238: multiple-catch statement behaves strangely
86724d8 is described below
commit 86724d849b915b4efc295f1bb6d150a08cb4162c
Author: Paul King <pa...@asert.com.au>
AuthorDate: Mon Jan 28 11:26:34 2019 +1000
GROOVY-8238: multiple-catch statement behaves strangely
---
.../org/codehaus/groovy/antlr/AntlrParserPlugin.java | 6 ++----
src/test/groovy/MultiCatchTest.groovy | 17 +++++++++++++++++
2 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/antlr/AntlrParserPlugin.java b/src/main/java/org/codehaus/groovy/antlr/AntlrParserPlugin.java
index 9b3981a..02e3e49 100644
--- a/src/main/java/org/codehaus/groovy/antlr/AntlrParserPlugin.java
+++ b/src/main/java/org/codehaus/groovy/antlr/AntlrParserPlugin.java
@@ -1748,16 +1748,14 @@ public class AntlrParserPlugin extends ASTHelper implements ParserPlugin, Groovy
protected List<CatchStatement> catchStatement(AST catchNode) {
AST node = catchNode.getFirstChild();
List<CatchStatement> catches = new LinkedList<CatchStatement>();
- Statement code = statement(node.getNextSibling());
if (MULTICATCH == node.getType()) {
- AST variableNode = node.getNextSibling();
final AST multicatches = node.getFirstChild();
if (multicatches.getType() != MULTICATCH_TYPES) {
// catch (e)
// catch (def e)
String variable = identifier(multicatches);
Parameter catchParameter = new Parameter(ClassHelper.DYNAMIC_TYPE, variable);
- CatchStatement answer = new CatchStatement(catchParameter, code);
+ CatchStatement answer = new CatchStatement(catchParameter, statement(node.getNextSibling()));
configureAST(answer, catchNode);
catches.add(answer);
} else {
@@ -1768,7 +1766,7 @@ public class AntlrParserPlugin extends ASTHelper implements ParserPlugin, Groovy
while (exceptionNodes != null) {
ClassNode exceptionType = buildName(exceptionNodes);
Parameter catchParameter = new Parameter(exceptionType, variable);
- CatchStatement answer = new CatchStatement(catchParameter, code);
+ CatchStatement answer = new CatchStatement(catchParameter, statement(node.getNextSibling()));
configureAST(answer, catchNode);
catches.add(answer);
exceptionNodes = exceptionNodes.getNextSibling();
diff --git a/src/test/groovy/MultiCatchTest.groovy b/src/test/groovy/MultiCatchTest.groovy
index d23829f..2d8de66 100644
--- a/src/test/groovy/MultiCatchTest.groovy
+++ b/src/test/groovy/MultiCatchTest.groovy
@@ -18,6 +18,10 @@
*/
package groovy
+import org.codehaus.groovy.control.CompilerConfiguration
+
+import static org.codehaus.groovy.control.ParserVersion.V_2
+
/**
* Test for the multi-catch exception from JDK 7 (Project Coin)
*/
@@ -116,4 +120,17 @@ class MultiCatchTest extends GroovyTestCase {
}
assert catched
}
+
+ // GROOVY-8238
+ void testMultipleCatchGroovyAndJavaExceptions() {
+ def cc = new CompilerConfiguration(parserVersion: V_2)
+ new GroovyShell(cc).evaluate '''
+ import groovy.cli.CliBuilderException
+ try {
+ throw new RuntimeException('boom')
+ } catch ( RuntimeException | CliBuilderException e ) {
+ assert e.message == 'boom'
+ }
+ '''
+ }
}