7.0.x dev : Breaking change discussion: Wish to change the default JAVA_TEMPLATE_TYPE = "modern";
See original GitHub issueA few years ago, as part of the 6.1.0 release I added a new code generation target, which was a subtarget of the Java code generation, primarily for GWT compatibility, but also to improve exception handling. I added an option called “JAVA_TEMPLATE_TYPE”, leaving existing behaviour in tact under the banner of JAVA_TEMPLATE_TYPE = “classic” (which was the default).
In order to get the new code generation patterns, you would require to opt-in, which made it safe for a point release. I wish to make the “modern” pattern the new default.
Modern mode primarily performs 3 functions:
a) Internal interface based IO / GWT Compatibility b) Better Exception Handling c) Some additional boilerplate / helper methods
NOTE : No Unicode changes are present under this particular configuration option.
The classic (pre-modern) Java code generation emits many instances of code that throw java.lang.Error, which are typically unhandled.
JavaCharStream.template (already in 6.1.x / 7.0.x dev)
catch (${LEGACY_EXCEPTION_HANDLING?Throwable:Exception} t)
{
throw new ${LEGACY_EXCEPTION_HANDLING?Error:RuntimeException}(t.getMessage());
}
(where legacy exception handling is an internal property that is set when modern mode is specified)
It throws these Errors when encountering something it doesn’t expect in the char stream, and for other reasons too.
This means that anyone using JavaCC generated Java based parsers has to catch ‘java.lang.Throwable’, which is generally frowned upon. In fact, this one aspect of JavaCC is the most dangerous.
It was always my intent to campaign for modern to become the new default, after a long enough incubation period.
Options.java (already in 6.1.x / 7.0.x dev)
/**
* 2013/07/22 -- GWT Compliant Output -- no external dependencies on GWT,
* but generated code adds loose coupling to IO, for 6.1 release, this is
* opt-in, moving forward to 7.0, after thorough testing, this will likely
* become the default option with classic being deprecated
*/
public static final String JAVA_TEMPLATE_TYPE_MODERN = "modern";
The GWT compliant code is also extremely useful with no drawbacks as far as I am aware.
The change I am proposing is simply this
Options.java (prior to change)
temp.add(new OptionInfo(USEROPTION__JAVA_TEMPLATE_TYPE, OptionType.STRING, JAVA_TEMPLATE_TYPE_CLASSIC));
Options.java (after change)
temp.add(new OptionInfo(USEROPTION__JAVA_TEMPLATE_TYPE, OptionType.STRING, JAVA_TEMPLATE_TYPE_MODERN));
As 7.0.0 is somewhat of a fresh start, I would like to see this become the default going forward. Discussion welcome.
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
We from JavaParser have used the modern template for a while now and are not going back because of the error handling 😃
I like the modern template because it creates (in my case) much faster code. So I think it is a good thing to make it the default. I also suggest to make
STATIC = false
the default when touching stuff.