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 2020/01/10 18:57:54 UTC

[groovy] branch GROOVY_3_0_X updated (17c9fda -> 4bd73a2)

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

sunlan pushed a change to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git.


    from 17c9fda  add null-safe stream() extension methods for Object, Optional, Iterable,
     new 866bf5b  GROOVY-9344: add test case
     new 0e9ac42  save source context in uncaught exception error message
     new 4bd73a2  GROOVY-9361: Bump jackson-dataformat-yaml to 2.10.2

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../codehaus/groovy/control/CompilationUnit.java   | 39 ++++++++++------------
 .../groovy/control/messages/ExceptionMessage.java  | 28 ++++++----------
 .../asm/sc/StaticCompileFlowTypingTest.groovy      | 37 +++++++++++++++++---
 subprojects/groovy-yaml/build.gradle               |  2 +-
 4 files changed, 61 insertions(+), 45 deletions(-)


[groovy] 01/03: GROOVY-9344: add test case

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 866bf5b693c606f6ad28c6e374fd519bd5212cc3
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Jan 10 10:11:17 2020 -0600

    GROOVY-9344: add test case
    
    (cherry picked from commit 01d9be5205abb005601a969bd464a5abcb77ba0d)
---
 .../asm/sc/StaticCompileFlowTypingTest.groovy      | 37 +++++++++++++++++++---
 1 file changed, 33 insertions(+), 4 deletions(-)

diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/StaticCompileFlowTypingTest.groovy b/src/test/org/codehaus/groovy/classgen/asm/sc/StaticCompileFlowTypingTest.groovy
index 81894f2..696164d 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/StaticCompileFlowTypingTest.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/StaticCompileFlowTypingTest.groovy
@@ -18,10 +18,17 @@
  */
 package org.codehaus.groovy.classgen.asm.sc
 
-import org.codehaus.groovy.classgen.asm.AbstractBytecodeTestCase
+import groovy.test.NotYetImplemented
+import groovy.transform.CompileStatic
+import org.junit.Test
 
-class StaticCompileFlowTypingTest extends AbstractBytecodeTestCase {
-    void testFlowTyping() {
+import static groovy.test.GroovyAssert.assertScript
+
+@CompileStatic
+final class StaticCompileFlowTypingTest {
+
+    @Test
+    void testFlowTyping1() {
         assertScript '''
             @groovy.transform.CompileStatic
             Object m() {
@@ -36,6 +43,27 @@ class StaticCompileFlowTypingTest extends AbstractBytecodeTestCase {
         '''
     }
 
+    @NotYetImplemented @Test // GROOVY-9344
+    void testFlowTyping2() {
+        assertScript '''
+            class A {}
+            class B {}
+
+            @groovy.transform.CompileStatic
+            String m() {
+                def var
+                var = new A()
+                def c = { ->
+                    var = new B()
+                }
+                c()
+                var.toString()
+            }
+            assert m() != null
+        '''
+    }
+
+    @Test
     void testInstanceOf() {
         assertScript '''
             @groovy.transform.CompileStatic
@@ -50,6 +78,7 @@ class StaticCompileFlowTypingTest extends AbstractBytecodeTestCase {
         '''
     }
 
+    @Test
     void testMethodSelection() {
         assertScript '''
             @groovy.transform.CompileStatic
@@ -63,6 +92,7 @@ class StaticCompileFlowTypingTest extends AbstractBytecodeTestCase {
         '''
     }
 
+    @Test
     void testMethodSelectionDifferentFromDynamicGroovy() {
         assertScript '''
             @groovy.transform.CompileStatic
@@ -90,7 +120,6 @@ class StaticCompileFlowTypingTest extends AbstractBytecodeTestCase {
             assert a.foo(arr[0]) == 1
             assert a.foo(arr[1]) == 2
             assert a.foo(arr[2]) == 3
-
         '''
     }
 }


[groovy] 02/03: save source context in uncaught exception error message

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 0e9ac424c7fd9b8cbf766a2b1025e600e6ff3bae
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Jan 10 11:01:58 2020 -0600

    save source context in uncaught exception error message
    
    (cherry picked from commit 137850cbeb0a694fafa42a06637bbd6974bcca8b)
---
 .../codehaus/groovy/control/CompilationUnit.java   | 39 ++++++++++------------
 .../groovy/control/messages/ExceptionMessage.java  | 28 ++++++----------
 2 files changed, 27 insertions(+), 40 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/control/CompilationUnit.java b/src/main/java/org/codehaus/groovy/control/CompilationUnit.java
index 053cad2..eb915ef 100644
--- a/src/main/java/org/codehaus/groovy/control/CompilationUnit.java
+++ b/src/main/java/org/codehaus/groovy/control/CompilationUnit.java
@@ -930,10 +930,23 @@ public class CompilationUnit extends ProcessingUnit {
                 } catch (GroovyBugError e) {
                     unit.changeBugText(e, context);
                     throw e;
-                } catch (NoClassDefFoundError | Exception e) {
-                    // effort to get more logging in case a dependency of a class is loaded
-                    // although it shouldn't have
-                    unit.convertUncaughtExceptionToCompilationError(e);
+                } catch (Exception | LinkageError e) {
+                    ErrorCollector errorCollector = null;
+                    // check for a nested compilation exception
+                    for (Throwable t = e.getCause(); t != e && t != null; t = t.getCause()) {
+                        if (t instanceof MultipleCompilationErrorsException) {
+                            errorCollector = ((MultipleCompilationErrorsException) t).getErrorCollector();
+                            break;
+                        }
+                    }
+
+                    if (errorCollector != null) {
+                        unit.getErrorCollector().addCollectorContents(errorCollector);
+                    } else if (context != null) {
+                        unit.getErrorCollector().addException(e instanceof Exception ? (Exception) e : new RuntimeException(e), context);
+                    } else {
+                        unit.getErrorCollector().addError(new ExceptionMessage(e instanceof Exception ? (Exception) e : new RuntimeException(e), unit.debug, unit));
+                    }
                 }
             }
             unit.getErrorCollector().failIfErrors();
@@ -1035,24 +1048,6 @@ public class CompilationUnit extends ProcessingUnit {
         return sorted;
     }
 
-    private void convertUncaughtExceptionToCompilationError(final Throwable e) {
-        ErrorCollector nestedCollector = null;
-        // check the exception for a nested compilation exception
-        for (Throwable next = e.getCause(); next != e && next != null; next = next.getCause()) {
-            if (!(next instanceof MultipleCompilationErrorsException)) continue;
-            MultipleCompilationErrorsException mcee = (MultipleCompilationErrorsException) next;
-            nestedCollector = mcee.collector;
-            break;
-        }
-
-        if (nestedCollector != null) {
-            getErrorCollector().addCollectorContents(nestedCollector);
-        } else {
-            Exception err = e instanceof Exception?((Exception)e):new RuntimeException(e);
-            getErrorCollector().addError(new ExceptionMessage(err, debug, this));
-        }
-    }
-
     private void changeBugText(final GroovyBugError e, final SourceUnit context) {
         e.setBugText("exception in phase '" + getPhaseDescription() + "' in source unit '" + (context != null ? context.getName() : "?") + "' " + e.getBugText());
     }
diff --git a/src/main/java/org/codehaus/groovy/control/messages/ExceptionMessage.java b/src/main/java/org/codehaus/groovy/control/messages/ExceptionMessage.java
index 57c92fb..cd7621f 100644
--- a/src/main/java/org/codehaus/groovy/control/messages/ExceptionMessage.java
+++ b/src/main/java/org/codehaus/groovy/control/messages/ExceptionMessage.java
@@ -22,36 +22,34 @@ import org.codehaus.groovy.control.Janitor;
 import org.codehaus.groovy.control.ProcessingUnit;
 
 import java.io.PrintWriter;
+import java.util.Objects;
 
 /**
  * A class for error messages produced by the parser system.
  */
 public class ExceptionMessage extends Message {
-    protected boolean verbose = true;
 
-    private Exception cause = null;   // The exception source of the message, if any
-    ProcessingUnit owner = null;
+    private final Exception cause;
+    protected final boolean debug;
+    protected final ProcessingUnit owner;
 
-    public ExceptionMessage(Exception cause, boolean v, ProcessingUnit owner) {
-        this.verbose = v;
-        this.cause = cause;
+    public ExceptionMessage(final Exception cause, final boolean debug, final ProcessingUnit owner) {
+        this.cause = Objects.requireNonNull(cause);
+        this.debug = debug;
         this.owner = owner;
     }
 
     /**
      * Returns the underlying Exception.
      */
-
     public Exception getCause() {
-        return this.cause;
+        return cause;
     }
 
-
     /**
      * Writes out a nicely formatted summary of the exception.
      */
-
-    public void write(PrintWriter output, Janitor janitor) {
+    public void write(final PrintWriter output, final Janitor janitor) {
         String description = "General error during " + owner.getPhaseDescription() + ": ";
 
         String message = cause.getMessage();
@@ -62,12 +60,6 @@ public class ExceptionMessage extends Message {
         }
         output.println();
 
-        //if (verbose) {
-        cause.printStackTrace(output);
-        //}
+        /*if (debug)*/ cause.printStackTrace(output);
     }
-
 }
-
-
-


[groovy] 03/03: GROOVY-9361: Bump jackson-dataformat-yaml to 2.10.2

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 4bd73a291aea0fa7c72de5f964dbb16adadf72dd
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Jan 11 02:55:02 2020 +0800

    GROOVY-9361: Bump jackson-dataformat-yaml to 2.10.2
    
    (cherry picked from commit 55b8bd1773a9380cd602952fb6735676d1e93319)
---
 subprojects/groovy-yaml/build.gradle | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/subprojects/groovy-yaml/build.gradle b/subprojects/groovy-yaml/build.gradle
index 239cb20..e7cdee6 100644
--- a/subprojects/groovy-yaml/build.gradle
+++ b/subprojects/groovy-yaml/build.gradle
@@ -18,7 +18,7 @@
  */
 
 ext {
-    jacksonVersion = '2.10.1'
+    jacksonVersion = '2.10.2'
 }
 
 dependencies {