1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2021 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
57
57
*/
58
58
public class ConstructorReference extends SpelNodeImpl {
59
59
60
- private boolean isArrayConstructor = false ;
60
+ private final boolean isArrayConstructor ;
61
61
62
62
@ Nullable
63
63
private SpelNodeImpl [] dimensions ;
@@ -208,14 +208,14 @@ public String toStringAST() {
208
208
StringBuilder sb = new StringBuilder ("new " );
209
209
int index = 0 ;
210
210
sb .append (getChild (index ++).toStringAST ());
211
- sb .append ("(" );
211
+ sb .append ('(' );
212
212
for (int i = index ; i < getChildCount (); i ++) {
213
213
if (i > index ) {
214
- sb .append ("," );
214
+ sb .append (',' );
215
215
}
216
216
sb .append (getChild (i ).toStringAST ());
217
217
}
218
- sb .append (")" );
218
+ sb .append (')' );
219
219
return sb .toString ();
220
220
}
221
221
@@ -234,6 +234,7 @@ private TypedValue createArray(ExpressionState state) throws EvaluationException
234
234
FormatHelper .formatClassNameForMessage (
235
235
intendedArrayType != null ? intendedArrayType .getClass () : null ));
236
236
}
237
+
237
238
String type = (String ) intendedArrayType ;
238
239
Class <?> componentType ;
239
240
TypeCode arrayTypeCode = TypeCode .forName (type );
@@ -243,7 +244,8 @@ private TypedValue createArray(ExpressionState state) throws EvaluationException
243
244
else {
244
245
componentType = arrayTypeCode .getType ();
245
246
}
246
- Object newArray ;
247
+
248
+ Object newArray = null ;
247
249
if (!hasInitializer ()) {
248
250
// Confirm all dimensions were specified (for example [3][][5] is missing the 2nd dimension)
249
251
if (this .dimensions != null ) {
@@ -252,23 +254,22 @@ private TypedValue createArray(ExpressionState state) throws EvaluationException
252
254
throw new SpelEvaluationException (getStartPosition (), SpelMessage .MISSING_ARRAY_DIMENSION );
253
255
}
254
256
}
255
- }
256
- TypeConverter typeConverter = state . getEvaluationContext (). getTypeConverter ();
257
-
258
- // Shortcut for 1 dimensional
259
- if ( this . dimensions . length == 1 ) {
260
- TypedValue o = this . dimensions [ 0 ]. getTypedValue ( state );
261
- int arraySize = ExpressionUtils . toInt ( typeConverter , o );
262
- newArray = Array . newInstance ( componentType , arraySize );
263
- }
264
- else {
265
- // Multi-dimensional - hold onto your hat!
266
- int [] dims = new int [ this .dimensions . length ] ;
267
- for ( int d = 0 ; d < this . dimensions . length ; d ++) {
268
- TypedValue o = this . dimensions [ d ]. getTypedValue ( state );
269
- dims [ d ] = ExpressionUtils . toInt ( typeConverter , o );
257
+ TypeConverter typeConverter = state . getEvaluationContext (). getTypeConverter ();
258
+ if ( this . dimensions . length == 1 ) {
259
+ // Shortcut for 1-dimensional
260
+ TypedValue o = this . dimensions [ 0 ]. getTypedValue ( state );
261
+ int arraySize = ExpressionUtils . toInt ( typeConverter , o );
262
+ newArray = Array . newInstance ( componentType , arraySize );
263
+ }
264
+ else {
265
+ // Multi-dimensional - hold onto your hat!
266
+ int [] dims = new int [ this . dimensions . length ];
267
+ for ( int d = 0 ; d < this . dimensions . length ; d ++) {
268
+ TypedValue o = this .dimensions [ d ]. getTypedValue ( state ) ;
269
+ dims [ d ] = ExpressionUtils . toInt ( typeConverter , o );
270
+ }
271
+ newArray = Array . newInstance ( componentType , dims );
270
272
}
271
- newArray = Array .newInstance (componentType , dims );
272
273
}
273
274
}
274
275
else {
0 commit comments