Grails
  1. Grails
  2. GRAILS-8273

Casting enum.values() to Set causes InstantiationException

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-RC1, 2.0 final
    • Fix Version/s: 2.0.2, 2.1-RC1
    • Component/s: Converters
    • Labels:
    • Environment:
      Tested on OSX
    • Testcase included:
      yes

      Description

      In a fresh grails application the following integration test fails. Casting to other collection types seems to work fine. This issue does not occur in a unit test, but does occur in integration tests and at runtime.

      class TempIntegrationTest extends GrailsUnitTestCase {

      enum MyEnum

      { FOO, BAR }

      void testToSet()

      { MyEnum.values() as Set //Throws Exception }

      }

        Activity

        Hide
        John Engelman added a comment -

        Doesn't appear to be related to Groovy, I've tested the following block under Groovy 1.7.6, 1.8.2, and 1.8.4 (using groovyConsole) and Grails 1.3.6 (grails console)

        enum Bar {
           FOO1,
           FOO2,
        }
        
        Bar.values() as Set
        

        Running the same block under a Grails 2.0.0 Final console (grails console), I get the following stack trace:
        org.codehaus.groovy.runtime.typehandling.GroovyCastException: Could not instantiate instance of: java.util.Set. Reason: java.lang.InstantiationException: java.util.Set
        at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:224)
        at org.codehaus.groovy.runtime.DefaultGroovyMethods.asType(DefaultGroovyMethods.java:17582)
        at org.codehaus.groovy.grails.web.converters.ConverterUtil.invokeOriginalAsTypeMethod(ConverterUtil.java:153)
        at org.codehaus.groovy.grails.plugins.converters.api.ConvertersApi.asType(ConvertersApi.java:45)
        at sun.reflect.GeneratedMethodAccessor208.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.groovy.runtime.metaclass.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:51)
        at org.codehaus.groovy.grails.commons.metaclass.BaseApiProvider$1.invoke(BaseApiProvider.java:83)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1054)
        at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1110)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:884)
        at org.codehaus.groovy.runtime.InvokerHelper.invokePojoMethod(InvokerHelper.java:781)
        at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:772)
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:164)
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.asType(ScriptBytecodeAdapter.java:587)
        at ConsoleScript0.run(ConsoleScript0:6)
        at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:266)
        at groovy.lang.GroovyShell.run(GroovyShell.java:517)
        at groovy.lang.GroovyShell.run(GroovyShell.java:172)
        at groovy.lang.GroovyShell$run.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
        at groovy.ui.Console$_runScriptImpl_closure16.doCall(Console.groovy:924)
        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.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:226)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:52)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
        at groovy.ui.Console$_runScriptImpl_closure16.doCall(Console.groovy)
        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.reflection.CachedMethod.invoke(CachedMethod.java:90)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1054)
        at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1110)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:884)
        at groovy.lang.Closure.call(Closure.java:410)
        at groovy.lang.Closure.call(Closure.java:404)
        at groovy.lang.Closure.run(Closure.java:488)
        at java.lang.Thread.run(Thread.java:680)

        Show
        John Engelman added a comment - Doesn't appear to be related to Groovy, I've tested the following block under Groovy 1.7.6, 1.8.2, and 1.8.4 (using groovyConsole) and Grails 1.3.6 (grails console) enum Bar { FOO1, FOO2, } Bar.values() as Set Running the same block under a Grails 2.0.0 Final console (grails console), I get the following stack trace: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Could not instantiate instance of: java.util.Set. Reason: java.lang.InstantiationException: java.util.Set at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:224) at org.codehaus.groovy.runtime.DefaultGroovyMethods.asType(DefaultGroovyMethods.java:17582) at org.codehaus.groovy.grails.web.converters.ConverterUtil.invokeOriginalAsTypeMethod(ConverterUtil.java:153) at org.codehaus.groovy.grails.plugins.converters.api.ConvertersApi.asType(ConvertersApi.java:45) at sun.reflect.GeneratedMethodAccessor208.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.groovy.runtime.metaclass.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:51) at org.codehaus.groovy.grails.commons.metaclass.BaseApiProvider$1.invoke(BaseApiProvider.java:83) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1054) at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1110) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:884) at org.codehaus.groovy.runtime.InvokerHelper.invokePojoMethod(InvokerHelper.java:781) at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:772) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:164) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.asType(ScriptBytecodeAdapter.java:587) at ConsoleScript0.run(ConsoleScript0:6) at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:266) at groovy.lang.GroovyShell.run(GroovyShell.java:517) at groovy.lang.GroovyShell.run(GroovyShell.java:172) at groovy.lang.GroovyShell$run.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124) at groovy.ui.Console$_runScriptImpl_closure16.doCall(Console.groovy:924) 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.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:226) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:52) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141) at groovy.ui.Console$_runScriptImpl_closure16.doCall(Console.groovy) 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.reflection.CachedMethod.invoke(CachedMethod.java:90) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1054) at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1110) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:884) at groovy.lang.Closure.call(Closure.java:410) at groovy.lang.Closure.call(Closure.java:404) at groovy.lang.Closure.run(Closure.java:488) at java.lang.Thread.run(Thread.java:680)
        Hide
        Jeff Scott Brown added a comment -

        I don't think the problem is limited to enum values. I think the problem relates to any time you try to convert an object array using the "as" operator (the enum's .values() method returns an array). In any case, I think we have it fixed now.

        Show
        Jeff Scott Brown added a comment - I don't think the problem is limited to enum values. I think the problem relates to any time you try to convert an object array using the "as" operator (the enum's .values() method returns an array). In any case, I think we have it fixed now.

          People

          • Assignee:
            Jeff Scott Brown
            Reporter:
            Shaun Jurgemeyer
          • Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development