Fix issue with empty array converting to string expression instead of string array (#11270)

This commit is contained in:
Clint Wylie 2021-05-21 18:31:28 -07:00 committed by GitHub
parent 4ba5738ffb
commit 2bfcee5824
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -378,7 +378,7 @@ public abstract class ExprEval<T>
return new String[]{null}; return new String[]{null};
} else { } else {
if (val != null) { if (val != null) {
return val.toArray(); return new String[0];
} }
return null; return null;
} }

View File

@ -273,6 +273,16 @@ public class ExprEvalTest extends InitializedNullHandlingTest
); );
} }
@Test
public void testEmptyArrayFromList()
{
// empty arrays will materialize from JSON into an empty list, which coerce list to array will make into Object[]
// make sure we can handle it
ExprEval someEmptyArray = ExprEval.bestEffortOf(new ArrayList<>());
Assert.assertTrue(someEmptyArray.isArray());
Assert.assertEquals(0, someEmptyArray.asArray().length);
}
private void assertExpr(int position, Object expected) private void assertExpr(int position, Object expected)
{ {
assertExpr(position, ExprEval.bestEffortOf(expected)); assertExpr(position, ExprEval.bestEffortOf(expected));