Apache Lucene open-source search software
LUCENE-5207: check the class too
Robert Muirb56c58884fd1
diff --git a/lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptCompiler.java b/lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptCompiler.javaindex f02d24f8fd8..a89efd74016 100644--- a/lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptCompiler.java+++ b/lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptCompiler.java@@ -715,6 +715,9 @@ public class JavascriptCompiler {if (!Modifier.isPublic(method.getModifiers())) {throw new IllegalArgumentException(method + " is not public.");}+ if (!Modifier.isPublic(method.getDeclaringClass().getModifiers())) {+ throw new IllegalArgumentException(method.getDeclaringClass().getName() + " is not public.");+ }for (Class<?> clazz : method.getParameterTypes()) {if (!clazz.equals(double.class)) {throw new IllegalArgumentException(method + " must take only double parameters");diff --git a/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestCustomFunctions.java b/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestCustomFunctions.javaindex 6c18dae3531..361c80fe7de 100644--- a/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestCustomFunctions.java+++ b/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestCustomFunctions.java@@ -141,4 +141,19 @@ public class TestCustomFunctions extends LuceneTestCase {assertTrue(e.getMessage().contains("is not public"));}}++ static class NestedNotPublic {+ public static double method() { return 0; }+ }++ /** wrong class modifiers: class containing method is not public */+ public void testWrongNestedNotPublic() throws Exception {+ Map<String,Method> functions = new HashMap<String,Method>();+ functions.put("foo", NestedNotPublic.class.getMethod("method"));+ try {+ JavascriptCompiler.compile("foo()", functions, getClass().getClassLoader());+ } catch (IllegalArgumentException e) {+ assertTrue(e.getMessage().contains("is not public"));+ }+ }}