Buggy code:
public class Selection extends SpelNodeImpl { public static final int ALL = 0 ; public static final int FIRST = 1 ; public static final int LAST = 2 ; private final int variant ; private final boolean nullSafe ; public Selection ( boolean nullSafe , int variant , int pos , SpelNodeImpl expression ) { } @ SuppressWarnings ( "unchecked" ) @ Override public TypedValue getValueInternal ( ExpressionState state ) throws EvaluationException { TypedValue op = state . getActiveContextObject ( ) ; Object operand = op . getValue ( ) ; SpelNodeImpl selectionCriteria = children [ 0 ] ; if ( operand instanceof Map ) { Map < ? , ? > mapdata = ( ( Map < ? , ? > ) ( operand ) ) ; Map < Object , Object > result = new HashMap < Object , Object > ( ) ; Object lastKey = null ; for ( Map . Entry entry : mapdata . entrySet ( ) ) { try { TypedValue kvpair = new TypedValue ( entry ) ; state . pushActiveContextObject ( kvpair ) ; Object o = selectionCriteria . getValueInternal ( state ) . getValue ( ) ; if ( o instanceof Boolean ) { if ( ( ( ( Boolean ) ( o ) ) . booleanValue ( ) ) == true ) { if ( ( variant ) == ( Selection . FIRST ) ) { result . put ( entry . getKey ( ) , entry . getValue ( ) ) ; return new TypedValue ( result ) ; } result . put ( entry . getKey ( ) , entry . getValue ( ) ) ; lastKey = entry . getKey ( ) ; } } else { throw new org . springframework . expression . spel . SpelEvaluationException ( selectionCriteria . getStartPosition ( ) , SpelMessage . RESULT_OF_SELECTION_CRITERIA_IS_NOT_BOOLEAN ) ; } } finally { state . popActiveContextObject ( ) ; } } if ( ( ( ( variant ) == ( Selection . FIRST ) ) || ( ( variant ) == ( Selection . LAST ) ) ) && ( ( result . size ( ) ) == 0 ) ) { return new TypedValue ( null ) ; } if ( ( variant ) == ( Selection . LAST ) ) { Map resultMap = new HashMap ( ) ; Object lastValue = result . get ( lastKey ) ; resultMap . put ( lastKey , lastValue ) ; return new TypedValue ( resultMap ) ; } return new TypedValue ( result ) ; } else if ( ( operand instanceof Collection ) || ( ObjectUtils . isArray ( operand ) ) ) { List < Object > data = new ArrayList < Object > ( ) ; Collection < ? > c = ( operand instanceof Collection ) ? ( ( Collection < ? > ) ( operand ) ) : Arrays . asList ( ObjectUtils . toObjectArray ( operand ) ) ; data . addAll ( c ) ; List < Object > result = new ArrayList < Object > ( ) ; int idx = 0 ; for ( Object element : data ) { try { state . pushActiveContextObject ( new TypedValue ( element ) ) ; state . enterScope ( "index" , idx ) ; Object o = selectionCriteria . getValueInternal ( state ) . getValue ( ) ; if ( o instanceof Boolean ) { if ( ( ( ( Boolean ) ( o ) ) . booleanValue ( ) ) == true ) { if ( ( variant ) == ( Selection . FIRST ) ) { return new TypedValue ( element ) ; } result . add ( element ) ; } } else { throw new org . springframework . expression . spel . SpelEvaluationException ( selectionCriteria . getStartPosition ( ) , SpelMessage . RESULT_OF_SELECTION_CRITERIA_IS_NOT_BOOLEAN ) ; } idx ++ ; } finally { state . exitScope ( ) ; state . popActiveContextObject ( ) ; } } if ( ( ( ( variant ) == ( Selection . FIRST ) ) || ( ( variant ) == ( Selection . LAST ) ) ) && ( ( result . size ( ) ) == 0 ) ) { return TypedValue . NULL ; } if ( ( variant ) == ( Selection . LAST ) ) { return new TypedValue ( result . get ( ( ( result . size ( ) ) - 1 ) ) ) ; } if ( operand instanceof Collection ) { return new TypedValue ( result ) ; } else { <START_BUG> Class < ? > elementType = ClassUtils . resolvePrimitiveIfNecessary ( op . getTypeDescriptor ( ) . getElementType ( ) ) ; <END_BUG> Object resultArray = Array . newInstance ( elementType , result . size ( ) ) ; System . arraycopy ( result . toArray ( ) , 0 , resultArray , 0 , result . size ( ) ) ; return new TypedValue ( resultArray ) ; } } else { if ( operand == null ) { if ( nullSafe ) { return TypedValue . NULL ; } else { throw new org . springframework . expression . spel . SpelEvaluationException ( getStartPosition ( ) , SpelMessage . INVALID_TYPE_FOR_SELECTION , "null" ) ; } } else { throw new org . springframework . expression . spel . SpelEvaluationException ( getStartPosition ( ) , SpelMessage . INVALID_TYPE_FOR_SELECTION , operand . getClass ( ) . getName ( ) ) ; } } } @ Override public String toStringAST ( ) { } }

Fix:
Class < ? > elementType = ClassUtils . resolvePrimitiveIfNecessary ( op . getTypeDescriptor ( ) . getElementType ( ) . getType ( ) ) ;