Skip to content

Commit 54c7862

Browse files
committed
groovy Utils.toMap() manage GroovyCastException
1 parent 58d233a commit 54c7862

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

groovy/src/main/groovy/org/jline/groovy/Utils.groovy

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002-2020, the original author or authors.
2+
* Copyright (c) 2002-2021, the original author or authors.
33
*
44
* This software is distributable under the BSD license. See the terms of the
55
* BSD license in the documentation provided with this software.
@@ -9,6 +9,7 @@
99
package org.jline.groovy
1010

1111
import org.codehaus.groovy.runtime.HandleMetaClass
12+
import org.codehaus.groovy.runtime.typehandling.GroovyCastException
1213

1314
import java.nio.file.Path
1415
import org.jline.script.GroovyEngine.Format
@@ -37,13 +38,18 @@ class Utils {
3738
}
3839

3940
static Map<String,Object> toMap(Object object) {
40-
def out = [:]
41-
if (object instanceof Closure) {
42-
out['closure'] = object.getClass().getName()
43-
} else if (object instanceof HandleMetaClass) {
44-
out['object'] = object.toString()
45-
} else {
46-
out = object != null ? object.properties : null
41+
Map<String,Object> out = [:]
42+
try {
43+
if (object instanceof Closure) {
44+
out['closure'] = object.getClass().getName()
45+
} else if (object instanceof HandleMetaClass) {
46+
out['HandleMetaClass'] = object.toString()
47+
} else {
48+
out = object != null ? object.properties : null
49+
}
50+
return out
51+
} catch (GroovyCastException e) {
52+
out[object.getClass().getSimpleName()] = object.toString()
4753
}
4854
out
4955
}

0 commit comments

Comments
 (0)