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

Random SpelEvaluationException with T() operator - EL1005E: Type cannot be found #244

Closed
jjpianta opened this issue Dec 10, 2020 · 4 comments

Comments

@jjpianta
Copy link

Hi,
we are experiencing such a strange behavior with our thymeleaf templates using SPEL T() operator to get references to custom enums or types: everything goes straight till we get random failures in resolving our custom types.
"random" means that same template sometimes get parsed properly and sometimes don't.
It looks like failures occur only in asynch context (StreamingResponseBody's callbacks and @‌Asynch annotated methods)

org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "myVar == T(my.custom.TypeEnum).VALUE)" (template: "myTemplate" - line xx, col yy)
        at org.thymeleaf.spring4.expression.SPELVariableExpressionEvaluator.evaluate(SPELVariableExpressionEvaluator.java:290) ~[thymeleaf-spring4-3.0.11.RELEASE.jar:3.0.11.RELEASE]
        at org.thymeleaf.standard.expression.VariableExpression.executeVariableExpression(VariableExpression.java:166) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
        at org.thymeleaf.standard.expression.SimpleExpression.executeSimple(SimpleExpression.java:66) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
 ...
        at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:592) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
        at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098) [thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
        at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1059) [thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
        at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1048) [thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
...
        at org.springframework.aop.interceptor.AsyncExecutionInterceptor$1.call(AsyncExecutionInterceptor.java:115) [spring-aop-4.3.29.RELEASE.jar:4.3.29.RELEASE]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_201]
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1005E: Type cannot be found 'my.custom.TypeEnum'
        at org.springframework.expression.spel.support.StandardTypeLocator.findType(StandardTypeLocator.java:115) ~[spring-expression-4.3.29.RELEASE.jar:4.3.29.RELEASE]
        at org.springframework.expression.spel.ExpressionState.findType(ExpressionState.java:154) ~[spring-expression-4.3.29.RELEASE.jar:4.3.29.RELEASE]
        at org.springframework.expression.spel.ast.TypeReference.getValueInternal(TypeReference.java:64) ~[spring-expression-4.3.29.RELEASE.jar:4.3.29.RELEASE]
        at org.springframework.expression.spel.ast.CompoundExpression.getValueRef(CompoundExpression.java:52) ~[spring-expression-4.3.29.RELEASE.jar:4.3.29.RELEASE]
        at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:88) ~[spring-expression-4.3.29.RELEASE.jar:4.3.29.RELEASE]
        at org.springframework.expression.spel.ast.OpEQ.getValueInternal(OpEQ.java:43) ~[spring-expression-4.3.29.RELEASE.jar:4.3.29.RELEASE]
        at org.springframework.expression.spel.ast.OpEQ.getValueInternal(OpEQ.java:32) ~[spring-expression-4.3.29.RELEASE.jar:4.3.29.RELEASE]
        at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:169) ~[spring-expression-4.3.29.RELEASE.jar:4.3.29.RELEASE]
        at org.springframework.expression.spel.ast.OpAnd.getBooleanValue(OpAnd.java:56) ~[spring-expression-4.3.29.RELEASE.jar:4.3.29.RELEASE]
        at org.springframework.expression.spel.ast.OpAnd.getValueInternal(OpAnd.java:51) ~[spring-expression-4.3.29.RELEASE.jar:4.3.29.RELEASE]
        at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:169) ~[spring-expression-4.3.29.RELEASE.jar:4.3.29.RELEASE]
        at org.springframework.expression.spel.ast.Ternary.getValueInternal(Ternary.java:51) ~[spring-expression-4.3.29.RELEASE.jar:4.3.29.RELEASE]
        at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:119) ~[spring-expression-4.3.29.RELEASE.jar:4.3.29.RELEASE]
        at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:327) ~[spring-expression-4.3.29.RELEASE.jar:4.3.29.RELEASE]
        at org.thymeleaf.spring4.expression.SPELVariableExpressionEvaluator.evaluate(SPELVariableExpressionEvaluator.java:263) ~[thymeleaf-spring4-3.0.11.RELEASE.jar:3.0.11.RELEASE]
        ... 53 more

see full stack trace

  • Thymeleaf

    • thymeleaf-3.0.11.RELEASE.jar
    • thymeleaf-spring4-3.0.11.RELEASE.jar
  • Environment

    • java 1.8.0_201-b09
    • tomcat 8.5.39
    • spring-aop-4.3.29.RELEASE.jar
    • spring-aspects-4.3.29.RELEASE.jar
    • spring-beans-4.3.29.RELEASE.jar
    • spring-context-4.3.29.RELEASE.jar
    • spring-context-support-4.3.29.RELEASE.jar
    • spring-core-4.3.29.RELEASE.jar
    • spring-expression-4.3.29.RELEASE.jar
    • spring-jdbc-4.3.29.RELEASE.jar
    • spring-jms-4.3.29.RELEASE.jar
    • spring-messaging-4.3.29.RELEASE.jar
    • spring-orm-4.3.29.RELEASE.jar
    • spring-security-acl-4.2.19.RELEASE.jar
    • spring-security-config-4.2.19.RELEASE.jar
    • spring-security-core-4.2.19.RELEASE.jar
    • spring-security-oauth-2.4.0.RELEASE.jar
    • spring-security-openid-4.2.19.RELEASE.jar
    • spring-security-taglibs-4.2.19.RELEASE.jar
    • spring-security-web-4.2.19.RELEASE.jar
    • spring-tx-4.3.29.RELEASE.jar
    • spring-web-4.3.29.RELEASE.jar
    • spring-webmvc-4.3.29.RELEASE.jar
@danielfernandez
Copy link
Member

Due to the nature of the issue, I would be more inclined to see this as a possible Spring (SpEL) issue, not Thymeleaf. Thymeleaf should have no influence in SpEL being able to identify (or not) a type in a class loader. Could you please verify if maybe this is a known Spring issue, or whether this happens to you using more modern major versions of Spring? (I mean one of the latest 5.x)

@jjpianta
Copy link
Author

Thanks, same issue submitted to spring guys

@danielfernandez
Copy link
Member

I've been exploring all uses of StandardEvaluationContext and its subclass ThymeleafEvaluationContext in Thymeleaf and the referenced StandardTypeLocator is never set nor used directly, and the only constructor used for StandardEvaluationContextis the default one, so I'm assuming it's not Thymeleaf who's making this locator reference different class loaders among executions…

@sbrannen
Copy link

sbrannen commented Sep 8, 2023

Hi @danielfernandez,

Regarding spring-projects/spring-framework#26253, we turned that into a documentation issue to raise awareness of the need to configure a suitable ClassLoader for the SpEL expression parser.

For example, we've added the following note.

If your application or framework manages its own EvaluationContext, you may need 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.

In light of that, you may also consider reopening this issue to see if you can address this in Thymeleaf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants