LUCENE-5207: check the class too

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene5207@1523301 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2013-09-14 19:40:20 +00:00
parent 591a3b1ca1
commit b56c58884f
2 changed files with 18 additions and 0 deletions

View File

@ -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");

View File

@ -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"));
}
}
}