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

When using Gretty with the Thymeleaf Layout Dialect, an exception was thrown when visiting a layout-applied page. #237

Open
mklinkj opened this issue Jun 25, 2023 · 2 comments
Assignees
Labels

Comments

@mklinkj
Copy link

mklinkj commented Jun 25, 2023

Hello.

When running the web server with Gretty.. When accessing the layout page, the following exception is exposed and nothing appears on the web browser screen.

  • Exception Log

    Caused by: java.lang.ClassCastException: class nz.net.ultraq.thymeleaf.layoutdialect.models.extensions.EventIterator cannot be cast to class [Ljava.lang.Object; (nz.net.ultraq.thymeleaf.layoutdialect.models.extensions.EventIterator is in unnamed module of loader java.net.URLClassLoader @889d9e8; [Ljava.lang.Object; is in module java.base of loader 'bootstrap')
            at org.codehaus.groovy.runtime.dgm$236.doMethodInvoke(Unknown Source) ~[groovy-4.0.10.jar:4.0.10]
            at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:321) ~[groovy-4.0.10.jar:4.0.10]
            at nz.net.ultraq.thymeleaf.layoutdialect.models.extensions.IModelExtensions.find(IModelExtensions.groovy:117) ~[thymeleaf-layout-dialect-3.2.1.jar:?]
            ...
    

My project environment looks like this

  • Spring 6 (Not Spring Boot )
  • Thymeleaf
    • thymeleaf-spring6: 3.1.1.RELEASE
    • thymeleaf-layout-dialect: 3.2.1
  • Gretty 4.0.3
    • Tomcat 10.1.10

When I run the web project, I run it with the command below.

gradle clean appRun

When I ran Gretty and accessed the page with the layout applied, I definitely saw the aforementioned exception.

However, there are two things that are unusual.

✨ Two unusual things

  1. If I'm using a direct deployment of Tomcat without using Gretty, I don't get the exception.

  2. If I use https://github.com/zhanhb/thymeleaf-layout-dialect, there's no problem running a web project with Gretty.

      // TODO: Using gretty with thymeleaf-layout-dialect causes an exception
      implementation "nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:${thymeleafLayoutVersion}"
      // TODO: If I use the thymeleaf-layout-dialect modified by zhanhb, the exception does not occur.
      // implementation "com.github.zhanhb:thymeleaf-layout-dialect:${zhanhbThymeleafLayoutVersion}"

✨ Example project to see the problem

I've created an example project for you to see the issue.

Thank you. Have a nice day. 👍

mklinkj referenced this issue in mklinkj/the-art-of-java-web-programming-study Jun 25, 2023
- 질문도 올렸다.
  `https://github.com/ultraq/thymeleaf-layout-dialect/issues/237`
- 어떤 사람이 패치한 버전을 쓰면 문제가 없음.

- 그외 Webjars 로케이터 정상 동작 확인해서, 사용자 정의 컨트롤러는 제거했다. (WebJarsController)
@ultraq ultraq added the bug label Nov 15, 2023
@ultraq ultraq self-assigned this Nov 15, 2023
@ultraq
Copy link
Owner

ultraq commented Nov 17, 2023

Hey there, sorry to take so long getting back to you on this one as this is an interesting bug and had me stumped for a very long time. However, I gave it another look this weekend and found the issue.

The Gretty plugin is written against Groovy 3, and introduces Groovy 3 JARs into the classloader of the servlet container that is being launched (Tomcat 10 in this case). However, version 3.1.0 and newer of the Thymeleaf Layout Dialect is written in Groovy 4, and so this mixup of Groovy versions causes the issues that you're seeing.

The only workarounds I can think of right now are:

  • to run Tomcat directly (as you've found, this doesn't cause the issue)
  • to use the Java-only port of the layout dialect by zhanhb
  • to use a version of the layout dialect before the move to Groovy 4, like version 3.0.0 (I've tested this using your example project and it works)
  • or, since you're using Spring, to use something like Spring Boot so that Tomcat can be bundled with your project and also includes a Gradle plugin to use in your build file

I hope that gives you some options to consider. Thank you again for the bug report and the example project which helped me figure out what was going on 🙇‍♂️

@mklinkj
Copy link
Author

mklinkj commented Nov 18, 2023

Thanks for your answer.

I posted the question in two places, so there’s also an issue on Gretty’s Github. 😅

gretty-gradle-plugin/gretty#289

Have a nice day. 👍

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

No branches or pull requests

2 participants