Skip to content

Commit 4270085

Browse files
authored
[Painless] Allow statically imported methods without whitelist class. (#34370)
This removes the extraneous check to see if the class for a statically imported method is already whitelisted, so a statically imported method can be whitelisted independently.
1 parent 34b935a commit 4270085

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.painless;
21+
22+
public class StaticTest {
23+
public static int staticAddIntsTest(int x, int y) {
24+
return x + y;
25+
}
26+
}

modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessLookupBuilder.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -691,13 +691,6 @@ public void addImportedPainlessMethod(Class<?> targetClass, String methodName, C
691691
"invalid imported method name [" + methodName + "] for target class [" + targetCanonicalClassName + "].");
692692
}
693693

694-
PainlessClassBuilder painlessClassBuilder = classesToPainlessClassBuilders.get(targetClass);
695-
696-
if (painlessClassBuilder == null) {
697-
throw new IllegalArgumentException("target class [" + targetCanonicalClassName + "] not found for imported method " +
698-
"[[" + targetCanonicalClassName + "], [" + methodName + "], " + typesToCanonicalTypeNames(typeParameters) + "]");
699-
}
700-
701694
int typeParametersSize = typeParameters.size();
702695
List<Class<?>> javaTypeParameters = new ArrayList<>(typeParametersSize);
703696

modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ class org.elasticsearch.painless.FeatureTest no_import {
261261

262262
# for testing
263263
static_import {
264+
int staticAddIntsTest(int, int) from_class org.elasticsearch.painless.StaticTest
264265
float staticAddFloatsTest(float, float) from_class org.elasticsearch.painless.FeatureTest
265266
int testAddWithState(int, int, int, double) bound_to org.elasticsearch.painless.BindingTest
266267
}

modules/lang-painless/src/test/java/org/elasticsearch/painless/BasicAPITests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ public void testNoSemicolon() {
136136
}
137137

138138
public void testStatic() {
139+
assertEquals(10, exec("staticAddIntsTest(7, 3)"));
139140
assertEquals(15.5f, exec("staticAddFloatsTest(6.5f, 9.0f)"));
140141
}
141142
}

0 commit comments

Comments
 (0)