Apache Lucene open-source search software
LUCENE-5207: More strict checks for invalid method signatures (currently only double is accepted as parameter or return type). The method must be static, too.
Uwe Schindlera62a5ce2ad42
diff --git a/lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptFunction.java b/lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptFunction.javaindex 9255c68174f..1f97c6f5558 100644--- a/lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptFunction.java+++ b/lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptFunction.java@@ -19,6 +19,7 @@ package org.apache.lucene.expressions.js;import java.util.HashMap;import java.util.Map;import java.lang.reflect.Method;+import java.lang.reflect.Modifier;import org.apache.lucene.util.MathUtil;import org.objectweb.asm.Type;@@ -86,8 +87,23 @@ class JavascriptFunction {public final String signature;private JavascriptFunction(String call, Method method) {+ // do some checks if the signature is "compatible":+ if (!Modifier.isStatic(method.getModifiers())) {+ throw new Error(method + " is not static.");+ }+ if (method.getReturnType() != double.class) {+ throw new Error(method + " does not return a double.");+ }++ final Class<?>[] paramTypes = method.getParameterTypes();+ for (final Class<?> paramType : paramTypes) {+ if (paramType != double.class) {+ throw new Error(method + " may only take parameters of type 'double'.");+ }+ }+this.call = call;- this.arguments = method.getParameterTypes().length;+ this.arguments = paramTypes.length;this.klass = Type.getInternalName(method.getDeclaringClass());this.method = method.getName();this.signature = Type.getMethodDescriptor(method);