[ 
https://issues.apache.org/jira/browse/WW-5690?focusedWorklogId=1037401&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1037401
 ]

ASF GitHub Bot logged work on WW-5690:
--------------------------------------

                Author: ASF GitHub Bot
            Created on: 24/Aug/26 09:56
            Start Date: 24/Aug/26 09:56
    Worklog Time Spent: 10m 
      Work Description: lukaszlenart opened a new pull request, #1864:
URL: https://github.com/apache/struts/pull/1864

   Fixes [WW-5690](https://issues.apache.org/jira/browse/WW-5690)
   
   `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.
   
   So every Struts application today pays to initialise FreeMarker for a page 
most of them never show.
   
   ## Change
   
   `init()` now just stores the `ServletContext`. 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.
   
   ## One 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 (Exception exp)` in 
`handleErrorInDevMode()` already degrades to `sendError(code, "Unable to show 
problem report: ...")`.
   
   I'd argue that's an improvement — a dev-only template shouldn't stop a 
production application starting — but it is a change in failure timing and 
worth a reviewer's eye.
   
   ## Scope
   
   Startup cost only. The `FreemarkerManager` injection, the 
`freemarker.template.Template` import and `error.ftl` itself all stay. Removing 
core's FreeMarker dependency outright is the remaining half of WW-5690, and 
part of the lean-core work tracked in 
[WW-5689](https://issues.apache.org/jira/browse/WW-5689) alongside 
[WW-5691](https://issues.apache.org/jira/browse/WW-5691) and 
[WW-5692](https://issues.apache.org/jira/browse/WW-5692).
   
   ## Tests
   
   Two added to `DefaultDispatcherErrorHandlerTest`, using a 
`FreemarkerManager` subclass that records whether `getConfiguration` was called 
(no mocking framework needed — it delegates to `super`, so the template really 
renders):
   
   - `testInitDoesNotLoadErrorTemplate` — asserts `init()` leaves FreeMarker 
untouched. **Verified failing before the change**, on the assertion, which is 
what makes it a real regression guard.
   - `testErrorTemplateLoadedOnFirstDevModeError` — asserts the deferred load 
actually happens, so the report can't silently stop rendering.
   
   The four existing tests are unchanged and still pass. Full `core` suite: 
3197 tests, 0 failures, 0 errors.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)




Issue Time Tracking
-------------------

            Worklog Id:     (was: 1037401)
    Remaining Estimate: 0h
            Time Spent: 10m

> Remove core's FreeMarker dependency from DefaultDispatcherErrorHandler
> ----------------------------------------------------------------------
>
>                 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: 10m
>  Remaining Estimate: 0h
>
> Part of the WW-5689 lean-core work, but self-contained and shippable in 7.x.
> *Scope note.* This is about _core's own_ dependency on FreeMarker. 
> Applications using the Struts tag library still require FreeMarker 
> regardless: {{struts.ui.templateSuffix}} defaults to {{ftl}} and all 129 
> bundled theme templates are {{.ftl}}. What these tickets buy is that a 
> REST/JSON-only application — one that never renders a tag — stops paying for 
> FreeMarker.
> h2. Current behaviour
> {{DefaultDispatcherErrorHandler}} renders the dev-mode error report through 
> FreeMarker:
> * it holds an injected {{FreemarkerManager}}
> * {{init(ServletContext)}} calls {{freemarkerManager.getConfiguration(ctx)}} 
> and loads {{/org/apache/struts2/dispatcher/error.ftl}}
> * only {{handleErrorInDevMode(...)}} ever uses the resulting template
> {{init()}} is *unconditional*. It runs at dispatcher startup and initialises 
> the whole FreeMarker configuration even in production mode, where the 
> template is never rendered — {{handleError(...)}} goes to 
> {{sendErrorResponse(...)}} and delegates to the container's error page.
> h2. Proposal
> Render the dev-mode error report without FreeMarker — a plain Java renderer 
> is sufficient for what {{error.ftl}} produces.
> Failing that, the minimum acceptable change is to make the template load lazy 
> and gate it on devMode, so a production deployment never touches FreeMarker 
> through this path.
> {{DispatcherErrorHandler}} is already a pluggable bean, so a FreeMarker-based 
> handler can remain available for anyone who has customised {{error.ftl}}.
> h2. Compatibility
> {{error.ftl}} is an internal template, not a documented extension point. If 
> the plain renderer lands, note the change in the migration guide for anyone 
> who has overridden it.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to