question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

7.0.x dev : Breaking change discussion: Wish to change the default JAVA_TEMPLATE_TYPE = "modern";

See original GitHub issue

A 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:open
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
matozoidcommented, Feb 22, 2017

We from JavaParser have used the modern template for a while now and are not going back because of the error handling 😃

1reaction
phaxcommented, Jan 3, 2017

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

angular/CHANGELOG.md at main - GitHub
This tightens parameter types of TransferState usage, and is a minor breaking change which may reveal existing problematic calls. router. The type of...
Read more >
Generic Types - Learning the Java Language
To update the Box class to use generics, you create a generic type declaration by changing the code "public class Box" to "public...
Read more >
Effective Go - The Go Programming Language
Introduction. Go is a new language. Although it borrows ideas from existing languages, it has unusual properties that make effective Go programs different ......
Read more >
Developer Documentation
If the change is a large change, consider inviting discussion on the issue at dev@tinkerpop.apache.org first before proceeding to implement the change.
Read more >
C++ Core Guidelines - GitHub Pages
concept : rules – in generic programming – template arguments – semantics; constructor: invariant – establish invariant – throw – default – not ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found