You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Lukasz Lenart (Jira)" <ji...@apache.org> on 2026/08/24 12:32:00 UTC
[jira] [Resolved] (WW-5690) Defer loading the dev-mode error template until first use
[ https://issues.apache.org/jira/browse/WW-5690?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Lukasz Lenart resolved WW-5690.
-------------------------------
Resolution: Fixed
> Defer loading the dev-mode error template until first use
> ---------------------------------------------------------
>
> Key: WW-5690
> URL: https://issues.apache.org/jira/browse/WW-5690
> Project: Struts 2
> Issue Type: Task
> Components: Core
> Reporter: Lukasz Lenart
> Assignee: Lukasz Lenart
> Priority: Major
> Fix For: 7.4.0
>
> Time Spent: 40m
> Remaining Estimate: 0h
>
> {{DefaultDispatcherErrorHandler.init()}} built a FreeMarker configuration and loaded {{/org/apache/struts2/dispatcher/error.ftl}} on *every* startup — including production, where the problem report is never rendered. {{handleError(...)}} only reaches it when devMode is on; otherwise it delegates to the container's error page via {{sendErrorResponse(...)}}.
> So every Struts application paid to initialise FreeMarker for a page most of them never show.
> h2. Change
> {{init(ServletContext)}} now only stores the servlet context. A new {{protected getTemplate()}} loads the template on first use and caches it in a {{volatile}} field.
> No lock: two threads racing on the very first error may both load it, which is harmless — FreeMarker caches templates in its own {{Configuration}} — and cheaper than locking a path taken once per application lifetime.
> h2. Behavioural change
> A missing or unparsable {{error.ftl}} used to throw {{StrutsException}} from {{init()}} and fail the application at boot. It now surfaces on the first dev-mode error, where the existing {{catch}} in {{handleErrorInDevMode(...)}} degrades to {{sendError(code, "Unable to show problem report: ...")}}. A dev-only template should not stop a production application starting.
> h2. Scope
> Startup cost only. The {{FreemarkerManager}} injection, the {{freemarker.template.Template}} import and {{error.ftl}} itself all remain — removing them is WW-5693.
> This ticket was originally filed as "Remove core's FreeMarker dependency from DefaultDispatcherErrorHandler" and has been narrowed to the change that actually shipped.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)