Commit Graph

138 Commits

Author SHA1 Message Date
Juergen Hoeller
2e7489d124 Allow null operands in compiled SpEL numeric operator expressions
Closes gh-22358
2019-05-03 16:10:44 +02:00
Spring Operator
6c4f510496 URL Cleanup - license headers
This commit updates URLs to prefer the https protocol. Redirects are not followed to avoid accidentally expanding intentionally shortened URLs (i.e. if using a URL shortener).

These URLs were switched to an https URL with a 2xx status. While the status was successful, your review is still recommended.

* [ ] http://www.apache.org/licenses/ with 1 occurrences migrated to:
  https://www.apache.org/licenses/ ([https](https://www.apache.org/licenses/) result 200).
* [ ] http://www.apache.org/licenses/LICENSE-2.0 with 5990 occurrences migrated to:
  https://www.apache.org/licenses/LICENSE-2.0 ([https](https://www.apache.org/licenses/LICENSE-2.0) result 200).

See gh-22632
2019-03-23 15:04:55 +01:00
Juergen Hoeller
6a5d986b33 Fix SpEL compilation for non trivial elvis operand
Issue: SPR-17214
2018-09-07 13:19:47 +02:00
Juergen Hoeller
6a727e1ed7 OperatorMatches flags misguided evaluation attempts as FLAWED_PATTERN
Issue: SPR-16731

(cherry picked from commit d4a55a2)
2018-04-17 13:46:37 +02:00
Andy Clement
d3acf45ea4 Modify SpEL code gen to take account of null safe refs
With this change the code generation for method and property
references is modified to include branching logic in the
case of null safe dereferencing (?.). This is complicated
by the possible usage of primitives on the left hand side
of the dereference. To cope with this case primitives are
promoted to boxed types when this situation occurs enabling
null to be passed as a possible result.

Issue: SPR-16489
2018-04-05 14:36:36 -07:00
Juergen Hoeller
f32b13c5b3 Restored original 4.3.x expectation for property access on null target 2018-03-28 11:40:24 +02:00
Juergen Hoeller
9cc03fa8b0 Polishing 2018-03-28 02:03:31 +02:00
Juergen Hoeller
65a8aa1c09 Backported DataBindingPropertyAccessor and DataBindingMethodResolver
Issue: SPR-16588
2018-03-28 01:22:59 +02:00
Juergen Hoeller
bc043245cc Polishing 2018-03-03 17:18:44 +01:00
Juergen Hoeller
722cb36e01 Consistent Class array vs vararg declarations (and related polishing)
(cherry picked from commit 3b810f3)
2018-02-14 16:38:28 +01:00
Juergen Hoeller
6dc73469f9 MethodReference treats proxy-targeting expressions as non-compilable
Issue: SPR-16191

(cherry picked from commit c30145d)
2017-11-14 12:28:15 +01:00
Juergen Hoeller
9cc3349e2d Introspect interface-declared methods in case of proxy (for varargs)
Issue: SPR-16122

(cherry picked from commit 419b444)
2017-10-27 11:30:52 +02:00
Juergen Hoeller
d0d4421aea Tokenizer uses single process step and length-based exhaustion check
Issue: SPR-16032

(cherry picked from commit 03b6828)
2017-10-04 13:18:04 +02:00
Juergen Hoeller
4b2bad96ce Polishing
(cherry picked from commit efc5b47)
2017-07-14 17:41:26 +02:00
Juergen Hoeller
1513c4a952 Expression javadoc alignment
(cherry picked from commit 1ad6180)
2017-07-14 17:12:50 +02:00
Juergen Hoeller
bb6d9fabee Expression alignment and related polishing (backported from master) 2017-07-14 15:41:38 +02:00
Juergen Hoeller
bffcd33ea3 PropertyOrFieldReference checks cached PropertyAccessor against current EvaluationContext
Issue: SPR-15769
(cherry picked from commit bcf9f21)
2017-07-14 15:40:52 +02:00
Andy Clement
7879bdfc1d Fix compilation of SpEL elvis/ternary expressions
Without this fix the compiled version of elvis
actual behaved differently to the interpreted version
if the value being queried was an empty string. This
is now fixed. It also now correctly handles the
query value being a primitive and addresses the
findings of SPR-15192 where some type inferencing
logic was trying to be too clever, that code has
been deleted.

Issue: SPR-15192
(cherry picked from commit d41d28f)
2017-02-18 00:50:30 +01:00
Juergen Hoeller
5f90a7eee9 Delegate to common ClassUtils.getQualifiedName
Issue: SPR-15237
(cherry picked from commit 81aca78)
2017-02-10 11:47:00 +01:00
Juergen Hoeller
5ca10b1d67 Consistent ExpressionException-style quoting of expression string and position
Issue: SPR-14942
(cherry picked from commit 14eba50)
2016-12-01 14:10:23 +01:00
Andy Clement
38cd1ecff4 Rework compilation of OpNE/OpEQ SpEL operators
For SPR-14863 we need to adjust the code generation for OpNE
to use !x.equals(y) rather than x!=y. There are also further
cases in the equalityCheck() code in Operator that were not
being handled in the compilation case (when comparators are
used for example). This latter issue also affects OpEQ.

Rather than add yet more bytecode generation, both OpNE and
OpEQ generateCode() methods have been simplified. The
generated code now delegates to equalityCheck() in Operator
which is exactly what the interpreted case does.

This ensures that the compiled code continues to behave just
like the interpreted case. It ensures changes to the interpreted
case are automatically picked up for the compiled case. It
makes the bytecode generation simpler.

The benefit of compilation of SpEL expressions is to avoid
slow reflective calls - that doesn't apply for a basic
(in)equality test so there is no need to go crazy in bytecode
gen.

Issue: SPR-14863
(cherry picked from commit 9000acd)
2016-11-02 12:40:24 +01:00
Andy Clement
a31f0bb3c0 Fix compilation of expressions using instanceof and primitives
Prior to this commit the SpEL compiler would generate bad bytecode
if the left hand operand of an instanceof was a primitive or
if the right hand operand was a primitive type reference.
With the fixes primitives on the left hand side are now
correctly boxed and special handling is in place for when the
right hand side is a primitive type reference. Using a primitive
type reference on the right always causes the instanceof
check to return false.

Additionally a guard has been added such that compilation is
not allowed when the right hand side of an expression
is not a type reference. If it is, for example, a variable
reference that evaluates to a type reference then that
cannot be expressed in bytecode so compilation is not performed.

Issue: SPR-14250
2016-05-05 09:57:15 -07:00
Johnny Lim
44e652f99e Remove duplicate words
Closes gh-1039
2016-04-19 08:24:21 +02:00
Juergen Hoeller
4ae065996b Polishing
(cherry picked from commit aa5c12c)
2016-04-08 23:06:25 +02:00
Juergen Hoeller
517ebd1d3e Consistent formatting 2016-03-24 19:22:50 +01:00
Sam Brannen
61824b1ade Remove trailing whitespace from source code 2016-02-29 18:52:57 +01:00
Juergen Hoeller
43bcab9c1a ReflectiveMethodResolver lets local static methods override java.lang.Class methods
Issue: SPR-13918
2016-02-08 13:23:02 +01:00
Andy Clement
a12f23936c Allow use of '&' prefix to access factory bean in SpEL
Prior to this change SpEL did not have an syntactic
construct enabling easy access to a FactoryBean. With this
change it is now possible to use &foo in an expression when
the factory bean should be returned.

Issue: SPR-9511
2016-01-21 16:14:16 -08:00
Andy Clement
a28fc760ba Fix SpEL compilation of static method/property/field operations
Before this change the compilation of a method reference or property/field
access was not properly cleaning up the stack if compilation meant
calling a static method or accessing a static field. In these cases there
is no need for a target object on the stack and it should be removed if
present. For a simple expression it is harmless since the end result of
the expression is the thing on the top of the stack, but for nested
expressions if the inner expression suffered this issue, the outer
expression can find itself operating on the wrong element.

The particular issue covered the case of a static field access but this
fix (and associated tests) cover static method, property and field access.

Issue: SPR-13781
2015-12-11 15:59:40 -08:00
Juergen Hoeller
8c4436926f Polishing 2015-11-26 02:09:37 +01:00
Juergen Hoeller
fd84262e71 Polishing 2015-11-25 23:09:24 +01:00
Andy Clement
58756b023c Ensure cast correctly included for OpPlus compilation
When the plus operator is used between strings in a SpEL
expression and that expression is compiled, it is
important to include a cast if computation of any of
the operands isn't obviously leaving strings on the
stack. Likewise if the stack contents are known to
be strings, a cast should not be included.

Issue: SPR-12426
2015-11-24 16:35:08 -08:00
Sam Brannen
b6c0e7cba3 Remove trailing whitespace in Java source code 2015-07-27 12:40:54 +02:00
Juergen Hoeller
0783a1c667 SpEL selection/projection works with Iterable as well
Issue: SPR-13231
2015-07-15 11:22:52 +02:00
Sam Brannen
3f0a6e814c Suppress warnings in spring-expression tests 2015-07-04 15:46:36 +02:00
Sam Brannen
078d252d1e Delete trailing whitespace in Java source code 2015-06-19 17:09:52 +02:00
Sam Brannen
7018747cec Remove trailing whitespace in Java source code 2015-05-29 02:03:44 +02:00
Andy Clement
91ed5b6b8c SpEL: ensure correct object used for nested #this references
Before this commit the object that #this would refer to in
nested expressions within projection/selection clauses was always
the root context object. This was incorrect as it should be the
element being projected/selected over. This commit introduces
a scope root context object which is set upon entering a new
scope (like when entering a projection or selection). Any
object. With this change this kind of expression now behaves:

where #this is the element of list1. Unqualified references
are also resolved against this scope root context object.

Issues: SPR-10417, SPR-12035, SPR-13055
2015-05-22 08:07:09 -07:00
Sam Brannen
7a690df925 Remove trailing whitespace from Java source code 2015-05-06 20:08:42 +02:00
Andy Clement
c382b6f059 Allow NEW and T to be used as unquoted map keys in SpEL
This change provides support for map[NEW], map[new], map[T]
and map[t]. Prior to this change the 'new' and 't' had to
be quoted because they were keywords in SpEL for a constructor
reference and type reference respectively.

Issue: SPR-11783
2015-03-30 16:20:04 -07:00
Juergen Hoeller
9d47a2b87e Explicit test for default useDistance mode
Issue: SPR-12808
2015-03-13 18:16:58 +01:00
Juergen Hoeller
348eb91891 ReflectiveMethodResolver applies useDistance mode by default (with fine-tuned varargs handling)
Issue: SPR-12803
Issue: SPR-12808
2015-03-11 22:09:03 +01:00
Sam Brannen
d90cee78ef Remove trailing whitespace in source code 2015-03-07 21:16:18 +01:00
Andy Clement
b7ef04767a Reduce SpEL compilation restrictions on mathematical expressions
Prior to this change the SpEL compiler would not compile mathematical
expressions where the operands were of differing types (e.g. int
and double). This required the expression writer to do the conversion
in the expression text. For example:

T(Integer).valueOf(someInt).doubleValue()/35d

With this commit the restriction is lifted and it is more like Java
so that you can simply do someInt/35d. The mathematical operators
affected are divide/plus/minus/multiply and modulus. This change
involved removing some guards so that the exitTypeDescriptor (the
trigger for whether compilation is allowed) is set more frequently
and enhancing bytecode generation to perform more sophisticated
conversion/coercion automatically.

Issue: SPR-12789
2015-03-06 10:32:42 -08:00
Juergen Hoeller
fa138d2c70 ReflectionHelper's isFirstEntryInArray properly handles empty arrays
Issue: SPR-12522
2014-12-22 19:54:16 +01:00
Andy Clement
abc3cc4dc4 Ensure correct boxing in compiled code for OpEq with primitives
Without this change when the operands to an == are a mix of a
reference type and a primitive, the failure to box the primitive
would result in a verifyerror when the compiled code is loaded.

Issue: SPR-12557
2014-12-18 13:46:55 -08:00
Juergen Hoeller
9ef0bdcb17 Consistent resolution of Class methods and static methods
Issue: SPR-12502
2014-12-03 23:03:24 +01:00
Andy Clement
94ee763bc8 Fix bytecode generation for SpEL OpPlus
Without this change the plus operator would fail to
include a CHECKCAST in generated bytecode when it
was compiled in cases where one of the operands
has a runtime type of String but a statically
declared type that was not String (i.e. Object).

Issue: SPR-12426
2014-11-13 08:12:43 -08:00
Juergen Hoeller
e989b2621f Test for cyclic type declaration handling in TypeDescriptor
Issue: SPR-9735
(cherry picked from commit 7fa3e65)
2014-11-02 11:40:58 +01:00
Andy Clement
03fc9e89a0 Fixed isWritable for badly formed SpEL expressions
Before this change isWritable() could return true
for a badly formed expression. That is because the
decision about whether something is writable was made
based on the node type rather than whether the node
represented something that could actually be resolved
to be a real thing. This change ensures a resolution
check is done and isWritable() should only return
true if a subsequent setValue() will succeed.

Issue: SPR-10610
2014-10-27 11:35:51 -07:00