Overview

While testing the regression raised in #27719, I noticed that our support for java.util.Optional is inconsistent when invoking a method or function that accepts a varargs array of type Optional in a SpEL expression.

As can be seen in MethodInvocationTests, if null is supplied along with other values, each null value gets converted to Optional.empty(); whereas, a null value supplied by itself gets passed through as null to the invoked method.

https://github.com/spring-projects/spring-framework/blob/62f480adc3090453946c4de4919aae7af7e906bf/spring-expression/src/test/java/org/springframework/expression/spel/MethodInvocationTests.java#L305-L310

Although this is a very specific use case that potentially does not even exist in a real project, we would like to ensure consistent semantics for Optional arguments in SpEL expressions.