ultraq / thymeleaf-layout-dialect

A dialect for Thymeleaf that lets you build layouts and reusable templates in order to improve code reuse

Home Page:https://ultraq.github.io/thymeleaf-layout-dialect/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

empty <head> in content page results in ERROR ArrayIndexOutOfBoundsException: -2

BigGitWorld opened this issue · comments

Hi.
Environment:
thymeleaf-layout-dialect : version 2.3.0
thymeleaf version: 3.0.11.RELEASE

Scenario:
I'm using layout:decorate for different content pages.
Here:

product-tabs.html -> decorate file
product-tabs-impl.html -> page content file

Error:
When I used an empty <head></head> tag in my content HTML file, I got the following error:

org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "...")

Caused by: org.attoparser.ParseException: Error during execution of processor 'nz.net.ultraq.thymeleaf.decorators.DecorateProcessor' (template: "product-tabs-impl" - line 4, col 7)

Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'nz.net.ultraq.thymeleaf.decorators.DecorateProcessor' (template: "product-tabs-impl" - line 4, col 7)

Caused by: java.lang.ArrayIndexOutOfBoundsException: -2

and my sample content page product-tabs-impl.html :

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorate="layout/product-tabs">

<head>
</head>

<div layout:fragment="tab-table">aaa</div>
<div layout:fragment="tab-comment">bbb</div>
<div layout:fragment="tab-faq">ccc</div>
<div layout:fragment="tab-compare">ddd</div>

</html>

Solution:
I did remove the above empty <head></head> tag from the product-tabs-impl.html (content page) and everything works fine.

Thanks for the thorough bug report! One thing to check: you've listed that you're using version 2.3.0 of the layout dialect, are you able to try the latest version, 2.5.1, to see if it fixes the problem?

I've had some trouble replicating this issue with the latest code. I can see in version 2.3.0 though what might be the cause of this -2 bug:

int findPositionForModel(IModel headModel, IModel childModel) {
return childModel.whitespace ? -1 : headModel.size() - 2
}

That code changed in version 2.4.0, so I hope that means it's fixed from then. Thanks for filing the bug though so that anybody else on 2.3.0 who encounters this has some solutions.