Skip to content

Commit 6bdc5bf

Browse files
committed
SpEL docs: supported literals, null comparisons
Issue: SPR-14361 Issue: SPR-14987
1 parent 8c26717 commit 6bdc5bf

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

src/reference/docbook/expressions.xml

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -490,13 +490,12 @@ Boolean b = simple.booleanList.get(0);
490490
<section xml:id="expressions-ref-literal">
491491
<title>Literal expressions</title>
492492

493-
<para>The types of literal expressions supported are strings, dates,
494-
numeric values (int, real, and hex), boolean and null. Strings are
495-
delimited by single quotes. To put a single quote itself in a string use
496-
two single quote characters. The following listing shows simple usage of
497-
literals. Typically they would not be used in isolation like this, but
498-
as part of a more complex expression, for example using a literal on one
499-
side of a logical comparison operator.</para>
493+
<para>The types of literal expressions supported are strings, numeric values
494+
(int, real, hex), boolean and null. Strings are delimited by single quotes.
495+
To put a single quote itself in a string, use two single quote characters.
496+
The following listing shows simple usage of literals. Typically they would not
497+
be used in isolation like this but rather as part of a more complex expression,
498+
for example using a literal on one side of a logical comparison operator.</para>
500499

501500
<programlisting language="java">ExpressionParser parser = new SpelExpressionParser();
502501

@@ -626,8 +625,8 @@ int[][] numbers3 = (int[][]) parser.parseExpression("new int[4][5]").getValue(co
626625
String c = parser.parseExpression("'abc'.substring(2, 3)").getValue(String.class);
627626

628627
// evaluates to true
629-
boolean isMember = parser.parseExpression("isMember('Mihajlo Pupin')").getValue(societyContext,
630-
Boolean.class);</programlisting>
628+
boolean isMember = parser.parseExpression("isMember('Mihajlo Pupin')").getValue(societyContext, Boolean.class);
629+
</programlisting>
631630
</section>
632631

633632
<section xml:id="expressions-operators">
@@ -640,15 +639,24 @@ boolean isMember = parser.parseExpression("isMember('Mihajlo Pupin')").getValue(
640639
or equal, greater than, and greater than or equal are supported using
641640
standard operator notation.</para>
642641

643-
<para><programlisting language="java">// evaluates to true
642+
<programlisting language="java">// evaluates to true
644643
boolean trueValue = parser.parseExpression("2 == 2").getValue(Boolean.class);
645644

646645
// evaluates to false
647646
boolean falseValue = parser.parseExpression("2 &lt; -5.0").getValue(Boolean.class);
648647

649648
// evaluates to true
650-
boolean trueValue = parser.parseExpression("'black' &lt; 'block'").getValue(Boolean.class);</programlisting>
651-
In addition to standard relational operators SpEL supports the
649+
boolean trueValue = parser.parseExpression("'black' &lt; 'block'").getValue(Boolean.class);
650+
</programlisting>
651+
652+
<para>Greater/less-than comparisons against `null` follow a simple rule: `null`
653+
is treated as nothing here (i.e. NOT as zero). As a consequence, any other value
654+
is always greater than `null` (`X &gt; null` is always `true`) and no other value
655+
is ever less than nothing (`X &lt; null` is always `false`). If you prefer numeric
656+
comparisons instead, please avoid number-based `null` comparisons in favor of
657+
comparisons against zero (e.g. `X &gt; 0` or `X &lt; 0`).</para>
658+
659+
<para>In addition to standard relational operators SpEL supports the
652660
'instanceof' and regular expression based 'matches' operator.</para>
653661

654662
<programlisting language="java">// evaluates to false
@@ -661,14 +669,13 @@ boolean trueValue =
661669
//evaluates to false
662670
boolean falseValue =
663671
parser.parseExpression("'5.0067' matches '^-?\\d+(\\.\\d{2})?$'").getValue(Boolean.class);
672+
</programlisting>
664673

665-
</programlisting>
666-
<para>Each symbolic operator can also be specified as a purely alphabetic equivalent. This avoids
667-
problems where the symbols used have special meaning for the document type in which
668-
the expression is embedded (eg. an XML document). The textual equivalents are shown
669-
here: lt ('&lt;'), gt ('&gt;'), le ('&lt;='), ge ('&gt;='),
670-
eq ('=='), ne ('!='), div ('/'), mod ('%'), not ('!').
671-
These are case insensitive.</para>
674+
<para>Each symbolic operator can also be specified as a purely alphabetic equivalent.
675+
This avoids problems where the symbols used have special meaning for the document type
676+
in which the expression is embedded (eg. an XML document). The textual equivalents are
677+
shown here: lt ('&lt;'), gt ('&gt;'), le ('&lt;='), ge ('&gt;='), eq ('=='), ne ('!='),
678+
div ('/'), mod ('%'), not ('!'). These are case insensitive.</para>
672679
</section>
673680

674681
<section xml:id="expressions-operators-logical">

0 commit comments

Comments
 (0)