Fix #437 - add java.util.Optional support to empty operator
Includes TCK test.
Test validated with Tomcat's EL implementation.
diff --git a/spec/src/main/asciidoc/expression-language-spec-body.adoc b/spec/src/main/asciidoc/expression-language-spec-body.adoc
index 6388ab5..2f0921c 100644
--- a/spec/src/main/asciidoc/expression-language-spec-body.adoc
+++ b/spec/src/main/asciidoc/expression-language-spec-body.adoc
@@ -1056,6 +1056,8 @@
* Otherwise, if `A` is an empty `Collection`, return `true`
+* Otherwise, if `A` is an instance of `java.util.Optional` and `A.isEmpty()` returns `true`, return `true`
+
* Otherwise return `false`
=== Conditional Operator - `A ? B : C`
@@ -3179,6 +3181,11 @@
the import handler expects canonical class names where full class names are
required.
+* https://github.com/jakartaee/expression-language/issues/437[#437]
+ Update the definition of the empty operator to include empty Optional
+ instances in the list of conditions that cause the empty operator to return
+ true.
+
=== Changes between 6.0 and 5.0
* The EL API requires Java 17 as a minimum.
diff --git a/tck/src/main/java/com/sun/ts/tests/el/spec/emptyoperator/ELClientIT.java b/tck/src/main/java/com/sun/ts/tests/el/spec/emptyoperator/ELClientIT.java
index b902a21..720ef44 100644
--- a/tck/src/main/java/com/sun/ts/tests/el/spec/emptyoperator/ELClientIT.java
+++ b/tck/src/main/java/com/sun/ts/tests/el/spec/emptyoperator/ELClientIT.java
@@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Optional;
import com.sun.ts.tests.el.common.util.ExprEval;
import com.sun.ts.tests.el.common.util.NameValuePair;
@@ -174,6 +175,14 @@
testCollection.clear();
}
+ @Test
+ public void elEmptyOptionalTest() throws Exception {
+
+ this.testEmptyOperator(Optional.empty() , true);
+
+ this.testEmptyOperator(Optional.of("value"), false);
+ }
+
// ---------------------------------------------------------- private methods
// Test Empty operator.