Strippable check system in GWT 2.8?

284 views
Skip to first unread message

Bruno Salmon

unread,
Feb 3, 2017, 6:47:00 AM2/3/17
to GWT Users
hi,

I heard that the GWT 2.8 check system is strippable (source: https://www.youtube.com/watch?v=P4VhPck5s_g&t=1337s).

By defaut the check level would be normal, which means that the generated js code will do all checks (such as collections bounds checks, API usage checks, java type checks, ...). But if we are confident that the application successfully passes all checks, it seems possible to reduce that check level from normal to optimized or minimal and get a smaller and faster compiled production code.

I haven't found any documentation about this feature, not sure it is actually documented.

Does anybody know how to tell the GWT compiler to change that check level?

Thomas Broyer

unread,
Feb 3, 2017, 7:47:57 AM2/3/17
to GWT Users
This is https://github.com/gwtproject/gwt/blob/2.8.0/user/super/com/google/gwt/emul/javaemul/internal/InternalPreconditions.java
The javadoc and first few lines of the class tells it all (note that System.getProperty is the emulated one here, so the properties are from your gwt.xml files, not the JVM System properties when calling the GWT compiler)

Bruno Salmon

unread,
Feb 3, 2017, 8:33:34 AM2/3/17
to GWT Users
Thank you Thomas, <set-property name="jre.checks.checkLevel" value="MINIMAL" /> in my gwt.xml file works :-)

Alex opn

unread,
Feb 3, 2017, 10:55:06 AM2/3/17
to GWT Users
What is the risk of disabling these checks?

Thomas Broyer

unread,
Feb 3, 2017, 11:44:17 AM2/3/17
to GWT Users


On Friday, February 3, 2017 at 4:55:06 PM UTC+1, Alex opn wrote:
What is the risk of disabling these checks?

If your code depends on ClassCastException, IndexOutOfBoundsException, etc. to be thrown, then it'll no longer work as intended. The checks make sure the contracts of the emulated Java API is respected; disabling the checks means the contracts are no longer guaranteed.

For example:

try {
  o = myList.get(2);
} catch (IndexOutOfBoundsException ioobe) {
  // handle error; e.g. show error to the user, or log it to the console or up to the server
}

This code would break with checks disabled. 'o' would simply be 'null' instead of the exception being thrown.

The "correct" way to program this is:

if (myList.size() > 2) {
  o = myList.get(2);
} else {
  // handle error
}

And similarly use "o instanceof MyObj" instead of "try { (MyObj) o; } catch (ClassClassException cce) { … }".

Alex opn

unread,
Feb 4, 2017, 10:04:08 AM2/4/17
to GWT Users
Thanks for the explanation Thomas. I think it should be safe to disable them then in my case. :-)
Reply all
Reply to author
Forward
0 new messages