From 629affca1ca9b073c8495276e0fe7c8051913676 Mon Sep 17 00:00:00 2001 From: Maurus Cuelenaere Date: Mon, 24 Dec 2012 00:38:33 +0100 Subject: [PATCH] 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. --- .../codegen/AbstractEvaluatorFactory.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/mysema/codegen/AbstractEvaluatorFactory.java b/src/main/java/com/mysema/codegen/AbstractEvaluatorFactory.java index b70279bd2..faed3055d 100644 --- a/src/main/java/com/mysema/codegen/AbstractEvaluatorFactory.java +++ b/src/main/java/com/mysema/codegen/AbstractEvaluatorFactory.java @@ -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 constants) { StringBuilder b = new StringBuilder(128); b.append("Q");