Commit Graph

586 Commits

Author SHA1 Message Date
Sam Brannen
e7cf54d4e2 Revise SpEL inline collection caching improvements
This commit revises the contribution for gh-25921 in the following ways.

- Use instanceof pattern matching

- Use List.of() and Map.of()

- Add missing @⁠since tags

- Polish Javadoc

- Rename isNegativeNumber() to isNegativeNumberLiteral()

- Restructure InlineCollectionTests using @⁠Nested, etc.

- Fix testListWithVariableNotCached() test: it previously set a SpEL
  "variable" but tested a "property" in the root context object, which
  effectively did not test anything.

- Introduce additional tests: listWithPropertyAccessIsNotCached(),
  mapWithVariableIsNotCached(), and mapWithPropertyAccessIsNotCached().
2023-09-13 13:35:41 +02:00
Sam Brannen
2cc1ee78c1 Polishing 2023-09-13 13:33:21 +02:00
Sébastien Deleuze
5d454390f0 Polishing
See gh-25921
2023-09-13 10:29:32 +02:00
Semyon Danilov
6f9546722a Improve SpEL inline collection caching
This commit fixes SpEL inline collection caching with
with negative keys or values.

Closes gh-25921
2023-09-13 10:29:01 +02:00
Sam Brannen
154aec7d75 Merge branch '6.0.x' 2023-09-08 17:22:16 +02:00
Sam Brannen
10de295a72 Document StandardTypeLocator configuration to support user types
Prior to this commit, it was unclear to users and third parties that it
is necessary to manually configure a StandardTypeLocator with a
specific ClassLoader to ensure that the SpEL expression parser is able
to reliably locate user types.

For example, the StandardBeanExpressionResolver in the spring-context
module configures a StandardTypeLocator using the bean ClassLoader of
the corresponding BeanFactory.

This commit improves the documentation to raise awareness of this fact.

Closes gh-26253
2023-09-08 17:19:51 +02:00
Sam Brannen
f0b1133b12 Merge branch '6.0.x' 2023-09-08 16:12:29 +02:00
Sam Brannen
311c58ea2d Polish [Standard]TypeLocator 2023-09-08 15:21:48 +02:00
Sam Brannen
05790e36db Polish StandardTypeLocatorTests 2023-09-07 13:26:38 +02:00
Stephane Nicoll
8432f777aa Update copyright header of changed file
See gh-26028
2023-08-25 16:13:27 +02:00
hzmpay
cde476f90e Use computeIfAbsent in SpelCompiler and AdvisedSupport
See gh-26028
2023-08-25 16:12:08 +02:00
Juergen Hoeller
ecc0a6d2db Merge branch '6.0.x' 2023-08-23 19:02:44 +02:00
Juergen Hoeller
906a9f7982 Polishing 2023-08-23 18:52:55 +02:00
Juergen Hoeller
6fed3a0d6b Consistently throw ParseException instead of IllegalStateException
Closes gh-31097
2023-08-23 18:50:52 +02:00
Sam Brannen
1e3099759e Polishing 2023-08-20 19:32:07 +02:00
Harry Yang
0e0c298dcf Optimize InlineMap and InlineList in SpEL
- Make InlineList#constant and InlineMap#constant final.

- Add more assertions for InlineMap tests.

Closes gh-30251
2023-08-20 17:52:27 +02:00
Sébastien Deleuze
1e73439955 Support Kotlin value class properties in SpEL
This commit adds support for inlined Kotlin value
class properties in SpEL by leveraging Kotlin
reflection instead of Java reflection broken
by the mangled method name.

Closes gh-30468
2023-08-11 16:54:34 +02:00
Sam Brannen
526fc391ee Use Class#componentType() for consistency with arrayType()
Java 12 introduced java.lang.Class#componentType() as a shortcut for
getComponentType().

Since we started using arrayType() in fe5560400c, this commit switches
to componentType() for consistent API usage style.
2023-08-07 12:43:40 +03:00
Juergen Hoeller
bbde68c49e Polishing 2023-07-25 19:12:07 +02:00
Juergen Hoeller
5ebbb3ff3e Merge branch '6.0.x'
# Conflicts:
#	spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java
#	spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java
#	spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplate.java
2023-07-25 19:13:33 +02:00
Juergen Hoeller
25ea1f4c0f Merge branch '6.0.x'
# Conflicts:
#	spring-context/src/main/java/org/springframework/scheduling/support/CronSequenceGenerator.java
2023-07-19 00:37:06 +02:00
Juergen Hoeller
2f33e77ab4 Consistent equals/hashCode style (and related polishing) 2023-07-19 00:35:19 +02:00
Sam Brannen
a34f9fa66c Update copyright headers 2023-07-15 13:10:46 +02:00
Sam Brannen
5ce8ffd197 Merge branch '6.0.x' 2023-07-15 13:11:03 +02:00
Sam Brannen
16b9640af2 Merge branch '6.0.x' 2023-07-12 11:50:11 +02:00
Sam Brannen
68f2b0ca59 Rely on auto-boxing in tests 2023-07-12 11:49:02 +02:00
Sébastien Deleuze
b3de1b8e95 Use consistently *KotlinTests naming for Kotlin tests
Closes gh-30837
2023-07-08 11:02:20 +02:00
Sébastien Deleuze
8fb412ea74 Merge branch '6.0.x' 2023-07-08 11:11:37 +02:00
Sam Brannen
b8a713fde3 Merge branch '6.0.x' 2023-06-22 15:12:25 +02:00
Johnny Lim
271f2dc665 Polish
This commit polishes a bit.

Closes gh-30691
2023-06-22 15:06:05 +02:00
Sam Brannen
c9165470f2 Update test
See gh-30610
2023-06-07 15:04:28 +02:00
Sam Brannen
61816d0076 Merge branch '6.0.x' 2023-06-07 14:59:14 +02:00
Sam Brannen
5ad853ef5b Do not precede indexed access with a dot in SpEL AST representation
Prior to this commit, if a Spring Expression Language (SpEL) expression
contained indexed access to an object, the generated AST String
representation incorrectly included a dot ('.') before the index access.

For example, 'property[0]' had a generated AST string representation of
'property.[0]'.

This commit addresses this by reworking the logic in
CompoundExpression.toStringAST().

Closes gh-30610
2023-06-07 14:45:52 +02:00
Sam Brannen
c8c8f5722b Support letters other than A-Z in identifiers in SpEL
Prior to this commit, only the letters 'A' - 'Z' (ignoring case) were
supported in identifiers (i.e., property, field, and variable names).

This known (yet undocumented) limitation prevented the use of characters
such as 'ü', 'ñ', 'é' as well as letters from other character sets such
as Chinese, Japanese, Cyrillic, etc.

This commit lifts that restriction by delegating to Character.isLetter()
to determine if a character in a SpEL expression is a letter.

Closes gh-30580
2023-06-06 14:14:15 +02:00
Sam Brannen
cd610b3ed1 Merge branch '6.0.x' 2023-06-06 12:46:15 +02:00
Sam Brannen
7b20aefecf Improve error message for unsupported character in SpEL expression
Prior to this commit, when an unsupported character such as "ü" was
encountered in a SpEL expression, the error message was:

Cannot handle (252) 'ü'

With this commit, the error message is now similar to:

Unsupported character 'ü' (252) encountered at position 5 in expression.

See gh-30580
Closes gh-30602
2023-06-06 12:45:05 +02:00
Juergen Hoeller
5441796675 Polishing 2023-05-23 20:01:28 +02:00
Juergen Hoeller
876e417eb4 Javadoc for setVariables and registerFunction
See gh-30045
2023-05-23 20:01:02 +02:00
Sam Brannen
ab253470f0 Update copyright headers 2023-05-23 15:12:32 +02:00
Sam Brannen
d8215a62f6 Merge branch '6.0.x' 2023-05-10 17:40:42 +02:00
Sam Brannen
89bcee68bb Add author tag 2023-05-10 17:39:46 +02:00
Sam Brannen
96fbcb26c9 Merge branch '6.0.x' 2023-05-10 14:36:09 +02:00
Sam Brannen
aefcb9d2d6 Make maximum SpEL expression length configurable
Closes gh-30380
2023-05-10 14:35:36 +02:00
Sam Brannen
e51c71bcd6 Delete unused code 2023-05-10 14:26:41 +02:00
Simon Baslé
906c54faff Add SpEL support for registered MethodHandles
This commit adds support for MethodHandles in SpEL, using the same
syntax as user-defined functions (which also covers reflective Methods).

The most benefit is expected with handles that capture a static method
with no arguments, or with fully bound handles (where all the arguments
have been bound, including a target instance as first bound argument
if necessary). Partially bound MethodHandle should also be supported.

A best effort approach is taken to detect varargs as there is no API
support to determine if an argument is a vararg or an explicit array,
unlike with Method. Argument conversions are also applied. Finally,
array repacking is not always necessary with varargs so it is only
performed when the vararg is the sole argument to the invoked method.

See gh-27099
Closes gh-30045
2023-05-05 16:18:25 +02:00
Simon Baslé
d3c3088c6b Clarify behavior of the Elvis SpEL operator in documentation (#30352)
This commit improves both the javadoc and the reference guide section on
the Elvis SpEL operator to clarify that in addition to `null` objects,
empty Strings also lead the operator to evaluate to its second operand.

The reference guide's advanced snippet is modified to use such an empty
String instead of `null` to make that behavior prominent with some code.

See gh-30318
Closes gh-30352
2023-05-05 16:13:06 +02:00
Sam Brannen
de113f1d11 Reject null and empty SpEL expressions
Prior to gh-30325, supplying a null reference for a SpEL expression was
effectively equivalent to supplying the String "null" as the
expression. Consequently, evaluation of a null reference expression
always evaluated to a null reference. However, that was accidental
rather than by design.

Due to the introduction of the checkExpressionLength(String) method in
InternalSpelExpressionParser (in conjunction with gh-30325), an attempt
to evaluate a null reference as a SpEL expression now results in a
NullPointerException.

To address both of these issues,
TemplateAwareExpressionParser.parseExpression() and
SpelExpressionParser.parseRaw() now reject null and empty SpEL
expressions.

Closes gh-30371
2023-04-25 13:46:30 +02:00
Sam Brannen
ca13b5cbca Polish SpelParserTests and TemplateExpressionParsingTests 2023-04-25 13:46:30 +02:00
Sam Brannen
be17c8d85f Disable variable assignment in SimpleEvaluationContext
This commit introduces infrastructure to differentiate between
programmatic setting of a variable in an EvaluationContext versus the
assignment of a variable within a SpEL expression using the assignment
operator (=). In addition, this commit disables variable assignment
within expressions when using the SimpleEvaluationContext.

Closes gh-30326
2023-04-13 09:40:23 +02:00
Sam Brannen
b73f5fcac2 Limit SpEL expression length
This commit enforces a limit of the maximum size of a single SpEL
expression.

Closes gh-30325
2023-04-13 09:39:53 +02:00