Upgrading from Groovy 1.7.x to 1.8.x: MissingPropertyException: No such property: for class:

Just jotting this down for anyone that might encounter this problem.

Apparently Groovy 1.8 introduced a backwards-incompatible language syntax change. It cropped up for me while I was attempting to compile existing Groovy unit tests (written against Groovy 1.7.x) that use EasyMock. I’ll show an example next – just note that that what I experienced was due to a Groovy syntax issue and not specific to EasyMock.

In a test case, I had a bit of code that looked like this:

expect(mock.someMethod(...)).andAnswer new IAnswer<Whatever>() {
    //bunch of stuff left out for brevity
}

Notice how the method argument to the anAnswer method is an anonymous inner class that spans multiple lines. Also notice that I didn’t wrap the argument in parenthesis as they are usually optional in Groovy. That is, instead of doing this:

someMethod.doSomething( anArg )

I usually do this:

someMethod.doSomething anArg

I find it to be more readable and less to type.

This worked fine with an anonymous inner class that spanned multiple lines in Groovy 1.7. This will not work in Groovy 1.8.x. When upgrading to Groovy 1.8.0 that same exact code threw an exception:

groovy.lang.MissingPropertyException: No such property: andAnswer for class: org.easymock.internal.MocksControl

Not nice. The ‘no such property’ error was a little misleading, but helpful – it told me Groovy thought andAnswer was a property – not a method. So, I decided to throw some parenthesis in there to indicate that it was in fact a method. The code then became:

expect(mock.someMethod(...)).andAnswer( new IAnswer<Whatever>() {
    //bunch of stuff left out for brevity
})

Notice the new opening parenthesis after andAnswer and the closing one after the anonymous inner class’s final } bracket. A very subtle difference!

After doing this, all of my test code compiled again. I hope this helps anyone with a similar problem!

One thought on “Upgrading from Groovy 1.7.x to 1.8.x: MissingPropertyException: No such property: for class:”

  1. Hi Les,

    I had a similar problem when upgrading from 1.7.x to 1.8.x. – incredible. But I solved it, by downgrading to Groovy 1.7.

    Thanks a lot for your article.

    Marcus

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>