Disable array allocation in case of no constructor resolution
Closes gh-28808
This commit is contained in:
parent
311048726e
commit
a3a48a241c
|
@ -243,6 +243,12 @@ public class ConstructorReference extends SpelNodeImpl {
|
|||
intendedArrayType != null ? intendedArrayType.getClass() : null));
|
||||
}
|
||||
|
||||
if (state.getEvaluationContext().getConstructorResolvers().isEmpty()) {
|
||||
// No constructor resolver -> no array construction either (as of 6.0)
|
||||
throw new SpelEvaluationException(getStartPosition(), SpelMessage.CONSTRUCTOR_NOT_FOUND,
|
||||
type + "[]", "[]");
|
||||
}
|
||||
|
||||
Class<?> componentType;
|
||||
TypeCode arrayTypeCode = TypeCode.forName(type);
|
||||
if (arrayTypeCode == TypeCode.OBJECT) {
|
||||
|
|
|
@ -18,17 +18,21 @@ package org.springframework.expression.spel;
|
|||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.SimpleEvaluationContext;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Test construction of arrays.
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @author Sam Brannen
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
class ArrayConstructorTests extends AbstractExpressionTests {
|
||||
|
||||
|
@ -114,6 +118,14 @@ class ArrayConstructorTests extends AbstractExpressionTests {
|
|||
String[][][].class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void noArrayConstruction() {
|
||||
EvaluationContext context = SimpleEvaluationContext.forReadWriteDataBinding().build();
|
||||
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
||||
parser.parseExpression("new int[2]").getValue(context));
|
||||
}
|
||||
|
||||
|
||||
private void evaluateArrayBuildingExpression(String expression, String expectedToString) {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Expression e = parser.parseExpression(expression);
|
||||
|
|
Loading…
Reference in New Issue