Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [el-dev] Question about the new OptionalELResolver

On 13/02/2024 15:31, Paul Nicolucci wrote:
Hey Mark,

Your proposal seems reasonable to me!

I've started to look at implementing this in Tomcat and have found a complication. Consider the following expression:

${beanA.beanBOpt.map(b -> b.name)}

Should this call Optional.map() which is likely what was intended or should it call Optional.get().map() which will probably throw a MethodNotFoundException

I think the answer is that the user has to choose.

Choice A: Don't use OptionalELResolver

Instances of Optional are treated like any other object. The expression above will trigger a call to Optional.map() and return a (possibly non-empty) Optional.


Choice B: Use OptionalELResolver

Instances of Optional are treated as Optional.get() if present and null if empty (and any property or method on the Optional is ignored). The expression above will return null if the Optional is empty. If the Optional is present then the expression will return the result of calling Optional.get().map() which may return a value or may throw a MethodNotFoundException


I'm going to continue my work in Tomcat on this basis and see where things end up.

Mark


Back to the top