Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiled SpEL expression fails if #root or #this is a non-public type #32356

Closed
sbrannen opened this issue Mar 2, 2024 · 0 comments
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@sbrannen
Copy link
Member

sbrannen commented Mar 2, 2024

If a SpEL expression references the root context object via the #root or #this variables, we currently insert a checkcast in the generated byte code that casts the object to its concrete type.

However if the root context object's type is non-public, that results in an IllegalAccessError when the compiled byte code is executed.

See the following test, for an example.

// custom CompilableMapAccessor via explicit #root & array index
expression = parser.parseExpression("#root.foo[1]");
assertThat(expression.getValue(context, map)).isEqualTo(2);
assertCanCompile(expression);
// TODO If map is created via Map.of(), the following fails with an IllegalAccessError.
//
// IllegalAccessError: failed to access class java.util.ImmutableCollections$Map1 from class
// spel.Ex2774 (java.util.ImmutableCollections$Map1 is in module java.base of loader 'bootstrap';
// spel.Ex2774 is in unnamed module of loader
// org.springframework.expression.spel.standard.SpelCompiler$ChildClassLoader @359b650b)
assertThat(expression.getValue(context, map)).isEqualTo(2);

Interestingly enough, VariableReference.getValueInternal(ExpressionState) already contains a "workaround" for global variables which inserts a checkcast to Object in the generated byte code instead of to the object's concrete non-public type.

I have a local fix that applies the same logic to #root/#this and global variables. Thus, this issue is here to provide public visibility and raise awareness.

@sbrannen sbrannen added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) labels Mar 2, 2024
@sbrannen sbrannen added this to the 6.1.5 milestone Mar 2, 2024
@sbrannen sbrannen self-assigned this Mar 2, 2024
@sbrannen sbrannen changed the title Compiled SpEL expression fails if #root context object is a non-public type Compiled SpEL expression fails if #root or #this is a non-public type Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

1 participant