Fix regression: wrong method chosen as evaluator

Some Java instrumentation tools (e.g. JaCoCo) insert code into classes at
runtime. This means that the static eval() method *could* not be the first
method of our runtime generated classes anymore.

Fix this by explicitly looking for the eval() method.
This commit is contained in:
Maurus Cuelenaere 2012-12-24 00:38:33 +01:00
parent dd37b94ff9
commit 629affca1c

View File

@ -129,7 +129,7 @@ public abstract class AbstractEvaluatorFactory implements EvaluatorFactory {
// reload
clazz = loader.loadClass(id);
}
method = clazz.getDeclaredMethods()[0];
method = findEvalMethod(clazz);
cache.put(id, method);
}
@ -143,6 +143,26 @@ public abstract class AbstractEvaluatorFactory implements EvaluatorFactory {
}
}
protected Method findEvalMethod(Class<?> clazz) {
/*
* Note 1:
* Some Java instrumentation tools (e.g. JaCoCo) insert code into
* classes at runtime. This means that the static eval() method *could*
* not be the first method of our runtime generated classes anymore.
*
* Note 2:
* We can't use clazz.getDeclaredMethod(name, classes), as the argument
* types of the eval() method could be normalized (see createSource()).
*/
for (Method method : clazz.getDeclaredMethods()) {
if ("eval".equals(method.getName())) {
return method;
}
}
throw new IllegalArgumentException("Couldn't find eval method!");
}
protected String toId(String source, Class<?> returnType, Type[] types, Collection<Object> constants) {
StringBuilder b = new StringBuilder(128);
b.append("Q");