Todd Schiller
Todd Schiller

Reputation: 486

Using Guava 10's Predicate and Function interfaces with GWT 2.4.0

Are Predicates and Functions supported in GWT 2.4.0 and Guava GWT 10.0.1? Both interfaces are marked as @GwtCompatible.

When running the project in debug hosted mode, I receive run-time validation errors at the uses of Predicate:

[ERROR] [MyProject] - Line XXY: The import javax.annotation.Nullable cannot be resolved

[ERROR] [MyProject] - Line YYY: Nullable cannot be resolved to a type

From other StackOverflow posts, I believe these errors should not require including JSR 305 in the path as of Guava version 09 (including JSR 305 in the path didn't fix the problem, anyway).

I also appear to receive a couple interface mismatch errors:

[ERROR] [MyProject] - Line XXX: The type new Function(){} must implement the inherited abstract method Function.apply(Object)

[ERROR] [MyProject] - Line YYY: The method apply(MyType) of type new Function(){} must override or implement a supertype method

, and similar errors at uses of Predicate, which I submitted as a bug: http://code.google.com/p/guava-libraries/issues/detail?id=765

Any ideas as to what might be wrong with my setup?

My Project.gwt.xml file contains the following lines:

<inherits name="com.google.common.collect.Collect" />
<inherits name="com.google.common.base.Base" />

My java file includes the following imports:

import com.google.common.base.Function;
import com.google.common.base.Predicate;

I am using Eclipse 3.7.1 and JavaSE-1.6

Upvotes: 7

Views: 1857

Answers (2)

Gandalf
Gandalf

Reputation: 2348

I just had the same problem and found a solution to this. The problem is that the JSR 305 sourcecode is not part of a GWT module and therefore ignored by GWT. To fix it do the following:

  • Add a GWT module descriptor to jsr305-2.0.0.jar. Inside the jar which should contain at least the java sources in the subfolder javax/annotation add a file Annotation.gwt.xml with the following content:
<?xml version="1.0" encoding="UTF-8"?>
<module>
    <source path="" />
</module>
  • Add the modified jsr305-2.0.0.jar to your GWT project's classpath in eclipse. Though stated elsewhere it is not requiered to add this jar to WEB-INF/lib

  • Let your project's modules inherit from the newly created GWT module by adding the following line to you modules's .gwt.xml files:

<inherits name='javax.annotation.Annotation'/>

That's it! Now your eclipse project will compile successfully and development/hosted mode will work too.

Upvotes: 2

Boris Daich
Boris Daich

Reputation: 2461

This is a kind of known bug you need to have jsr305.jar in your WEB-INF/lib that is it.

Another thing to pay attention to is the fact that parts of guava is bundled in side GWT*.jar but there they are put in the separate package com.google.gwt.thirdparty.guava.common..... And as it often happens with eclipse is that when resolving imports it grabs the wrong import and this causes mess at runtime as classes that packaged in com.google.gwt.thirdparty.guava are from another version and MUST NOT be referenced.

My advice:

Do a text search on all your *.java files for "thirdparty" substring and replace it with correct imports - it worked for me.

A little bit deeper explanation is that in previous versions of Guava jsr305 was included in the guava jar but this release they took it out and dependency on it does appear in the Maven pom of the lib but was not well documented on the web site. This caused a lot of confusion among users.

Upvotes: 0

Related Questions