[
https://issues.apache.org/jira/browse/GROOVY-11781?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18029207#comment-18029207
]
Eric Milles commented on GROOVY-11781:
--------------------------------------
GroovyMockMetaClass#getProperty could implement the "property missing" flow
that can be seen at the end of MetaClassImpl#getProperty. setProperty would
require similar treatment.
{code:java}
public Object getProperty(Object target, String property) {
String methodName =
GroovyRuntimeUtil.propertyToBooleanGetterMethodName(property);
MetaMethod metaMethod = delegate.getMetaMethod(methodName,
GroovyRuntimeUtil.EMPTY_ARGUMENTS);
if (metaMethod == null || metaMethod.getReturnType() != boolean.class) {
methodName = GroovyRuntimeUtil.propertyToGetterMethodName(property);
}
try {
return invokeMethod(target, methodName,
GroovyRuntimeUtil.EMPTY_ARGUMENTS);
} catch (org.codehaus.groovy.runtime.InvokerInvocationException |
MissingMethodException e) {
if (target instanceof Class && delegate.getTheClass() != Class.class) {
MetaMethod propertyMissing =
delegate.getMetaMethod("$static_propertyMissing", new Class[]{String.class});
if (propertyMissing != null) {
return propertyMissing.invoke(target, new Object[]{property});
}
throw new MissingPropertyException(property, (Class<?>) target);
}
return invokeMissingProperty(target, property, null, true);
}
}
{code}
With this, AbstractClassA can dispatch a property request to its outer class.
To get the instance test to work, GroovyMockInterceptor#intercept needs to pass
propertyMissing along. I just commented out the throw.
The missingMethod sequence should work, in which case you would get
MissingMethodException instead of InvokerInvocationException.
> static field access to outer class does not work properly anymore
> -----------------------------------------------------------------
>
> Key: GROOVY-11781
> URL: https://issues.apache.org/jira/browse/GROOVY-11781
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 5.0.1
> Reporter: Björn Kautler
> Priority: Major
>
> This is a regression in Groovy 5.
> Groovy 2.5, 3.0, and 4.0 it works fine.
> To reproduce:
> * checkout my {{groovy5}} PR branch of
> [https://github.com/spockframework/spock/pull/2213]
> * go to
> {{org.spockframework.smoke.mock.GroovyMockAbstractGlobalClass.AbstractClassA}}
> * replace the three {{GroovyMockAbstractGlobalClass.NAME}} by just {{NAME}}
> * execute {{./gradlew -Dvariant=5.0 -DjavaVersion=11 :spock-specs:test
> --tests org.spockframework.smoke.mock.GroovyMockAbstractGlobalClass --info}}
> As a result you get an `IllegalArgumentException` with message `object is not
> an instance of declaring class`.
> I'm not 100% sure whether this is a Groovy bug or Spock bug, but it works
> fine up to and including Groovy 4.
> If this is not a Groovy bug but a Spock bug, I'd appreciate very much help in
> how to resolve this on the Spock side.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)