Skip to content

Commit 39c4e2d

Browse files
committed
Add support for java.util.Optional to the empty operator.
1 parent acb0eb0 commit 39c4e2d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

java/org/apache/el/parser/AstAbstractEmpty.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.util.Collection;
2121
import java.util.Map;
22+
import java.util.Optional;
2223

2324
import jakarta.el.ELException;
2425

@@ -52,7 +53,8 @@ public Object getValue(EvaluationContext ctx) throws ELException {
5253
if (obj == null || obj instanceof String && ((String) obj).isEmpty() ||
5354
obj instanceof Object[] && ((Object[]) obj).length == 0 ||
5455
obj instanceof Collection<?> && ((Collection<?>) obj).isEmpty() ||
55-
obj instanceof Map<?,?> && ((Map<?,?>) obj).isEmpty()) {
56+
obj instanceof Map<?,?> && ((Map<?,?>) obj).isEmpty() ||
57+
obj instanceof Optional && ((Optional<?>) obj).isEmpty()) {
5658
return RETURN_EMPTY;
5759
}
5860
return RETURN_NOT_EMPTY;

webapps/docs/changelog.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@
355355
Add support for coercion to <code>java.time.Instant</code> and
356356
<code>java.util.Date</code>. (markt)
357357
</add>
358+
<add>
359+
Add support for <code>java.util.Optional</code> to the empty operator.
360+
(markt)
361+
</add>
358362
<!-- Entries for backport and removal before 12.0.0-M1 below this line -->
359363
<fix>
360364
<bug>69948</bug>: Avoid ArrayOutOfBoundsException instead of

0 commit comments

Comments
 (0)