Skip to content

Commit 1319b40

Browse files
committed
Painless: Fix Bindings Bug (#33274)
When the change was made to the format for in the whitelist for bindings, parameters from both the constructor and the method were combined into a single list instead of separate lists. The check for method parameters was being executed from the start of the combined list rather than the correct position. The tests for bindings used a constructor and a method that only used the int types so this was not caught. The test has been changed to also use a double type and this issue is fixed.
1 parent 61e0ce7 commit 1319b40

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

modules/lang-painless/src/main/java/org/elasticsearch/painless/BindingTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public BindingTest(int state0, int state1) {
2626
this.state = state0 + state1;
2727
}
2828

29-
public int testAddWithState(int stateless) {
30-
return stateless + state;
29+
public int testAddWithState(int istateless, double dstateless) {
30+
return istateless + state + (int)dstateless;
3131
}
3232
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ public void addPainlessBinding(Class<?> targetClass, String methodName, Class<?>
908908
int methodTypeParametersSize = javaMethod.getParameterCount();
909909

910910
for (int typeParameterIndex = 0; typeParameterIndex < methodTypeParametersSize; ++typeParameterIndex) {
911-
Class<?> typeParameter = typeParameters.get(typeParameterIndex);
911+
Class<?> typeParameter = typeParameters.get(constructorTypeParametersSize + typeParameterIndex);
912912

913913
if (isValidType(typeParameter) == false) {
914914
throw new IllegalArgumentException("type parameter [" + typeToCanonicalTypeName(typeParameter) + "] not found " +

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,5 +181,5 @@ class org.elasticsearch.painless.FeatureTest no_import {
181181

182182
# for testing
183183
static {
184-
int testAddWithState(int, int, int) bound_to org.elasticsearch.painless.BindingTest
184+
int testAddWithState(int, int, int, double) bound_to org.elasticsearch.painless.BindingTest
185185
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
public class BindingsTests extends ScriptTestCase {
2929

3030
public void testBasicBinding() {
31-
assertEquals(15, exec("testAddWithState(4, 5, 6)"));
31+
assertEquals(15, exec("testAddWithState(4, 5, 6, 0.0)"));
3232
}
3333

3434
public void testRepeatedBinding() {
35-
String script = "testAddWithState(4, 5, params.test)";
35+
String script = "testAddWithState(4, 5, params.test, 0.0)";
3636
Map<String, Object> params = new HashMap<>();
3737
ExecutableScript.Factory factory = scriptEngine.compile(null, script, ExecutableScript.CONTEXT, Collections.emptyMap());
3838
ExecutableScript executableScript = factory.newInstance(params);
@@ -48,7 +48,7 @@ public void testRepeatedBinding() {
4848
}
4949

5050
public void testBoundBinding() {
51-
String script = "testAddWithState(4, params.bound, params.test)";
51+
String script = "testAddWithState(4, params.bound, params.test, 0.0)";
5252
Map<String, Object> params = new HashMap<>();
5353
ExecutableScript.Factory factory = scriptEngine.compile(null, script, ExecutableScript.CONTEXT, Collections.emptyMap());
5454
ExecutableScript executableScript = factory.newInstance(params);

0 commit comments

Comments
 (0)