-
Notifications
You must be signed in to change notification settings - Fork 38.5k
VerifyErrors when using SpEL compilation with Thymeleaf [SPR-12271] #16876
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
Comments
Joris Kuipers commented Updated stack trace after switching to thymleaf-spring4 to rule that out as a possible cause |
Juergen Hoeller commented Andy Clement, any idea for the root cause of that Juergen |
Andy Clement commented I probably need to see the particular expression. Can we get a quick demo project together that contains the failure, then I'll take a look? If it was a representative example of thymeleaf in a project i can also fix up any other compile issues that exist in it at the same time (if there are any). |
Joris Kuipers commented That sounds like a good plan: I'll try to whip up a small project (can probably use Spring Boot for that) that uses Thymeleaf with some representative SpEL expressions and will make sure that I can reproduce the error with that. |
Joris Kuipers commented I've attached a Spring Boot app that uses a Thymeleaf view with several expressions (it's secured with username 'user' and password 'secret', so that I could test a Security SpEL expression as well). |
Joris Kuipers commented OK, did a little more investigation using the problematic app and found the expression that's causing the problem: it's reproducable. This one causes a VerifyError: <span th:text="${#strings.contains(#httpServletRequest.servletPath, 'organisation') ? 'active' : ''}">boom</span>. |
Andy Clement commented Not all expressions are compilable right now. When they aren't it should just silently not compile them - if it makes a mistake in that decision process and produces a class anyway it can lead to a verify error. Initial effort has been spent on compiling specific kinds of expression that benefited some Spring Integration/XD environments, but the framework is there to add more over time. Let me find out what the verify error is - thanks for the test case. I'll also take a look at what is or is not compilable of the set in this sample. |
Joris Kuipers commented Thanks. BTW, looking at the code that determines if an expression is compilable I got the impression that Thymeleaf should change their code to ensure that something like simple property access (pretty common in a web view) would be compilable. Any tips on doing that (in a Spring 4.0-compatible manner) would be much appreciated as well, I can file some issues in their JIRA for that. |
Andy Clement commented What an exciting bunch of expressions in there :) With a variety of reasons for not compiling. I breakpointed on expression compilation:
|
Andy Clement commented To turn our regular map accessor into a CompilablePropertyAccessor we added these methods:
|
Andy Clement commented I just pushed the fixes to address the problem expression:
In fact there were two problems:
With these changes in place that expression compiles. |
Juergen Hoeller commented Thanks for the thorough analysis and quick turnaround, Andy! I'll mark this as resolved for 4.1.2 then. We still got a few weeks for further testing before the release... Juergen |
Joris Kuipers commented Nice, glad that the issues could be fixed. I guess for now enabling this support for Thymeleaf views will probably not result in much of a speed improvement given that most expressions will not be compiled, but at least now I can further investigate if this is indeed the case :) |
Andy Clement commented Hey Joris - do we have any measurements to verify that compiling these expressions will make a difference? Or are we just hoping it will? Just asking before I dive into spending time compiling these kinds of expression, I'd hate to do loads of work and it to have no appreciable effect. |
Joris Kuipers commented Hi Andy, Thymeleaf view rendering in general is quite slow compared to something like JSPs or Freemarker. Some initial testing using the new Java Flight Recorder suggested that expression evaluation was contributing to this, but I haven't done proper profiling yet. I'll see if I can get you some numbers today. |
Joris Kuipers commented It took me a while to get back to providing some numbers. I've done some profiling and found some pretty big performance issues in Thymeleaf that prevent the SpEL expression evaluation from being a real bottleneck: not sure that's a good thing, though ;) I've been trying to work on those issues first. |
Andy Clement commented Thanks for getting back to me Joris. Under #16933 I am addressing a few more scenarios for compilation, one of which I saw in this setup, namely invocation of a varargs method. Then the key ones I will be considering are custom property accessors and selection/projection. |
Uh oh!
There was an error while loading. Please reload this page.
Joris Kuipers opened SPR-12271 and commented
I tried to enable SpEL compilation support in my project using
-Dspring.expression.compiler.mode=immediate
. This project uses Thymeleaf for views, and thus relies rather heavily on SpEL expressions.When running the application I can see that the compiler kicks in, but I'm seeing VerifyErrors on the generated SpEL classes:
I haven't tried to dig any deeper into the root cause, as byte code generation isn't really my cup of tea.
Thymeleaf has a lot of runtime overhead compared to JPSs or FreeMarker: if Spring could support compiled SpEL expressions in Thymeleaf views I think it could have a very positive impact on performance, so I'm eager to get this to work.
Affects: 4.1 GA
Attachments:
Issue Links:
Referenced from: commits bd7d56a
The text was updated successfully, but these errors were encountered: