You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2021/08/14 15:12:15 UTC

[groovy] branch master updated: GROOVY-10191: catch LinkageError during static inline

This is an automated email from the ASF dual-hosted git repository.

sunlan 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 18c9ab9  GROOVY-10191: catch LinkageError during static inline
18c9ab9 is described below

commit 18c9ab98ede3ca72856c03b127da41222ad9fc7e
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Thu Aug 12 15:53:22 2021 -0500

    GROOVY-10191: catch LinkageError during static inline
---
 .../apache/groovy/ast/tools/ExpressionUtils.java   |  4 +-
 src/test/groovy/bugs/Groovy10191.groovy            | 43 ++++++++++++++++++++++
 2 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/groovy/ast/tools/ExpressionUtils.java b/src/main/java/org/apache/groovy/ast/tools/ExpressionUtils.java
index bb9790c..c3af88e 100644
--- a/src/main/java/org/apache/groovy/ast/tools/ExpressionUtils.java
+++ b/src/main/java/org/apache/groovy/ast/tools/ExpressionUtils.java
@@ -240,7 +240,7 @@ public final class ExpressionUtils {
                             configure(exp, ce3);
                             return ce3;
                         }
-                    } catch(Exception e) {
+                    } catch (Exception | LinkageError e) {
                         // ignore, leave property expression in place and we'll report later
                     }
                 }
@@ -282,7 +282,7 @@ public final class ExpressionUtils {
                 Expression transformed = transformInlineConstants(e, attrType);
                 newList.addExpression(transformed);
                 if (transformed != e) changed = true;
-            } catch(Exception ignored) {
+            } catch (Exception ignored) {
                 newList.addExpression(e);
             }
         }
diff --git a/src/test/groovy/bugs/Groovy10191.groovy b/src/test/groovy/bugs/Groovy10191.groovy
new file mode 100644
index 0000000..96cab84
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy10191.groovy
@@ -0,0 +1,43 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package groovy.bugs
+
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+final class Groovy10191 {
+
+    static class Foo {
+        public static final BAR = 'baz'
+        static {
+            throw new NoSuchMethodError('simulate complex init')
+        }
+    }
+
+    @Test
+    void testStaticInlining() {
+        assertScript """
+            class C {
+                private static final x = ${getClass().getName()}.Foo.BAR
+            }
+            assert true
+        """
+    }
+}