@@ -82,7 +82,7 @@ private enum IndexedType {ARRAY, LIST, MAP, STRING, OBJECT}
82
82
private IndexedType indexedType ;
83
83
84
84
@ Nullable
85
- private String originalPrimitiveExitTypeDescriptor ;
85
+ private volatile String originalPrimitiveExitTypeDescriptor ;
86
86
87
87
@ Nullable
88
88
private volatile String arrayTypeDescriptor ;
@@ -373,131 +373,6 @@ public String toStringAST() {
373
373
}
374
374
375
375
376
- private void setArrayElement (TypeConverter converter , Object ctx , int idx , @ Nullable Object newValue ,
377
- Class <?> arrayComponentType ) throws EvaluationException {
378
-
379
- if (arrayComponentType == boolean .class ) {
380
- boolean [] array = (boolean []) ctx ;
381
- checkAccess (array .length , idx );
382
- array [idx ] = convertValue (converter , newValue , boolean .class );
383
- }
384
- else if (arrayComponentType == byte .class ) {
385
- byte [] array = (byte []) ctx ;
386
- checkAccess (array .length , idx );
387
- array [idx ] = convertValue (converter , newValue , byte .class );
388
- }
389
- else if (arrayComponentType == char .class ) {
390
- char [] array = (char []) ctx ;
391
- checkAccess (array .length , idx );
392
- array [idx ] = convertValue (converter , newValue , char .class );
393
- }
394
- else if (arrayComponentType == double .class ) {
395
- double [] array = (double []) ctx ;
396
- checkAccess (array .length , idx );
397
- array [idx ] = convertValue (converter , newValue , double .class );
398
- }
399
- else if (arrayComponentType == float .class ) {
400
- float [] array = (float []) ctx ;
401
- checkAccess (array .length , idx );
402
- array [idx ] = convertValue (converter , newValue , float .class );
403
- }
404
- else if (arrayComponentType == int .class ) {
405
- int [] array = (int []) ctx ;
406
- checkAccess (array .length , idx );
407
- array [idx ] = convertValue (converter , newValue , int .class );
408
- }
409
- else if (arrayComponentType == long .class ) {
410
- long [] array = (long []) ctx ;
411
- checkAccess (array .length , idx );
412
- array [idx ] = convertValue (converter , newValue , long .class );
413
- }
414
- else if (arrayComponentType == short .class ) {
415
- short [] array = (short []) ctx ;
416
- checkAccess (array .length , idx );
417
- array [idx ] = convertValue (converter , newValue , short .class );
418
- }
419
- else {
420
- Object [] array = (Object []) ctx ;
421
- checkAccess (array .length , idx );
422
- array [idx ] = convertValue (converter , newValue , arrayComponentType );
423
- }
424
- }
425
-
426
- private Object accessArrayElement (Object ctx , int idx ) throws SpelEvaluationException {
427
- Class <?> arrayComponentType = ctx .getClass ().componentType ();
428
- if (arrayComponentType == boolean .class ) {
429
- boolean [] array = (boolean []) ctx ;
430
- checkAccess (array .length , idx );
431
- setExitTypeDescriptor ("Z" );
432
- this .arrayTypeDescriptor = "[Z" ;
433
- return array [idx ];
434
- }
435
- else if (arrayComponentType == byte .class ) {
436
- byte [] array = (byte []) ctx ;
437
- checkAccess (array .length , idx );
438
- setExitTypeDescriptor ("B" );
439
- this .arrayTypeDescriptor = "[B" ;
440
- return array [idx ];
441
- }
442
- else if (arrayComponentType == char .class ) {
443
- char [] array = (char []) ctx ;
444
- checkAccess (array .length , idx );
445
- setExitTypeDescriptor ("C" );
446
- this .arrayTypeDescriptor = "[C" ;
447
- return array [idx ];
448
- }
449
- else if (arrayComponentType == double .class ) {
450
- double [] array = (double []) ctx ;
451
- checkAccess (array .length , idx );
452
- setExitTypeDescriptor ("D" );
453
- this .arrayTypeDescriptor = "[D" ;
454
- return array [idx ];
455
- }
456
- else if (arrayComponentType == float .class ) {
457
- float [] array = (float []) ctx ;
458
- checkAccess (array .length , idx );
459
- setExitTypeDescriptor ("F" );
460
- this .arrayTypeDescriptor = "[F" ;
461
- return array [idx ];
462
- }
463
- else if (arrayComponentType == int .class ) {
464
- int [] array = (int []) ctx ;
465
- checkAccess (array .length , idx );
466
- setExitTypeDescriptor ("I" );
467
- this .arrayTypeDescriptor = "[I" ;
468
- return array [idx ];
469
- }
470
- else if (arrayComponentType == long .class ) {
471
- long [] array = (long []) ctx ;
472
- checkAccess (array .length , idx );
473
- setExitTypeDescriptor ("J" );
474
- this .arrayTypeDescriptor = "[J" ;
475
- return array [idx ];
476
- }
477
- else if (arrayComponentType == short .class ) {
478
- short [] array = (short []) ctx ;
479
- checkAccess (array .length , idx );
480
- setExitTypeDescriptor ("S" );
481
- this .arrayTypeDescriptor = "[S" ;
482
- return array [idx ];
483
- }
484
- else {
485
- Object [] array = (Object []) ctx ;
486
- checkAccess (array .length , idx );
487
- Object retValue = array [idx ];
488
- setExitTypeDescriptor (CodeFlow .toDescriptor (arrayComponentType ));
489
- this .arrayTypeDescriptor = CodeFlow .toDescriptor (array .getClass ());
490
- return retValue ;
491
- }
492
- }
493
-
494
- private void checkAccess (int arrayLength , int index ) throws SpelEvaluationException {
495
- if (index >= arrayLength ) {
496
- throw new SpelEvaluationException (getStartPosition (), SpelMessage .ARRAY_INDEX_OUT_OF_BOUNDS ,
497
- arrayLength , index );
498
- }
499
- }
500
-
501
376
private void setExitTypeDescriptor (String descriptor ) {
502
377
// If this indexer would return a primitive - and yet it is also marked
503
378
// null-safe - then the exit type descriptor must be promoted to the box
@@ -511,16 +386,6 @@ private void setExitTypeDescriptor(String descriptor) {
511
386
}
512
387
}
513
388
514
- @ SuppressWarnings ("unchecked" )
515
- private <T > T convertValue (TypeConverter converter , @ Nullable Object value , Class <T > targetType ) {
516
- T result = (T ) converter .convertValue (
517
- value , TypeDescriptor .forObject (value ), TypeDescriptor .valueOf (targetType ));
518
- if (result == null ) {
519
- throw new IllegalStateException ("Null conversion result for index [" + value + "]" );
520
- }
521
- return result ;
522
- }
523
-
524
389
525
390
private class ArrayIndexingValueRef implements ValueRef {
526
391
@@ -541,7 +406,7 @@ private class ArrayIndexingValueRef implements ValueRef {
541
406
542
407
@ Override
543
408
public TypedValue getValue () {
544
- Object arrayElement = accessArrayElement (this .array , this .index );
409
+ Object arrayElement = getArrayElement (this .array , this .index );
545
410
return new TypedValue (arrayElement , this .typeDescriptor .elementTypeDescriptor (arrayElement ));
546
411
}
547
412
@@ -556,6 +421,142 @@ public void setValue(@Nullable Object newValue) {
556
421
public boolean isWritable () {
557
422
return true ;
558
423
}
424
+
425
+ private Object getArrayElement (Object ctx , int idx ) throws SpelEvaluationException {
426
+ Class <?> arrayComponentType = ctx .getClass ().componentType ();
427
+ if (arrayComponentType == boolean .class ) {
428
+ boolean [] array = (boolean []) ctx ;
429
+ checkAccess (array .length , idx );
430
+ setExitTypeDescriptor ("Z" );
431
+ Indexer .this .arrayTypeDescriptor = "[Z" ;
432
+ return array [idx ];
433
+ }
434
+ else if (arrayComponentType == byte .class ) {
435
+ byte [] array = (byte []) ctx ;
436
+ checkAccess (array .length , idx );
437
+ setExitTypeDescriptor ("B" );
438
+ Indexer .this .arrayTypeDescriptor = "[B" ;
439
+ return array [idx ];
440
+ }
441
+ else if (arrayComponentType == char .class ) {
442
+ char [] array = (char []) ctx ;
443
+ checkAccess (array .length , idx );
444
+ setExitTypeDescriptor ("C" );
445
+ Indexer .this .arrayTypeDescriptor = "[C" ;
446
+ return array [idx ];
447
+ }
448
+ else if (arrayComponentType == double .class ) {
449
+ double [] array = (double []) ctx ;
450
+ checkAccess (array .length , idx );
451
+ setExitTypeDescriptor ("D" );
452
+ Indexer .this .arrayTypeDescriptor = "[D" ;
453
+ return array [idx ];
454
+ }
455
+ else if (arrayComponentType == float .class ) {
456
+ float [] array = (float []) ctx ;
457
+ checkAccess (array .length , idx );
458
+ setExitTypeDescriptor ("F" );
459
+ Indexer .this .arrayTypeDescriptor = "[F" ;
460
+ return array [idx ];
461
+ }
462
+ else if (arrayComponentType == int .class ) {
463
+ int [] array = (int []) ctx ;
464
+ checkAccess (array .length , idx );
465
+ setExitTypeDescriptor ("I" );
466
+ Indexer .this .arrayTypeDescriptor = "[I" ;
467
+ return array [idx ];
468
+ }
469
+ else if (arrayComponentType == long .class ) {
470
+ long [] array = (long []) ctx ;
471
+ checkAccess (array .length , idx );
472
+ setExitTypeDescriptor ("J" );
473
+ Indexer .this .arrayTypeDescriptor = "[J" ;
474
+ return array [idx ];
475
+ }
476
+ else if (arrayComponentType == short .class ) {
477
+ short [] array = (short []) ctx ;
478
+ checkAccess (array .length , idx );
479
+ setExitTypeDescriptor ("S" );
480
+ Indexer .this .arrayTypeDescriptor = "[S" ;
481
+ return array [idx ];
482
+ }
483
+ else {
484
+ Object [] array = (Object []) ctx ;
485
+ checkAccess (array .length , idx );
486
+ Object retValue = array [idx ];
487
+ Indexer .this .exitTypeDescriptor = CodeFlow .toDescriptor (arrayComponentType );
488
+ Indexer .this .arrayTypeDescriptor = CodeFlow .toDescriptor (array .getClass ());
489
+ return retValue ;
490
+ }
491
+ }
492
+
493
+ private void setArrayElement (TypeConverter converter , Object ctx , int idx , @ Nullable Object newValue ,
494
+ Class <?> arrayComponentType ) throws EvaluationException {
495
+
496
+ if (arrayComponentType == boolean .class ) {
497
+ boolean [] array = (boolean []) ctx ;
498
+ checkAccess (array .length , idx );
499
+ array [idx ] = convertValue (converter , newValue , boolean .class );
500
+ }
501
+ else if (arrayComponentType == byte .class ) {
502
+ byte [] array = (byte []) ctx ;
503
+ checkAccess (array .length , idx );
504
+ array [idx ] = convertValue (converter , newValue , byte .class );
505
+ }
506
+ else if (arrayComponentType == char .class ) {
507
+ char [] array = (char []) ctx ;
508
+ checkAccess (array .length , idx );
509
+ array [idx ] = convertValue (converter , newValue , char .class );
510
+ }
511
+ else if (arrayComponentType == double .class ) {
512
+ double [] array = (double []) ctx ;
513
+ checkAccess (array .length , idx );
514
+ array [idx ] = convertValue (converter , newValue , double .class );
515
+ }
516
+ else if (arrayComponentType == float .class ) {
517
+ float [] array = (float []) ctx ;
518
+ checkAccess (array .length , idx );
519
+ array [idx ] = convertValue (converter , newValue , float .class );
520
+ }
521
+ else if (arrayComponentType == int .class ) {
522
+ int [] array = (int []) ctx ;
523
+ checkAccess (array .length , idx );
524
+ array [idx ] = convertValue (converter , newValue , int .class );
525
+ }
526
+ else if (arrayComponentType == long .class ) {
527
+ long [] array = (long []) ctx ;
528
+ checkAccess (array .length , idx );
529
+ array [idx ] = convertValue (converter , newValue , long .class );
530
+ }
531
+ else if (arrayComponentType == short .class ) {
532
+ short [] array = (short []) ctx ;
533
+ checkAccess (array .length , idx );
534
+ array [idx ] = convertValue (converter , newValue , short .class );
535
+ }
536
+ else {
537
+ Object [] array = (Object []) ctx ;
538
+ checkAccess (array .length , idx );
539
+ array [idx ] = convertValue (converter , newValue , arrayComponentType );
540
+ }
541
+ }
542
+
543
+ private void checkAccess (int arrayLength , int index ) throws SpelEvaluationException {
544
+ if (index >= arrayLength ) {
545
+ throw new SpelEvaluationException (getStartPosition (), SpelMessage .ARRAY_INDEX_OUT_OF_BOUNDS ,
546
+ arrayLength , index );
547
+ }
548
+ }
549
+
550
+ @ SuppressWarnings ("unchecked" )
551
+ private static <T > T convertValue (TypeConverter converter , @ Nullable Object value , Class <T > targetType ) {
552
+ T result = (T ) converter .convertValue (
553
+ value , TypeDescriptor .forObject (value ), TypeDescriptor .valueOf (targetType ));
554
+ if (result == null ) {
555
+ throw new IllegalStateException ("Null conversion result for index [" + value + "]" );
556
+ }
557
+ return result ;
558
+ }
559
+
559
560
}
560
561
561
562
@@ -789,20 +790,20 @@ private void growCollectionIfNecessary() {
789
790
}
790
791
}
791
792
793
+ @ Override
794
+ public boolean isWritable () {
795
+ return true ;
796
+ }
797
+
792
798
@ Nullable
793
- private Constructor <?> getDefaultConstructor (Class <?> type ) {
799
+ private static Constructor <?> getDefaultConstructor (Class <?> type ) {
794
800
try {
795
801
return ReflectionUtils .accessibleConstructor (type );
796
802
}
797
803
catch (Throwable ex ) {
798
804
return null ;
799
805
}
800
806
}
801
-
802
- @ Override
803
- public boolean isWritable () {
804
- return true ;
805
- }
806
807
}
807
808
808
809
0 commit comments