Skip to content

Commit 05579fd

Browse files
committed
SpEL docs: supported literals, null comparisons
Issue: SPR-14361 Issue: SPR-14987
1 parent 6517c53 commit 05579fd

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/asciidoc/core-expressions.adoc

+19-6
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ example for Spring bean or Spring Web Flow definitions. In this case, the parser
220220
evaluation context, root object and any predefined variables are all set up implicitly,
221221
requiring the user to specify nothing other than the expressions.
222222
====
223+
223224
As a final introductory example, the use of a boolean operator is shown using the
224225
Inventor object in the previous example.
225226

@@ -583,12 +584,13 @@ Autowired methods and constructors can also use the `@Value` annotation.
583584

584585
[[expressions-ref-literal]]
585586
=== Literal expressions
586-
The types of literal expressions supported are strings, dates, numeric values (int,
587-
real, and hex), boolean and null. Strings are delimited by single quotes. To put a
588-
single quote itself in a string use two single quote characters. The following listing
589-
shows simple usage of literals. Typically they would not be used in isolation like this,
590-
but as part of a more complex expression, for example using a literal on one side of a
591-
logical comparison operator.
587+
The types of literal expressions supported are strings, numeric values (int, real, hex),
588+
boolean and null. Strings are delimited by single quotes. To put a single quote itself
589+
in a string, use two single quote characters.
590+
591+
The following listing shows simple usage of literals. Typically they would not be used
592+
in isolation like this but rather as part of a more complex expression, for example
593+
using a literal on one side of a logical comparison operator.
592594

593595
[source,java,indent=0]
594596
[subs="verbatim,quotes"]
@@ -777,6 +779,17 @@ and greater than or equal are supported using standard operator notation.
777779
boolean trueValue = parser.parseExpression("'black' < 'block'").getValue(Boolean.class);
778780
----
779781

782+
[NOTE]
783+
====
784+
Greater/less-than comparisons against `null` follow a simple rule: `null` is treated as
785+
nothing here (i.e. NOT as zero). As a consequence, any other value is always greater
786+
than `null` (`X > null` is always `true`) and no other value is ever less than nothing
787+
(`X < null` is always `false`).
788+
789+
If you prefer numeric comparisons instead, please avoid number-based `null` comparisons
790+
in favor of comparisons against zero (e.g. `X > 0` or `X < 0`).
791+
====
792+
780793
In addition to standard relational operators SpEL supports the `instanceof` and regular
781794
expression based `matches` operator.
782795

0 commit comments

Comments
 (0)