11/*
2- * Copyright 2002-2022 the original author or authors.
2+ * Copyright 2002-2024 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1818
1919import org .junit .jupiter .api .Test ;
2020
21+ import org .springframework .expression .EvaluationContext ;
2122import org .springframework .expression .Expression ;
2223import org .springframework .expression .spel .standard .SpelExpressionParser ;
24+ import org .springframework .expression .spel .support .SimpleEvaluationContext ;
2325import org .springframework .util .ObjectUtils ;
2426
2527import static org .assertj .core .api .Assertions .assertThat ;
28+ import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
2629
2730/**
2831 * Test construction of arrays.
2932 *
3033 * @author Andy Clement
3134 * @author Sam Brannen
35+ * @author Juergen Hoeller
3236 */
3337class ArrayConstructorTests extends AbstractExpressionTests {
3438
@@ -97,7 +101,7 @@ void errorCases() {
97101 void typeArrayConstructors () {
98102 evaluate ("new String[]{'a','b','c','d'}[1]" , "b" , String .class );
99103 evaluateAndCheckError ("new String[]{'a','b','c','d'}.size()" , SpelMessage .METHOD_NOT_FOUND , 30 , "size()" ,
100- "java.lang.String[]" );
104+ "java.lang.String[]" );
101105 evaluate ("new String[]{'a','b','c','d'}.length" , 4 , Integer .class );
102106 }
103107
@@ -110,10 +114,18 @@ void basicArray() {
110114 void multiDimensionalArrays () {
111115 evaluate ("new String[2][2]" , "[Ljava.lang.String;[2]{[2]{null,null},[2]{null,null}}" , String [][].class );
112116 evaluate ("new String[3][2][1]" ,
113- "[[Ljava.lang.String;[3]{[2]{[1]{null},[1]{null}},[2]{[1]{null},[1]{null}},[2]{[1]{null},[1]{null}}}" ,
114- String [][][].class );
117+ "[[Ljava.lang.String;[3]{[2]{[1]{null},[1]{null}},[2]{[1]{null},[1]{null}},[2]{[1]{null},[1]{null}}}" ,
118+ String [][][].class );
115119 }
116120
121+ @ Test
122+ void noArrayConstruction () {
123+ EvaluationContext context = SimpleEvaluationContext .forReadWriteDataBinding ().build ();
124+ assertThatExceptionOfType (SpelEvaluationException .class ).isThrownBy (() ->
125+ parser .parseExpression ("new int[2]" ).getValue (context ));
126+ }
127+
128+
117129 private void evaluateArrayBuildingExpression (String expression , String expectedToString ) {
118130 SpelExpressionParser parser = new SpelExpressionParser ();
119131 Expression e = parser .parseExpression (expression );
0 commit comments