groovy
  1. groovy
  2. GROOVY-3412

Method Caching within MethodMissiing is not working

    Details

    • Type: Bug Bug
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.6
    • Fix Version/s: 3.0
    • Component/s: groovy-jdk
    • Labels:
      None
    • Environment:
      Ubuntu Linux, JDK 1.6, Eclipse 3.4
    • Number of attachments :
      0

      Description

      The following code attempts to cache a method call within the methodMissing method, however in groovy 1.6, when the method is called for a second time the cached version is not being used. This code works fine in 1.5.7.

      class PersonAgain
      {
      	def work() { "working..." }
      	def plays = ['Tennis', 'VolleyBall', 'BasketBall']
      	def methodMissing(String name, args)
      	{
      		System.out.println "methodMissing called for $name"
      		def methodInList = plays.find {it == name.split('play')[1] }
      		if(methodInList)
      		{
      			def impl = { Object[] vargs ->
      				return "playing ${name.split('play')[1]}..."
      			}
      			
      			PersonAgain.metaClass."$name" = impl
      			return impl(args)
      		}
      		else
      		{
      			throw new MissingMethodException(name, PersonAgain.class, args)
      		}
      	}
      	static { PersonAgain.metaClass }
      }
      
      jack = new PersonAgain()
      println jack.playTennis()
      println jack.playTennis()
      

        Activity

        No work has yet been logged on this issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            James Parkin
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: