Friday, October 7, 2016

GWT 2.7.0 and Java 1.8

Well hello there, here's a quick post before I forget of some aggravating "errors" I encountered while trying to compile my code. We currently use GWT 2.7.0 and just upped our code to finally (stop laughing) use Java 1.8. Sounds great right?

Now, to be fair, I'm sure GWT mentions these issues in their documentation... but I'm also sure most of you haven't read through every iota of documentation and probably missed these awesome warnings.

The current warning I get when I compile my GWT module is:

[INFO] Tracing compile failure path for type 'org.eaglei.ui.gwt.search.SearchApplication'
[INFO] [ERROR] Errors in 'jar:file:/Users/sophia/.m2/repository/org/eagle-i/eagle-i-search-gwt/4.5.0-SNAPSHOT/eagle-i-search-gwt-4.5.0-SNAPSHOT-sources.jar!/org/eaglei/ui/gwt/search/SearchApplication.java'
[INFO] [ERROR] org.eaglei.ui.gwt.uiconfig.rpc.SearchUIConfigServiceRemoteAsync cannot be resolved to a type
[INFO] [ERROR] Errors in 'jar:file:/Users/sophia/.m2/repository/org/eagle-i/eagle-i-search-gwt/4.5.0-SNAPSHOT/eagle-i-search-gwt-4.5.0-SNAPSHOT-sources.jar!/org/eaglei/ui/gwt/search/common/SearchTopPanel.java'
[INFO] [ERROR] org.eaglei.ui.gwt.search.common.SearchBarWidget cannot be resolved to a type
[INFO] [ERROR] Errors in 'jar:file:/Users/sophia/.m2/repository/org/eagle-i/eagle-i-search-gwt/4.5.0-SNAPSHOT/eagle-i-search-gwt-4.5.0-SNAPSHOT-sources.jar!/org/eaglei/ui/gwt/search/SearchApplicationController.java'
[INFO] [ERROR] org.eaglei.ui.gwt.search.SearchApplicationContext cannot be resolved to a type
[INFO] [ERROR] Errors in 'jar:file:/Users/sophia/.m2/repository/org/eagle-i/eagle-i-common-ui-gwt/4.5.0-SNAPSHOT/eagle-i-common-ui-gwt-4.5.0-SNAPSHOT-sources.jar!/org/eaglei/ui/gwt/uiconfig/rpc/SearchUIConfigServiceRemoteAsync.java'
[INFO] [ERROR] org.eaglei.services.uiconfig.SearchUIConfig cannot be resolved to a type
[INFO] [ERROR] Errors in 'jar:file:/Users/sophia/.m2/repository/org/eagle-i/eagle-i-search-gwt/4.5.0-SNAPSHOT/eagle-i-search-gwt-4.5.0-SNAPSHOT-sources.jar!/org/eaglei/ui/gwt/search/common/SearchBarWidget.java'
[INFO] [ERROR] org.eaglei.ui.gwt.search.SearchApplicationContext cannot be resolved to a type
[INFO] [ERROR] Errors in 'jar:file:/Users/sophia/.m2/repository/org/eagle-i/eagle-i-search-gwt/4.5.0-SNAPSHOT/eagle-i-search-gwt-4.5.0-SNAPSHOT-sources.jar!/org/eaglei/ui/gwt/search/SearchApplicationContext.java'
[INFO] [ERROR] org.eaglei.services.uiconfig.SearchUIConfig cannot be resolved to a type
[INFO] [ERROR] Errors in 'jar:file:/Users/sophia/.m2/repository/org/eagle-i/eagle-i-common-services/4.5.0-SNAPSHOT/eagle-i-common-services-4.5.0-SNAPSHOT-sources.jar!/org/eaglei/services/uiconfig/SearchUIConfig.java'
[INFO] [ERROR] org.eaglei.common.util.nodeinfo.NodeConfig cannot be resolved to a type
[INFO] [ERROR] Errors in 'jar:file:/Users/sophia/.m2/repository/org/eagle-i/eagle-i-common-util/4.5.0-SNAPSHOT/eagle-i-common-util-4.5.0-SNAPSHOT-sources.jar!/org/eaglei/common/util/nodeinfo/NodeConfig.java'
[INFO] [ERROR] Line 308: Type mismatch: cannot convert from List to List

So what the crap? I tried googling that last bit about List and only got results about people failing to use generics correctly. That's not my issue, I'm not using generics in this particular block of code.

It turns out it is because of a Java 1.8 enhancement I was using. Instead of:

List thingList = new ArrayList();

You can now omit the second type specifier:

List thingList = new ArrayList<>();

Fantastic!

Except if you use it in one of those fancy schmancy one line tertiary statements. In my code, the offending line of code was:

final List otherInstitutions = (other.getInstitutions() != null) ? other.getInstitutions() : new ArrayList<>();

By specifying the type in the tertiary statement, all was good:

final List otherInstitutions = (other.getInstitutions() != null) ? other.getInstitutions() : new ArrayList();

Yay?