Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

guava 10.0.1 import javax.annotation.Nullable #776

Closed
gissuebot opened this issue Oct 31, 2014 · 42 comments
Closed

guava 10.0.1 import javax.annotation.Nullable #776

gissuebot opened this issue Oct 31, 2014 · 42 comments

Comments

@gissuebot
Copy link

gissuebot commented Oct 31, 2014

Original issue created by pondruska+o...@csas.cz on 2011-10-28 at 09:22 PM


What steps will reproduce the problem?

  1. Add guava-10.0.1.jar, guava-gwt-10.0.1.jar to build path
  2. Compile GWT module

What is the expected output? What do you see instead?

Compiling module ***
   Validating newly compiled units
      [ERROR] Errors in 'jar:file:/***/guava/guava-gwt-10.0.1.jar!/com/google/common/base/CharMatcher.java'
         [ERROR] Line 29: The import javax.annotation.CheckReturnValue cannot be resolved
         [ERROR] Line 871: CheckReturnValue cannot be resolved to a type
         [ERROR] Line 908: CheckReturnValue cannot be resolved to a type

Also complains not being able to find javax.annotation.Nullable

What version of the product are you using? On what operating system?
guava 10.0.1, gwt 2.4.0, java se 1.6

Please provide any additional information below.
There are "fixed" issues against guava r09 but clearly referring to javax.annotation.Nullable and CheckReturnValue in guava which does not provide them (and not docs mention where to get those).

@gissuebot
Copy link
Author

gissuebot commented Oct 31, 2014

Original comment posted by pondruska+o...@csas.cz on 2011-10-28 at 09:27 PM


deprecated guava-r09.zip:guava-r09/guava-r09-gwt.jar containst javax.annotation package. Please fix it in guava 10

@gissuebot
Copy link
Author

Original comment posted by wasserman.louis on 2011-11-07 at 07:29 PM


javax.annotation.Nullable is available from JSR 305, which is listed as a Guava dependency in the Maven POM:
     <groupId>com.google.code.findbugs</groupId>
      <artifactId>jsr305</artifactId>
      <version>1.3.9</version>

@gissuebot
Copy link
Author

gissuebot commented Oct 31, 2014

Original comment posted by pondruska+o...@csas.cz on 2011-11-08 at 05:22 AM


Thanks Louis, I do not use Maven (and do not know how to use it either). So if that is the only way to go(?) I have to do some homework and learn new stuff :-)

@gissuebot
Copy link
Author

gissuebot commented Oct 31, 2014

Original comment posted by pondruska+o...@csas.cz on 2011-11-08 at 10:06 AM


OK, just get jsr305-1.3.9.jar from http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22jsr305%22 and place onto build path and everything is fine. Thanks.

@gissuebot
Copy link
Author

Original comment posted by raymond.rishty on 2011-11-08 at 10:52 AM


So what happened to this note Kevin had posted on SO a few months back?

"You are absolutely positively 100% NOT supposed to need to go off hunting for a jsr305 jar yourself! guava-gwt.jar is supposed to just work for you out of the box..."

@gissuebot
Copy link
Author

Original comment posted by kevinb@google.com on 2011-11-09 at 03:16 PM


I agree with that.

@gissuebot
Copy link
Author

Original comment posted by andy.dennie on 2011-11-10 at 04:14 PM


I've added jsr305-1.3.9.jar to my classpath and it hasn't resolved the issue for me. I'm stumped as to why not. FWIW, my symptom is
[ERROR] [newsbotserver] - Errors in 'jar:file:/C:/Users/Andy/Dev/Eclipse%20Workspace/NewsBotServer/war/WEB-INF/lib/guava-gwt-10.0.1.jar!/com/google/common/base/Equivalence.java'
[ERROR] [newsbotserver] - Line 26: The import javax.annotation.Nullable cannot be resolved
[ERROR] [newsbotserver] - Line 65: Nullable cannot be resolved to a type

I am able to eliminate the problem by downgrading to v09 of guava and guava-gwt jars, and changing my code to account for the fact that in v09, Equivalence was an interface rather than a class. But I'd like to make this work with v10 if possible.

@gissuebot
Copy link
Author

Original comment posted by andy.dennie on 2011-11-10 at 04:29 PM


apparently I'm not the only one for whom adding jsr305 has not fixed the issue. See this SO question:

http://stackoverflow.com/questions/7817156/using-guava-10s-predicate-and-function-interfaces-with-gwt-2-4-0

@gissuebot
Copy link
Author

Original comment posted by kevinb@google.com on 2011-11-15 at 10:04 PM


(No comment entered for this change.)


Status: Accepted
Labels: Milestone-Release11

@gissuebot
Copy link
Author

Original comment posted by cpovirk@google.com on 2011-12-02 at 10:42 PM


Issue #765 has been merged into this issue.

@gissuebot
Copy link
Author

Original comment posted by cpovirk@google.com on 2011-12-02 at 11:26 PM


Can anyone upload a project demonstrating this problem? My attempts to reproduce it have failed.

@gissuebot
Copy link
Author

Original comment posted by yrfselrahc on 2011-12-05 at 06:35 PM


(No comment entered for this change.)


Labels: -Milestone-Release11

@gissuebot
Copy link
Author

Original comment posted by trupanka on 2012-01-09 at 09:58 PM


This code compiles:
List<String> location = ImmutableList.copyOf(new String[] {"s", "s"});
But in DevMode it doesn't work with Exception
00:31:37.320 [ERROR] [com.example.list] Line 32: The import javax.annotation.Nullable cannot be resolved

This code doen't compile without adding <super-source path="path/to/JSR-305/source"> or <source path="path/to/JSR-305/source">:
ImmutableList<String> location = ImmutableList.copyOf(new String[] {"s", "s"});

I think the issue is about how GWT Compiler resolves and ignores unrecognized annotation types.

@gissuebot
Copy link
Author

Original comment posted by bdleitner80 on 2012-01-22 at 08:00 AM


I'm also having this issue. I have guava-11.0.1/jar, guava-gwt-11.0.1.jar AND jsr305-1.3.9.jar in my classpath, but I get:

[ERROR] Errors in 'jar:file:/D:/Projects/Java/appengine/jnddb/war/WEB-INF/lib/guava-gwt-11.0.1.jar!/com/google/common/base/CharMatcher.java'
[ERROR] Line 864: CheckReturnValue cannot be resolved to a type

and later
[ERROR] Errors in 'jar:file:/D:/Projects/Java/appengine/jnddb/war/WEB-INF/lib/guava-gwt-11.0.1.jar!/com/google/common/base/Enums.java'
[ERROR] Line 26: The import javax.annotation.Nullable cannot be resolved
[ERROR] Line 75: Nullable cannot be resolved to a type

etc.

My module has:
  <inherits name="com.google.common.collect.Collect"/>
  <inherits name="com.google.common.base.Base"/>

in it.

@gissuebot
Copy link
Author

Original comment posted by wasserman.louis on 2012-01-22 at 08:07 AM


I'll repeat cpovirk's plea: "Can anyone upload a project demonstrating this problem? My attempts to reproduce it have failed."

@gissuebot
Copy link
Author

Original comment posted by victor.ott on 2012-01-24 at 11:22 AM


I'm also having this issue, and am pretty disappointed.

Attached you'll find the requested demo project:

  • freshly created Eclipse GWT project with default demo code, GWT 2.4.0, JDK 6;
  • converted project to use Facets ("Dynamic Web Module" and "Java");
  • reconfigured Google web app "project WAR directory" [sic!] to be "WebContent";
  • added guava-11.0.1.jar and guava-gwt-11.0.1.jar to WebContent/WEB-INF/lib;
  • added dependency to module definition
      "/GwtGuava/src/com/test/gwtguava/GwtGuava.gwt.xml":
        <inherits name="com.google.common.collect.Collect"/>
  • added lines 61-66 and corresponding imports to
      /GwtGuava/src/com/test/gwtguava/client/GwtGuava.java:
        // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        TreeMultimap<String, String> tmMap = TreeMultimap.create();
        tmMap.put("one", "something");
        tmMap.put("one", "something else");
        tmMap.put("two", "another");
        // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  • "GWT Compile Project..." gives:

Compiling module com.test.gwtguava.GwtGuava
   Validating newly compiled units
      Ignored 113 units with compilation errors in first pass.
Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
   [ERROR] Errors in 'jar:file:/D:/workspace/ZZZ/GwtGuava/WebContent/WEB-INF/lib/guava-gwt-11.0.1.jar!/com/google/common/collect/AbstractSortedSetMultimap.java'
      [ERROR] Line 25: The import javax.annotation.Nullable cannot be resolved
      [ERROR] Line 64: Nullable cannot be resolved to a type
      [ERROR] Line 76: Nullable cannot be resolved to a type
[...etc...]

@gissuebot
Copy link
Author

Original comment posted by victor.ott on 2012-01-24 at 12:33 PM


PS
Forgot to mention: manually adding jsr305-2.0.0.jar to WEB-INF/lib solved the GWT compiler errors, but as comments #5 and #6 already mentioned, that shouldn't be necessary, imho.

@gissuebot
Copy link
Author

Original comment posted by cpovirk@google.com on 2012-01-24 at 05:25 PM


victor.ott,

Thanks very much for the sample project.

andy.dennie, bdleitner80,

Does adding the jsr305 jar to your WEB-INF/lib solve the problem, or is this what you already did when you said that you added it to your CLASSPATH?

All,

Our goal is to keep our dependencies minimal, but we have allowed JSR 305 in, and we may pick up JSR 330 soon. We switched from Ant to Maven in order to minimize the hassle of adding dependencies. It sounds like Eclipse GWT support and Maven aren't closely integrated, which dumps dependency management back in the laps of users. Does anyone know whether there's a way for us to supply enough metadata with guava-gwt (ideally in the pom.xml) to tell Eclipse "Please also include these jars?" Is there some additional Eclipse plugin that users could install to make this possible?

@gissuebot
Copy link
Author

gissuebot commented Oct 31, 2014

Original comment posted by pondruska+o...@csas.cz on 2012-01-24 at 05:44 PM


I did not add jsr305 jar to WEB-INF/lib as it is only needed to be available on classpath (Eclipse's build path) during GWT compile. That works, actually I have modified my guava-gwt library to include jsr305jar in addition to guava-gwt-..jar and that fixes the problem.

@gissuebot
Copy link
Author

Original comment posted by raymond.rishty on 2012-01-24 at 05:46 PM


Chris,
I believe that there are Eclipse plugins to integrate with Maven, but it's not what everybody is using.

Personally, I don't think it's a problem to have to get and include JSR 305, if that's the solution. I've gone out and found the jar myself, included it in my projects, and everything worked great. I've also found it very useful to use those annotations myself and reap the benefits from FindBugs.

That said, I think it would be helpful to have a clear and consistent instruction from the Guava team. Since we've heard that we don't need that jar, we assume there's something wrong. But if all that's needed is to get the jar, just making that explicit would be helpful (as well as, perhaps, a link to the jar?)

As far as additional metadata... I think this is where we run into different people using different technologies. Some of us are using Ant, some Maven, some use OSGi... I doubt there is a one-size-fits-all solution.

Thanks

@gissuebot
Copy link
Author

Original comment posted by victor.ott on 2012-01-24 at 06:34 PM


More information: I've now spent good 1+ hour to find out why our Ant build script still doesn't GWT compile, although jsr305-2.0.0.jar is included. The difference is: "-strict".
Try adding the "-strict" parameter to the GWT compiler in the sample project (see attached screenshot), and the issue is back.

@gissuebot
Copy link
Author

Original comment posted by cpovirk@google.com on 2012-02-08 at 09:35 PM


Victor,

Thanks for bailing me out again. I can reproduce the problem with -strict.

My current understanding is that we need to provide a javax/annotation/Annotation.gwt.xml. This will inform GWT that it should look for source files under that path in the jar. We don't see this problem internally because our build system generates the .gwt.xml automatically.

Currently I'm here:

Compiling module com.test.gwtguava.GwtGuava
   Validating newly compiled units
      [ERROR] Errors in 'jar:file:/usr/local/google/home/cpovirk/workspace/GwtGuava/WebContent/WEB-INF/lib/jsr305.jar!/javax/annotation/MatchesPattern.java'
         [ERROR] Line 23: No source code is available for type java.util.regex.Pattern; did you forget to inherit a required module?
      [ERROR] Errors in 'jar:file:/usr/local/google/home/cpovirk/workspace/GwtGuava/WebContent/WEB-INF/lib/jsr305.jar!/javax/annotation/RegEx.java'
         [ERROR] Line 32: No source code is available for type java.util.regex.Pattern; did you forget to inherit a required module?
         [ERROR] Line 33: No source code is available for type java.util.regex.PatternSyntaxException; did you forget to inherit a required module?
   [ERROR] Aborting compile due to errors in some input files

I'm not yet sure why we aren't seeing that error internally.


Labels: -Priority-Medium, Priority-High

@gissuebot
Copy link
Author

Original comment posted by cpovirk@google.com on 2012-02-08 at 09:53 PM


Setting aside the question of why we don't get the error internally, I can at least eliminate it:

<module>
  <source path="" excludes="MatchesPattern.java,RegEx.java"/>
</module>

This is slightly more than we need to exclude, since it's only the nested Checker classes in those files that cause a problem, but it's probably good enough to get Guava working.

@gissuebot
Copy link
Author

Original comment posted by cpovirk@google.com on 2012-02-27 at 10:59 PM


I've spoken to someone from the GWT team, and he thinks that the problem is with the Google Plugin for Eclipse -- specifically, that it's not setting up the classpath for the compiler correctly, so the compiler can't find the annotation types. (In the end, it shouldn't need the sources at all.)

He's going to try to verify with someone more familiar with the plugin.

@gissuebot
Copy link
Author

Original comment posted by victor.ott on 2012-02-27 at 11:16 PM


In comment #22 I wrote that I was analyzing why our ANT script did not
GWT compile. Then I was able to reproduce the issue with the Eclipse
plugin. Therefore imho the issue in NOT specific only to the Eclipse
plugin.

@gissuebot
Copy link
Author

Original comment posted by cpovirk@google.com on 2012-02-27 at 11:21 PM


Victor,

Sorry, I forgot about that part. I'll make sure that I get instructions for the proper Ant compile to go along with whatever we recommend for the Eclipse compile. My guess is that the fix will be the same -- "include jsr305.jar in the compiler's classpath" -- but I'll report back.

@gissuebot
Copy link
Author

Original comment posted by cpovirk@google.com on 2012-02-27 at 11:22 PM


(The GWT guy got it running by setting up a manual gwtc configuration, rather than relying on the plugin's or Ant's.)

@gissuebot
Copy link
Author

Original comment posted by dusan.maliarik on 2012-03-07 at 11:54 AM


Adding jsr305.jar did not solve it for me. I'm running dev mode from IDEA. Before adding JSR305, the symptom was:

The import javax.annotation.Nullable cannot be resolved

After adding it, it changed to:

The type new Predicate<String>(){} must implement the inherited abstract method Predicate<String>.apply(Object)
The method apply(String) of type new Predicate<String>(){} must override or implement a supertype method.

@gissuebot
Copy link
Author

Original comment posted by dusan.maliarik on 2012-03-07 at 12:13 PM


And the workaround was to create javax/annotation/Annotation.gwt.xml (with source path="") and inherit it.

@gissuebot
Copy link
Author

Original comment posted by cpovirk@google.com on 2012-03-07 at 01:08 PM


And the workaround was to create javax/annotation/Annotation.gwt.xml (with
source path="") and inherit it.

Interesting. In my tests, that hasn't been good enough, at least with -strict. Are you using -strict?

(And thanks for the information.)

@gissuebot
Copy link
Author

Original comment posted by cpovirk@google.com on 2012-03-23 at 06:00 PM


RE: Eclipse: We're getting some attention from the GWT team now, so I'm hoping that they'll be able to fix up the Eclipse plugin to avoid this.

RE: Ant: I haven't been able to reproduce this problem with Ant, even with -strict, at least once I include jsr305.jar in my classpath. I've attached a project (based on Victor's Eclipse project) that works for me, which you can run with something like ant -Dgwt.home=/path/to/gwt/jar/directory. Can anyone share an Ant project with jsr305.jar in the classpath that fails? Thanks.

@gissuebot
Copy link
Author

gissuebot commented Oct 31, 2014

Original comment posted by HendrikU...@nexgo.de on 2012-05-17 at 12:19 PM


And the workaround was to create javax/annotation/Annotation.gwt.xml
(with source path="") and inherit it.

This worked for me in Eclipse

@gissuebot
Copy link
Author

Original comment posted by gentijo on 2012-05-27 at 05:28 AM


Help, I just Incorporated Guava 12.0 into my GWT project and I am getting the error where Nullable can not be resolved.

I added guava-12.0.jar, guava-gwt-12.0.jar, and jsr305-2.0.0.jar in my war/WEB-INF/lib and included the jars in the build properties / libs

I also created a javax.annotations package in my source tree and created Annotations.gwt.xml with source path="" and inherited it in my gwt project file.

I even upgraded to Jdk1.7 from Oracle in case this is a System Mac JDK issue.

All == No Luck..

Dev environment =
Mac (Lion)
Eclipse Helios SR2
The latest GWT Eclipse plugin..

@gissuebot
Copy link
Author

Original comment posted by gentijo on 2012-05-27 at 07:19 AM


I got it to compile by copying the source of jsr305 into my project and creating a gmt.xml file for it.. Although when it compiles now, I get an error on one of the custom serializers. I don't use that function so I don't think it's causing an issue, just wanted to point it out.. I expect my extreme fix may be part of the cause somehow..

Validating newly compiled units
  Errors in 'generated://1DCFAC23BE2D8C9BC205377978109764/com/google/common/collect/ForwardingImmutableList_FieldSerializer.java'
 See snapshot: /var/folders/pn/rtgx2jks7_j1cq5h8cl9ldsr0000gn/T/com.google.common.collect.ForwardingImmutableList_FieldSerializer4785162401512167816.java
Ignored 1 unit with compilation errors in first pass.

@gissuebot
Copy link
Author

Original comment posted by kevinb@google.com on 2012-05-30 at 07:49 PM


(No comment entered for this change.)


Labels: -Type-Defect, Type-Dev

@gissuebot
Copy link
Author

Original comment posted by kevinb@google.com on 2012-06-22 at 06:57 PM


(No comment entered for this change.)


Labels: Package-General

@gissuebot
Copy link
Author

Original comment posted by ljw1001 on 2012-09-18 at 11:57 AM


Also having this problem with Guava-gwt-13. Is this likely to see a resolution soon or should I punt on Guava in my GWT code?

@gissuebot
Copy link
Author

Original comment posted by cbonami on 2012-09-18 at 12:24 PM


I cannot make decisions in your place, but :

And the workaround was to create javax/annotation/Annotation.gwt.xml
(with source path="") and inherit it.

This worked for me in Eclipse, IntelliJ and in our ANT builds (GWT compiler).
We're using Guava 11.0.2.

We've not upgraded since, but I'm planning to.

@gissuebot
Copy link
Author

Original comment posted by cgruber@google.com on 2013-02-20 at 02:22 PM


So here's the question. Is the listed workaround sufficient to resolve this issue? Looking at this whole thread, is this even rightly a Guava issue? It seems like it's an upstream dependency issue which is resolvable by the listed workaround... which seems not like a workaround, but the actually correct solution to a dependency issue.

That is, if you're going to use Guava, in GWT, you need to have a javax/annotation/Annotation.gwt.xml that pulls in the correct source. Is there anything further Guava needs to do in terms of what we supply or how our builds are configured? Or is this a documentation issue at this point ("using Guava with GWT" etc.)?

@gissuebot
Copy link
Author

Original comment posted by cgruber@google.com on 2013-07-29 at 07:17 PM


(No comment entered for this change.)


Status: Obsolete

@gissuebot
Copy link
Author

Original comment posted by RogerMHand on 2014-07-17 at 07:51 PM


Not sure why this was marked obsolete ... I just spent over an hour getting Guava version 17 to work in GWT, and I had to do the Annotation.gwt.xml trick.

@dengyuning
Copy link

Can anyone upload a project demonstrating this problem? My attempts to reproduce it have failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants