Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
None
Description
Each instance of FMParser creates a new instance of LookAheadSuccess.
In our case, where we tend to work with a lot of FreeMarker templates (in some cases generating freemarker template as an intermediate representation of a more abstract form), this has had a couple of impacts:
1. LookAheadSuccess extends java.lang.Error which adds noise to our Java Flight Recorder recordings, similar to the situation described in http://hirt.se/blog/?p=1288
2. Each instance fills in a stack trace, causing unnecessary object allocation, given that
These issues (non-static LookAheadSuccess instance, extending java.lang.Error, populating a stack trace) have been addressed in JavaCC 7 in the following PR
https://github.com/javacc/javacc/pull/99/files
If it seems reasonable, I would be willing to create a PR to update FreeMarker 2.3 to Java CC 7.x. The unit tests do seem to pass with Java CC 7.
If upgrading JavaCC is deemed undesirable, the approach used to make the class static in https://github.com/apache/freemarker/blob/2.3-gae/build.xml#L157 could probably also be used to make the instance final.