Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.7.10, 1.8.0
-
None
-
None
-
Patch
Description
toString() and other methods that are expected to be on Object should not generate an UnsupportedOperationException when using the Proxy pattern in groovy. Many methods expect non-null objects to allow methods that exist on Object to be called without issue. The example below should throw a MissingMethodException with a nice message that includes the method name and the arguments that were called, but since MissingMethodException.getMessage() calls the proxy's toString() method we get an UnsupportedOperationException on toString() instead, as well as a stack trace that originates from the location that the MissingMethodException's getMessage() is being called, obscuring the actual problem entirely.
interface A { def getValue() } class B { } def test = [ getValue: { 'getValue() called' } ] as A def b = new B() b.call(test)
Stack trace from 1.8.0:
java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108) at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) Caused by: java.lang.UnsupportedOperationException at org.codehaus.groovy.runtime.ConvertedMap.invokeCustom(ConvertedMap.java:46) at org.codehaus.groovy.runtime.ConversionHandler.invoke(ConversionHandler.java:82) at $Proxy4.toString(Unknown Source) at org.codehaus.groovy.runtime.InvokerHelper.format(InvokerHelper.java:550) at org.codehaus.groovy.runtime.InvokerHelper.format(InvokerHelper.java:504) at org.codehaus.groovy.runtime.InvokerHelper.toArrayString(InvokerHelper.java:689) at org.codehaus.groovy.runtime.InvokerHelper.toString(InvokerHelper.java:109) at groovy.lang.MissingMethodException.getMessage(MissingMethodException.java:55) at java.lang.Throwable.getLocalizedMessage(Throwable.java:267) at java.lang.Throwable.toString(Throwable.java:343) at java.lang.String.valueOf(String.java:2826) at java.lang.StringBuilder.append(StringBuilder.java:115) at groovy.ui.GroovyMain.run(GroovyMain.java:340) at groovy.ui.GroovyMain.process(GroovyMain.java:315) at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112) at groovy.ui.GroovyMain.main(GroovyMain.java:93) ... 6 more