Search code examples
grailsgroovy

groovy.lang.MissingMethodException: No signature of method: com.x.License.add() is applicable for argument types: (com.x.License) values


I'm using a scheduled job to retrieve the licenses every so often. When I retrieve the licenses for each license I want to add that license to a hashmap per account. In the hashmap I have an Account and a list of Licenses. For each license I try to check if there already is a list of Licenses in the hashmap, if there isn't I make a new list and that works fine. But if there is a list I try to add it to that list and that where it throws an error for some reason

licenses.each{license->
        List<License> licensesPerAccount =  accountLicenseMap.get(license.account)
        log.info("initial licenseperaccount " + licensesPerAccount)
        if(licensesPerAccount == null) {
            accountLicenseMap.put(license.account, license as List<License>)
        } else{
            log.info("licenseperaccount in else is " + licensesPerAccount)
            licensesPerAccount.push(license)
            log.info("licenseperaccount now is " + licensesPerAccount)
            accountLicenseMap.put(license.account, licensesPerAccount)
        }
    }

This is the error it throws:

ERROR 2017-12-27 10:12:59,045 grails.plugins.quartz.listeners.ExceptionPrinterJobListener - Exception occurred in job: Grails Job org.quartz.JobExecutionException: groovy.lang.MissingMethodException: No signature of method: com.x.License.add() is applicable for argument types: (com.x.License) values: [com.x.License : 10] Possible solutions: any(), find(com.x.License), any(groovy.lang.Closure), wait(), last(), save() at grails.plugins.quartz.GrailsJobFactory$GrailsJob.execute(GrailsJobFactory.java:111) at org.quartz.core.JobRunShell.run(JobRunShell.java:202) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) Caused by: groovy.lang.MissingMethodException: No signature of method: com.x.License.add() is applicable for argument types: (com.x.License) values: [com.x.License : 10] Possible solutions: any(), find(com.x.License), any(groovy.lang.Closure), wait(), last(), save() at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoMetaMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:253) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:71) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) at com.x.NewLicenseJob$_execute_closure1$$EQezpeTI.doCall(NewLicenseJob.groovy:32) at sun.reflect.GeneratedMethodAccessor629.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.springsource.loaded.ri.ReloadedTypeInvoker$2.invoke(ReloadedTypeInvoker.java:133) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1461) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1021) at groovy.lang.Closure.call(Closure.java:426) at com.x.NewLicenseJob$_execute_closure1.call(NewLicenseJob.groovy) at groovy.lang.Closure.call(Closure.java:442) at com.x.NewLicenseJob$_execute_closure1.call(NewLicenseJob.groovy) at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2030) at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2015) at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2056) at org.codehaus.groovy.runtime.dgm$162.invoke(Unknown Source) at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:274) at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) at com.x.NewLicenseJob$$EQezpeT2.execute(NewLicenseJob.groovy:25) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.springsource.loaded.ri.ReloadedTypeInvoker$2.invoke(ReloadedTypeInvoker.java:133) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1461) at grails.plugins.quartz.GrailsJobFactory$GrailsJob.execute(GrailsJobFactory.java:104) ... 2 common frames omitted

And this is what it logs:

INFO 2017-12-27 10:12:59,029 grails.app.jobs.com.x.NewLicenseJob - initial licenseperaccount null Hibernate: select account0_.id as id1_4_0_, account0_.approve_hours_by_manager as approve_2_4_0_, account0_.brand_id as brand_id3_4_0_, account0_.check_tags as check_ta4_4_0_, account0_.checkin_at_work_module as checkin_5_4_0_, account0_.cj1_export as cj6_4_0_, account0_.company_id as company_7_4_0_, account0_.csv_import as csv_impo8_4_0_, account0_.default_date_pattern as default_9_4_0_, account0_.default_date_time_pattern as default10_4_0_, account0_.default_time_pattern as default11_4_0_, account0_.default_time_zone as default12_4_0_, account0_.default_view as default13_4_0_, account0_.deleted as deleted14_4_0_, account0_.display_as_decimal as display15_4_0_, account0_.instant_feedback as instant16_4_0_, account0_.language as languag17_4_0_, account0_.match_registration_hours as match_r18_4_0_, account0_.payroll_hours as payroll19_4_0_, account0_.project_tags as project20_4_0_, account0_.separate_date as separat21_4_0_, account0_.show_charts as show_ch22_4_0_, account0_.templa_link as templa_23_4_0_, account0_.vip_export as vip_exp24_4_0_ from account account0_ where account0_.id=? Hibernate: select company0_.id as id1_14_0_, company0_.account_id as account_2_14_0_, company0_.address as address3_14_0_, company0_.city as city4_14_0_, company0_.cocnumber as cocnumbe5_14_0_, company0_.country as country6_14_0_, company0_.deleted as deleted7_14_0_, company0_.emailaddress as emailadd8_14_0_, company0_.logo_url as logo_url9_14_0_, company0_.name as name10_14_0_, company0_.phonenumber as phonenu11_14_0_, company0_.province as provinc12_14_0_, company0_.vatnumber as vatnumb13_14_0_, company0_.website as website14_14_0_, company0_.zipcode as zipcode15_14_0_ from company company0_ where company0_.id=? INFO 2017-12-27 10:12:59,045 grails.app.jobs.com.x.NewLicenseJob - initial licenseperaccount null INFO 2017-12-27 10:12:59,045 grails.app.jobs.com.x.NewLicenseJob - initial licenseperaccount [com.x.License : 9] INFO 2017-12-27 10:12:59,045 grails.app.jobs.com.x.NewLicenseJob - licenseperaccount in else is [com.x.License : 9]


Solution

  • I fixed it by creating the list as follows:

    List<License> licenseList = []
                licenseList << license
                accountLicenseMap.put(license.account, licenseList)
    

    Instead of doing accountLicenseMap.put(license.account, license as List<License>)