Index: src/main/org/codehaus/groovy/runtime/wrappers/GroovyObjectWrapper.java =================================================================== --- src/main/org/codehaus/groovy/runtime/wrappers/GroovyObjectWrapper.java (revision 20234) +++ src/main/org/codehaus/groovy/runtime/wrappers/GroovyObjectWrapper.java (working copy) @@ -62,6 +62,13 @@ } /* (non-Javadoc) + * @see groovy.lang.GroovyObject#getMetaClass() + */ + public MetaClass getMetaClass() { + return this.wrapped.getMetaClass(); + } + + /* (non-Javadoc) * @see groovy.lang.GroovyObject#setProperty(java.lang.String, java.lang.Object) */ public void setProperty(final String property, final Object newValue) { Index: src/test/groovy/bugs/Groovy4241Bug.groovy =================================================================== --- src/test/groovy/bugs/Groovy4241Bug.groovy (revision 0) +++ src/test/groovy/bugs/Groovy4241Bug.groovy (revision 0) @@ -0,0 +1,22 @@ +package groovy.bugs + +class Groovy4241Bug extends GroovyTestCase { + void testAsTypeWithinvokeMethodOverridden() { + Foo4241.metaClass.invokeMethod = { String name, args -> + println name + for (arg in args) { + println arg.getClass() + } + } + def f = new Foo4241() + + def bar = [key: 'foo'] as Bar4241 + f.echo(bar) // this used to work + + f.echo([key: 'foo'] as Bar4241) // this used to fail with NPE + } +} + +class Foo4241 {} + +class Bar4241 {}