Skip to content

Commit ec29d9c

Browse files
committed
Remove unnecessary error handling code, which is already handled by Groovy MetaClassImpl.
1 parent f9eec57 commit ec29d9c

File tree

2 files changed

+4
-66
lines changed

2 files changed

+4
-66
lines changed

spock-core/src/main/java/org/spockframework/mock/runtime/GroovyRealGetPropertyInvoker.java

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
*/
3131
@ThreadSafe
3232
public class GroovyRealGetPropertyInvoker extends GroovyRealMethodInvoker {
33-
static final String STATIC_PROPERTY_MISSING = "$static_propertyMissing";
34-
private static final Class<?>[] GETTER_MISSING_ARGS = {String.class};
35-
3633
private final MetaClass metaClass;
3734
private final Class<?> sender;
3835
private final String property;
@@ -57,37 +54,9 @@ public Object respond(IMockInvocation invocation) {
5754
try {
5855
return metaClass.getProperty(sender, receiver, property, useSuper, fromInsideClass);
5956
} catch (InvokerInvocationException | MissingMethodException e2) {
60-
try {
61-
return handleMissingProperty(receiver, property);
62-
} catch (MissingPropertyException e3) {
63-
e3.addSuppressed(e2);
64-
e3.addSuppressed(e1);
65-
throw e3;
57+
e2.addSuppressed(e1);
58+
throw e2;
6659
}
6760
}
6861
}
69-
}
70-
71-
private Object handleMissingProperty(Object target, String property) {
72-
//https://issues.apache.org/jira/browse/GROOVY-11781
73-
//Since Groovy 5: Groovy uses getProperty() and setProperty() for field access of outer classes.
74-
//So we need to implement the "property missing" workflow from MetaClassImpl.getProperty().
75-
if (isTargetStatic(target)) {
76-
return invokeStaticMissingProperty(target, property);
77-
}
78-
79-
return metaClass.invokeMissingProperty(target, property, null, true);
80-
}
81-
82-
private Object invokeStaticMissingProperty(Object target, String property) {
83-
MetaMethod propertyMissing = metaClass.getMetaMethod(STATIC_PROPERTY_MISSING, GETTER_MISSING_ARGS);
84-
if (propertyMissing != null) {
85-
return propertyMissing.invoke(target, new Object[]{property});
86-
}
87-
throw new MissingPropertyException(property, (Class<?>) target);
88-
}
89-
90-
private boolean isTargetStatic(Object target) {
91-
return target instanceof Class && metaClass.getTheClass() != Class.class;
92-
}
9362
}

spock-core/src/main/java/org/spockframework/mock/runtime/GroovyRealSetPropertyInvoker.java

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
*/
3131
@ThreadSafe
3232
public 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

Comments
 (0)