Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-6584

Cannot use memoize() to cache metaclass method call

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.2.1
    • 2.4.8
    • groovy-runtime
    • None

    Description

      Hi I want to extend my list with new method and cache the result because actually it will query db but I am getting 'java.lang.UnsupportedOperationException', I reproduced it for simple case also using groovy console

      def lst = []
      lst.metaClass.getTotalCount = {
          println ">>>>>>>>>> 12 <<<<<<<<<<"
          12 // can be some select count(*) from xxx
      }.memoize()
      
      println lst.getTotalCount()
      println lst.getTotalCount()
      

      I am getting

      java.lang.UnsupportedOperationException: org.codehaus.groovy.runtime.metaclass.ClosureMetaMethod$AnonymousMetaMethod
      	at ConsoleScript10.run(ConsoleScript10:2)
      
      

      Attachments

        Issue Links

          Activity

            People

              jwagenleitner John Wagenleitner
              armsargis Sargis Harutyunyan
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: