StackOverflowError when editing model

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

StackOverflowError when editing model

MartinW
Hi,

we have a processor created that responds to y:noIndex attributes.

<div y:noIndex>
   <some body elements>
</div>

The task is to add comments before and after the complete model body for the Google Search Appliance to turn off indexing for these contents.

Desired result:

<!-- googleoff: index -->
<div>
   <some body elements>
</div>
<!-- googleon: index -->

In order to get access to full body (OpenElement till CloseElement) we created an AttributeModelProcessor.
Adding a comment behind the CloseElement was simple:

model.add(modelFactory.createComment("googleon: index"));

We thought it would be also as simple to insert a new comment at the beginning.

model.insert(0, modelFactory.createComment("googleoff: index"));

But with this we run into StackOverflowError!
The stacktrace is showing approx. 1000 line with the following messages repeated again and again

        at org.thymeleaf.engine.GatheringModelProcessable.process(GatheringModelProcessable.java:78)
        at org.thymeleaf.engine.ProcessorTemplateHandler.handleCloseElement(ProcessorTemplateHandler.java:1640)
        at org.thymeleaf.engine.CloseElementTag.beHandled(CloseElementTag.java:139)
        at org.thymeleaf.engine.Model.process(Model.java:282)
        at org.thymeleaf.engine.ProcessorTemplateHandler.handleOpenElement(ProcessorTemplateHandler.java:1587)
        at org.thymeleaf.engine.OpenElementTag.beHandled(OpenElementTag.java:205)
        at org.thymeleaf.engine.Model.process(Model.java:282)
        at org.thymeleaf.engine.Model.process(Model.java:290)
        at org.thymeleaf.engine.GatheringModelProcessable.process(GatheringModelProcessable.java:78)
        at org.thymeleaf.engine.ProcessorTemplateHandler.handleCloseElement(ProcessorTemplateHandler.java:1640)
        at org.thymeleaf.engine.CloseElementTag.beHandled(CloseElementTag.java:139)
        at org.thymeleaf.engine.Model.process(Model.java:282)
        at org.thymeleaf.engine.ProcessorTemplateHandler.handleOpenElement(ProcessorTemplateHandler.java:1587)
        at org.thymeleaf.engine.OpenElementTag.beHandled(OpenElementTag.java:205)
        at org.thymeleaf.engine.Model.process(Model.java:282)
        at org.thymeleaf.engine.Model.process(Model.java:290)
        at org.thymeleaf.engine.GatheringModelProcessable.process(GatheringModelProcessable.java:78)

We have tried a lot and searched already for similar problems.
We have found a thymeleaf issue reported more than a year ago with similar error.
https://github.com/thymeleaf/thymeleaf/issues/518
It tells us that this has been fixed. Nevertheless, we have no idea how to solve that.
Any suggestions?

Thanks in advance
Martin
Reply | Threaded
Open this post in threaded view
|

Re: StackOverflowError when editing model

danielfernandez
Administrator
Quick question: is your processor also removing the "y:noIndex" attribute from the host element? attributes are re-scanned after each processor execution (so that processors can add new attributes), so if not, this can be a cause for your error.

Depending on the abstract class you are extending from, you could have the possibility to do so just by signaling it at the constructor. If not... just remove it manually at the end of the processor.
Reply | Threaded
Open this post in threaded view
|

AW: StackOverflowError when editing model

MartinW
This post was updated on .
Hi Daniel,

we do remove the matched attribute via constructor. Yes.

Best regards,
Martin

[cid:image003.png@01D35890.C4D90C10]
Reply | Threaded
Open this post in threaded view
|

Re: AW: StackOverflowError when editing model

danielfernandez
Administrator
OK, this looks like a bug, or at least something that should be improved (because not 100% attribute removal cases can be covered).

The "removeAttribute" flag is triggering the attribute removal on the first element in the modified model, but by the time it does that --after execution--, such "first element" has been modified because you've inserted a comment at the beginning.

Could you please register this at https://github.com/thymeleaf/thymeleaf/issues ? thanks a lot.

The workaround for now would be to perform the attribute removal manually in your processor code.

Regards,
Daniel.
Reply | Threaded
Open this post in threaded view
|

Re: AW: StackOverflowError when editing model

MartinW
This post was updated on .
Hi Daniel,

thanks for your help. Removing the attribute manually helps perfectly.
Issue registered at https://github.com/thymeleaf/thymeleaf/issues/653

Best regards
Martin