GROOVY-7563: InvokerHelper: Safe formatting of ranges

Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/9be00f21
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/9be00f21
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/9be00f21

Branch: refs/heads/master
Commit: 9be00f218b56739fa6b850136f83abf024d5f44b
Parents: 56904d6
Author: Thibault Kruse <thibault.kr...@gmx.de>
Authored: Wed Sep 2 19:40:55 2015 +0200
Committer: paulk <pa...@asert.com.au>
Committed: Fri Jul 29 08:36:47 2016 +1000

----------------------------------------------------------------------
 .../org/codehaus/groovy/runtime/InvokerHelper.java  | 16 ++++++++++++----
 .../runtime/InvokerHelperFormattingTest.groovy      |  2 ++
 2 files changed, 14 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/9be00f21/src/main/org/codehaus/groovy/runtime/InvokerHelper.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/InvokerHelper.java 
b/src/main/org/codehaus/groovy/runtime/InvokerHelper.java
index 17f7ca9..199ed74 100644
--- a/src/main/org/codehaus/groovy/runtime/InvokerHelper.java
+++ b/src/main/org/codehaus/groovy/runtime/InvokerHelper.java
@@ -593,10 +593,18 @@ public class InvokerHelper {
         }
         if (arguments instanceof Range) {
             Range range = (Range) arguments;
-            if (verbose) {
-                return range.inspect();
-            } else {
-                return range.toString();
+            try {
+                if (verbose) {
+                    return range.inspect();
+                } else {
+                    return range.toString();
+                }
+            } catch (RuntimeException ex) {
+                if (!safe) throw ex;
+                return handleFormattingException(arguments, ex);
+            } catch (Exception ex) {
+                if (!safe) throw new GroovyRuntimeException(ex);
+                return handleFormattingException(arguments, ex);
             }
         }
         if (arguments instanceof Collection) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/9be00f21/src/test/org/codehaus/groovy/runtime/InvokerHelperFormattingTest.groovy
----------------------------------------------------------------------
diff --git 
a/src/test/org/codehaus/groovy/runtime/InvokerHelperFormattingTest.groovy 
b/src/test/org/codehaus/groovy/runtime/InvokerHelperFormattingTest.groovy
index 4e55623..3e87770 100644
--- a/src/test/org/codehaus/groovy/runtime/InvokerHelperFormattingTest.groovy
+++ b/src/test/org/codehaus/groovy/runtime/InvokerHelperFormattingTest.groovy
@@ -92,6 +92,8 @@ class InvokerHelperFormattingTest extends GroovyTestCase {
         shouldFail(UnsupportedOperationException) {
             InvokerHelper.format(eObject..eObject2)
         }
+
+        assert InvokerHelper.format(eObject..eObject, false, -1, true) == 
'<groovy.lang.ObjectRange@????>'
     }
 
     public void testToStringLists() {

Reply via email to