3030 */
3131@ ThreadSafe
3232public class GroovyRealSetPropertyInvoker extends GroovyRealMethodInvoker {
33- private static final Class <?>[] SETTER_MISSING_ARGS = {String .class , Object .class };
34-
3533 private final MetaClass metaClass ;
3634 private final Class <?> sender ;
3735 private final String property ;
@@ -58,38 +56,9 @@ public Object respond(IMockInvocation invocation) {
5856 metaClass .setProperty (sender , receiver , property , newValue , useSuper , fromInsideClass );
5957 return null ;
6058 } catch (InvokerInvocationException | MissingMethodException e2 ) {
61- try {
62- return handleMissingProperty (receiver , property , newValue );
63- } catch (MissingPropertyException e3 ) {
64- e3 .addSuppressed (e2 );
65- e3 .addSuppressed (e1 );
66- throw e3 ;
59+ e2 .addSuppressed (e1 );
60+ throw e2 ;
6761 }
68- }
69- }
70- }
71-
72- private Object handleMissingProperty (Object target , String property , Object newValue ) {
73- //https://issues.apache.org/jira/browse/GROOVY-11781
74- //Since Groovy 5: Groovy uses getProperty() and setProperty() for field access of outer classes.
75- //So we need to implement the "property missing" workflow from MetaClassImpl.getProperty().
76- if (isTargetStatic (target )) {
77- return invokeStaticMissingProperty (target , property , newValue );
78- }
79-
80- return metaClass .invokeMissingProperty (target , property , newValue , false );
81- }
82-
83- private Object invokeStaticMissingProperty (Object target , String property , Object newValue ) {
84- MetaMethod propertyMissing = metaClass .getMetaMethod (GroovyRealGetPropertyInvoker .STATIC_PROPERTY_MISSING , SETTER_MISSING_ARGS );
85- if (propertyMissing != null ) {
86- return propertyMissing .invoke (target , new Object []{property , newValue });
8762 }
88-
89- throw new MissingPropertyException (property , (Class <?>) target );
90- }
91-
92- private boolean isTargetStatic (Object target ) {
93- return target instanceof Class && metaClass .getTheClass () != Class .class ;
9463 }
9564}
0 commit comments