groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [groovy] branch GROOVY_2_5_X updated: GROOVY-8238: multiple-catch statement behaves strangely
Date Mon, 28 Jan 2019 01:34:46 GMT
This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY_2_5_X by this push:
     new ad88d2c  GROOVY-8238: multiple-catch statement behaves strangely
ad88d2c is described below

commit ad88d2c9c2bd184e5bddc3a1747ddba582fb343a
Author: Paul King <paulk@asert.com.au>
AuthorDate: Mon Jan 28 11:26:34 2019 +1000

    GROOVY-8238: multiple-catch statement behaves strangely
---
 .../java/org/codehaus/groovy/antlr/AntlrParserPlugin.java     |  6 ++----
 src/test/groovy/MultiCatchTest.groovy                         | 11 +++++++++++
 2 files changed, 13 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..ac4eb71 100644
--- a/src/test/groovy/MultiCatchTest.groovy
+++ b/src/test/groovy/MultiCatchTest.groovy
@@ -18,6 +18,8 @@
  */
 package groovy
 
+import groovy.cli.CliBuilderException
+
 /**
  * Test for the multi-catch exception from JDK 7 (Project Coin)
  */
@@ -116,4 +118,13 @@ class MultiCatchTest extends GroovyTestCase {
         }
         assert catched
     }
+
+    // GROOVY-8238
+    void testMultipleCatchGroovyAndJavaExceptions() {
+        try {
+            throw new RuntimeException('boom')
+        } catch ( RuntimeException | CliBuilderException e ) {
+            assert e.message == 'boom'
+        }
+    }
 }


Mime
View raw message