Conversation
…IZ-13504) Jira: https://issues.apache.org/jira/browse/OFBIZ-13504 Backport of the trunk fix to release24.09. Thanks to Carsten Heinrigs for reporting this, and for naming both the template and the method in the report. This also follows on from OFBIZ-10478 by Jacques Le Roux and Pradhan Yash Sharma, reviewed by Michael Brohl. That was a broad and worthwhile cleanup; this one method simply happened to have all of its callers in templates, where static analysis could not see them. ### The problem `UtilDateTime.toDateString(Date, String)` is reached from templates through `Static["org.apache.ofbiz.base.util.UtilDateTime"]`. FreeMarker resolves those members reflectively and so sees public methods only, so narrowing the two argument overload to private left the templates unable to resolve it: Java method "static org.apache.ofbiz.base.util.UtilDateTime.toDateString(Date)" takes 1 argument, but 2 was given. The render does not throw. That message is written into the output stream, so an `.fo.ftl` still returns a structurally valid PDF with a FreeMarker stack trace printed where the dates belong, and the HTTP response still looks healthy. release24.09 carries the same modifier and the same seven call sites as trunk: `ProductionRun.fo.ftl` (four), `PRunsProductsAndOrder.fo.ftl:324`, `PRunsProductsStacks.fo.ftl:92` and `ContentTreeLookupList.ftl:85`. Restoring the two argument overload to public keeps the rendered format unchanged. Dropping the format string in the templates instead would fall back to the single argument overload and silently move the reports from dd/MM/yyyy to MM/dd/yyyy. ### Note on the build.gradle line The `test` task here lists the JUnit classes it runs explicitly, and `FreeMarkerWorkerTests` was not among them, so the existing test in that class was never executed. Without the added `include` the new regression test would sit in the tree without ever running. It is listed separately in this commit so that it is easy to drop if reviewers would rather keep the task list unchanged. ### Verification The test is written for JUnit 4 to match this branch, rather than the Jupiter version used on trunk. It renders the failing expression through `FreeMarkerWorker` and asserts `09/03/2026`, a date whose dd/MM/yyyy and MM/dd/yyyy forms differ, so it also fails if the format string is dropped rather than the method restored. Watched failing before the change and passing after, on this branch, against the FreeMarker 2.3.35 it now pins. `./gradlew test checkstyleMain javadoc` passes with 25 tests, 0 failures, 0 errors. The equivalent trunk change is in apache#1827, where it was additionally verified by rendering a production run PDF over HTTP before and after.
Contributor
Author
|
Update from the Jira thread, for anyone reviewing this cold. Carsten Heinrigs, who reported the issue, has confirmed he is happy with restoring the That flexibility is really the crux of the choice here. With the two-argument form private, a Jira thread: https://issues.apache.org/jira/browse/OFBIZ-13504 |
…IZ-13504) Thanks to Carsten Heinrigs for confirming the approach on the Jira issue, and for noting that the ability to pass an explicit date format is worth keeping. That is the part most at risk of being lost again, so this records it in the source. The method has no callers in Java code; its callers are FreeMarker templates using Static["org.apache.ofbiz.base.util.UtilDateTime"], which static analysis cannot see. That is exactly why the scope reduction in OFBIZ-10478 looked safe. Without a note in the code, the next such pass would reasonably reach the same conclusion and reintroduce the bug. The comment also records that the failure mode is quiet, and that the single argument overload is fixed to MM/dd/yyyy, so dropping the pattern is not a neutral simplification.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #1827 to
release24.09.Credits
Thanks to Carsten Heinrigs for reporting OFBIZ-13504 and for naming both the
template and the method in the report.
This follows on from OFBIZ-10478 by Jacques Le Roux and Pradhan Yash Sharma,
reviewed by Michael Brohl — a broad and worthwhile cleanup, in which this one method
happened to have all of its callers in templates, where static analysis could not see them.
The problem
UtilDateTime.toDateString(Date, String)is reached from templates throughStatic["org.apache.ofbiz.base.util.UtilDateTime"]. FreeMarker resolves those membersreflectively and so sees public methods only, so narrowing the two-argument overload to
private left the templates unable to resolve it:
The render does not throw — that message is written into the output stream. So the
report still returns HTTP 200 and a structurally valid PDF, with a FreeMarker stack trace
printed where the dates belong.
release24.09carries the same modifier and the same seven call sites as trunk:ProductionRun.fo.ftl(4),PRunsProductsAndOrder.fo.ftl:324,PRunsProductsStacks.fo.ftl:92andContentTreeLookupList.ftl:85.Restoring the overload to public keeps the rendered format unchanged. Dropping the format
string in the templates instead would fall back to the single-argument overload and
silently move the reports from
dd/MM/yyyytoMM/dd/yyyy.This was discussed on the Jira issue, and Carsten Heinrigs, who reported it, agreed that
restoring the method is the better route, adding that he values being able to specify the
date format string. With the two-argument form private, a template that needs a particular
format has no clean way to ask for one.
Two differences from the trunk PR, both deliberate
1. The test is JUnit 4, matching this branch, rather than the Jupiter version on trunk.
2. There is a one-line
build.gradlechange. Thetesttask here lists the JUnitclasses it runs explicitly, and
FreeMarkerWorkerTestswas not among them — so the testalready in that class was never executed. Without the added
include, the new regressiontest would sit in the tree and never run, which would be worse than not adding it. It is
called out separately here so it is easy to drop if you would rather leave the task list
untouched.
Verification
The test asserts
09/03/2026, a date whosedd/MM/yyyyandMM/dd/yyyyforms differ, soit also fails if the format string is dropped rather than the method restored. It was
watched failing before the change and passing after, on this branch, against the
FreeMarker 2.3.35 this branch now pins.
./gradlew test checkstyleMain codenarcMain codenarcTest javadoc— all pass, 25 tests,0 failures, 0 errors.
The trunk change in #1827 was additionally verified by creating a production run and
fetching
PrintProductionRunover HTTP before and after, which is what confirmed the"valid PDF containing a stack trace" behaviour described above. That runtime check was not
repeated here, since the code path and the fix are identical.