You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Many warning messages related to errorprone "CompatibleWith"Β #2721
When compiling code that depends on Guava 21.0, [Edit: I mistakenly said 20.0 originally] using Maven, I get many warning messages like this:
Cannot find annotation method 'value()' in type 'com.google.errorprone.annotations.CompatibleWith': class file for com.google.errorprone.annotations.CompatibleWith not found
I do not use the errorprone library in my code, so this error message is due to its use by Guava.
Obviously, these are only warning messages and are not critical.
The reason is that we don't make the Error Prone annotations available to our users at compile time. We could maybe change that, but our understanding has been that it shouldn't be necessary. Do you know if you're using any Maven plugins that might be plugging into the compiler (annotation processors, mainly)?
We ran into this attempting to upgrade the jdbi3 project to Guava 21: jdbi/jdbi#697
We also don't do anything super fancy with Maven plugins, but we do attempt to set "warnings as errors" everywhere. That said, despite being logged at ERROR level, it doesn't fail the build.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:
testCompile (default-testCompile) on project jdbi3-sqlobject: Compilation failure
[ERROR] /home/travis/.m2/repository/com/google/guava/guava/21.0/guava-21.0.jar(com/google/common/collect/Multimap.class):
warning: Cannot find annotation method 'value()' in type 'CompatibleWith':
class file for com.google.errorprone.annotations.CompatibleWith not found
Thanks. I tried pulling the jdbi3 and running mvn clean install. It successes without the CompatibleWith message. Is there a different command I should use or a different commit I should check out?
No, sorry, an earlier version of this comment incorrectly stated the build failed.
The actual problem is that the javac output all gets logged at the maximum error level -- so the WARNING that this emits will be represented as an ERROR if there are other build errors, which is confusing. Once you fix the other unrelated build errors this message then gets downgraded to a WARNING. So it does not actually break out build, but it does introduce warnings -- which as soon as "warnings as errors" gets fixed (someday π€) it will then actually fail the build
I am also seeing this, on a standard javac -Xlint -Werror build with ant.
The messages are
[javac] .../guava.jar(com/google/common/collect/Multiset.class): warning: Cannot find annotation method 'value()' in type 'CompatibleWith': class file for com.google.errorprone.annotations.CompatibleWith not found
[javac] .../guava.jar(com/google/common/collect/Multiset.class): warning: Cannot find annotation method 'value()' in type 'CompatibleWith'
[javac] error: warnings found and -Werror specified
Because we want to use -Werror, this breaks our build and prevents us from upgrading Guava.
@PhilippWendler thanks for trying javac. Which JDK version is it?
I have found that I can eliminate the warning message in a Maven build by using this flag for the maven-compiler-plugin: <forceJavacCompilerUse>true</forceJavacCompilerUse>. That should make Maven use the javac command in my jdk, which is 1.8.0_66. I don't exactly understand why that removes the warning.
Running mvn clean install on jdbi3 didn't give me any output that mentions "CompatibleWith" anywhere. I tried with -Dmaven.compiler.forceJavacCompilerUse=true, and I tried introducing a compile error into a file that uses Multimap, and I still don't see it.
If anyone can point me to a repository and a command that I can use to reproduce this, that would be a big help. There's definitely something wrong, but I need to figure out where to point the finger (which might be at us -- I'm not just not sure yet).
^ And if you declare that dependency <scope>provided</scope>, then it shouldn't end up in your final aggregate build artifact (WAR, Uber JAR, etc.), meaning there should be no downside to doing so.
You should be able to reproduce the problem in branch guava21 of sosy-lab/java-common-lib. You can start a build with javac with ant clean build-project. The definition of the ant target that calls javac is in build/build-compile.xml, you can see the compiler options there.
The problem is reproducible with this branch on AppVeyor (log) and Travis (log).
Btw, we are even using error-prone already (though I disabled it in that branch for easier debugging) and want to upgrade to 2.0.15 at some point anyway, but I think that it would still be good if Guava would not have this problem.
The Eclipse Java Compiler builds our project just fine (ant clean build-project-ecj).
@cpovirk To reproduce the problem in Maven you must use bothXlint and showWarnings or showDeprecation. @PhilippWendler did something similar with javac -Xlint -Werror. So it may be that the problem is related to lint.
You can then reproduce it with a project containing one single java class like this:
As the original submitter of this bug, I'll add my two cents.
I think that there is something fishy about the fact that javac reports compiler warnings about code that is not part of the code being compiled. I no longer think this is a bug of guava. The change made in the guava pom file seems like a work-around for a deficiency in javac or in java language specification related to annotations.
The details are above my level of understanding.
I wish there were some way to avoid forcing me to include a dependency on errorprone. This particular library doesn't bother me because it is small and useful. But the general principal that could lead to other libraries becoming forced inclusions in the future does bother me.
Perhaps javac could implement an additional 'SuppressWarnings' directive for this case. But I'm not going to file a request for that myself.
After pondering this discussion, for my own library (see https://globalmentor.atlassian.net/browse/JAVA-47) I've decided to go with <optional> after all. Even assuming that javac is doing the correct thing here (and I'm not convinced it is), @enwired (in the hypothetical case that he used our library) simply has a use case/configuration for which he actually needs one or more of dependencies to be present, so he can explicitly include it. In my view that is in fact precisely the semantics of <optional>: not everybody needs it, but those who need it, like @enwired , can include it explicitly.
Thanks again for all the info and help with the research.
FWIW, an alternative solution I found (at least on Oracle JDK 1.8.0_151) for nixing these warnings is available through javac flags (for Maven, these can be set in the maven-compiler-plugin config):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<!-- Suppress warnings for RUNTIME annotations used in dependencies but missing from classpath -->
<arg>-Xlint:-processing</arg>
</compilerArgs>
</configuration>
</plugin>
It seems like the optional dependency is a much more surgical solution (the above will silence all javac annotation processor warnings), but this option avoids pulling in an unused jar for compilation. I'm going the optional dep route in my library as well, but thought this might be of interest to others.
Thanks. To be clear, -Xlint:processing may work around problems with annotation processors, but it doesn't work around problems with plain javac with the warnings turned up:
$ javac -Xlint:all,-processing -Werror -cp $HOME/.m2/repository/com/google/guava/guava/23.0/guava-23.0.jar GuavaTest.java
/usr/local/google/home/cpovirk/.m2/repository/com/google/guava/guava/23.0/guava-23.0.jar(com/google/common/collect/Table.class): warning: Cannot find annotation method 'value()' in type 'CompatibleWith': class file for com.google.errorprone.annotations.CompatibleWith not found
/usr/local/google/home/cpovirk/.m2/repository/com/google/guava/guava/23.0/guava-23.0.jar(com/google/common/collect/Table.class): warning: Cannot find annotation method 'value()' in type 'CompatibleWith'
/usr/local/google/home/cpovirk/.m2/repository/com/google/guava/guava/23.0/guava-23.0.jar(com/google/common/collect/Table.class): warning: Cannot find annotation method 'value()' in type 'CompatibleWith'
/usr/local/google/home/cpovirk/.m2/repository/com/google/guava/guava/23.0/guava-23.0.jar(com/google/common/collect/Table.class): warning: Cannot find annotation method 'value()' in type 'CompatibleWith'
/usr/local/google/home/cpovirk/.m2/repository/com/google/guava/guava/23.0/guava-23.0.jar(com/google/common/collect/Table.class): warning: Cannot find annotation method 'value()' in type 'CompatibleWith'
/usr/local/google/home/cpovirk/.m2/repository/com/google/guava/guava/23.0/guava-23.0.jar(com/google/common/collect/Table.class): warning: Cannot find annotation method 'value()' in type 'CompatibleWith'
/usr/local/google/home/cpovirk/.m2/repository/com/google/guava/guava/23.0/guava-23.0.jar(com/google/common/collect/Table.class): warning: Cannot find annotation method 'value()' in type 'CompatibleWith'
/usr/local/google/home/cpovirk/.m2/repository/com/google/guava/guava/23.0/guava-23.0.jar(com/google/common/collect/Table.class): warning: Cannot find annotation method 'value()' in type 'CompatibleWith'
/usr/local/google/home/cpovirk/.m2/repository/com/google/guava/guava/23.0/guava-23.0.jar(com/google/common/collect/Table.class): warning: Cannot find annotation method 'value()' in type 'CompatibleWith'
error: warnings found and -Werror specified
1 error
9 warnings
It might still be a perfectly good solution for some people, since most people don't use -Xlint -Werror.
Activity
cpovirk commentedon Jan 20, 2017
The reason is that we don't make the Error Prone annotations available to our users at compile time. We could maybe change that, but our understanding has been that it shouldn't be necessary. Do you know if you're using any Maven plugins that might be plugging into the compiler (annotation processors, mainly)?
enwired commentedon Jan 20, 2017
These warnings are happening even in some pretty simple packages where there are no exotic maven plugins.
It does not happen on all of my modules that use Guava. But I haven't narrowed-down which Guava class is involved.
The warnings happen during the "default-compile" step from maven-compiler-plugin. I've tried version 3.3 and 3.6 of that plugin.
The warnings appear even if I set
<showWarnings>false</showWarnings>enwired commentedon Jan 20, 2017
Ok. So this is related to annotation processors of some basic sort. My standard build involves this:
The warnings are shown only when I include
Xlintalong with either ofshowWarningsorshowDeprecation.Then 9 identical warnings appear if my java code contains one single line like this:
ImmutableTable.Builder<?,?,?> builder = ImmutableTable.builder();So, I don't know if there is a bug in maven compiler plugin, or in Guava's
ImmutableTableor what. But I really shouldn't be seeing these warnings.Again, not a bug in the program operation, just an annoying set of warning messages.
stevenschlansker commentedon Jan 21, 2017
We ran into this attempting to upgrade the
jdbi3project to Guava 21:jdbi/jdbi#697
We also don't do anything super fancy with Maven plugins, but we do attempt to set "warnings as errors" everywhere. That said, despite being logged at
ERRORlevel, it doesn't fail the build.cpovirk commentedon Jan 23, 2017
Thanks. I tried pulling the
jdbi3and runningmvn clean install. It successes without theCompatibleWithmessage. Is there a different command I should use or a different commit I should check out?stevenschlansker commentedon Jan 23, 2017
No, sorry, an earlier version of this comment incorrectly stated the build failed.
The actual problem is that the javac output all gets logged at the maximum error level -- so the
WARNINGthat this emits will be represented as anERRORif there are other build errors, which is confusing. Once you fix the other unrelated build errors this message then gets downgraded to aWARNING. So it does not actually break out build, but it does introduce warnings -- which as soon as "warnings as errors" gets fixed (someday π€) it will then actually fail the buildPhilippWendler commentedon Jan 25, 2017
I am also seeing this, on a standard
javac -Xlint -Werrorbuild withant.The messages are
Because we want to use
-Werror, this breaks our build and prevents us from upgrading Guava.enwired commentedon Jan 25, 2017
@PhilippWendler thanks for trying javac. Which JDK version is it?
I have found that I can eliminate the warning message in a Maven build by using this flag for the
maven-compiler-plugin:<forceJavacCompilerUse>true</forceJavacCompilerUse>. That should make Maven use thejavaccommand in my jdk, which is 1.8.0_66. I don't exactly understand why that removes the warning.PhilippWendler commentedon Jan 25, 2017
I tested with javac 1.8.0_111 from OpenJDK.
cpovirk commentedon Jan 25, 2017
Running
mvn clean installonjdbi3didn't give me any output that mentions "CompatibleWith" anywhere. I tried with-Dmaven.compiler.forceJavacCompilerUse=true, and I tried introducing a compile error into a file that usesMultimap, and I still don't see it.If anyone can point me to a repository and a command that I can use to reproduce this, that would be a big help. There's definitely something wrong, but I need to figure out where to point the finger (which might be at us -- I'm not just not sure yet).
cpovirk commentedon Jan 25, 2017
In the meantime, as a workaround, you can probably add an explicit dependency on:
Stephan202 commentedon Jan 25, 2017
^ And if you declare that dependency
<scope>provided</scope>, then it shouldn't end up in your final aggregate build artifact (WAR, Uber JAR, etc.), meaning there should be no downside to doing so.PhilippWendler commentedon Jan 25, 2017
You should be able to reproduce the problem in branch
guava21of sosy-lab/java-common-lib. You can start a build withjavacwithant clean build-project. The definition of the ant target that callsjavacis inbuild/build-compile.xml, you can see the compiler options there.The problem is reproducible with this branch on AppVeyor (log) and Travis (log).
Btw, we are even using error-prone already (though I disabled it in that branch for easier debugging) and want to upgrade to 2.0.15 at some point anyway, but I think that it would still be good if Guava would not have this problem.
The Eclipse Java Compiler builds our project just fine (
ant clean build-project-ecj).enwired commentedon Jan 25, 2017
@cpovirk To reproduce the problem in Maven you must use both
XlintandshowWarningsorshowDeprecation. @PhilippWendler did something similar withjavac -Xlint -Werror. So it may be that the problem is related tolint.You can then reproduce it with a project containing one single java class like this:
cpovirk commentedon Jan 25, 2017
@PhilippWendler , thanks, I'm now seeing the error. I'll poke around some more.
16 remaining items
cpovirk commentedon Oct 30, 2017
That links to https://bugs.openjdk.org/browse/JDK-6365854, which says:
And also:
enwired commentedon Oct 30, 2017
As the original submitter of this bug, I'll add my two cents.
I think that there is something fishy about the fact that javac reports compiler warnings about code that is not part of the code being compiled. I no longer think this is a bug of guava. The change made in the guava pom file seems like a work-around for a deficiency in javac or in java language specification related to annotations.
The details are above my level of understanding.
I wish there were some way to avoid forcing me to include a dependency on errorprone. This particular library doesn't bother me because it is small and useful. But the general principal that could lead to other libraries becoming forced inclusions in the future does bother me.
Perhaps javac could implement an additional 'SuppressWarnings' directive for this case. But I'm not going to file a request for that myself.
garretwilson commentedon Nov 4, 2017
After pondering this discussion, for my own library (see https://globalmentor.atlassian.net/browse/JAVA-47) I've decided to go with
<optional>after all. Even assuming thatjavacis doing the correct thing here (and I'm not convinced it is), @enwired (in the hypothetical case that he used our library) simply has a use case/configuration for which he actually needs one or more of dependencies to be present, so he can explicitly include it. In my view that is in fact precisely the semantics of<optional>: not everybody needs it, but those who need it, like @enwired , can include it explicitly.Thanks again for all the info and help with the research.
zalimeni commentedon Nov 5, 2017
FWIW, an alternative solution I found (at least on Oracle JDK 1.8.0_151) for nixing these warnings is available through javac flags (for Maven, these can be set in the
maven-compiler-pluginconfig):It seems like the optional dependency is a much more surgical solution (the above will silence all javac annotation processor warnings), but this option avoids pulling in an unused jar for compilation. I'm going the optional dep route in my library as well, but thought this might be of interest to others.
cpovirk commentedon Nov 6, 2017
Thanks. To be clear,
-Xlint:processingmay work around problems with annotation processors, but it doesn't work around problems with plainjavacwith the warnings turned up:It might still be a perfectly good solution for some people, since most people don't use
-Xlint -Werror.Remove <optional>true</optional> from annotation dependency.
Remove <optional>true</optional> from annotation dependency.
Move all dependency versions into the parent POM's dependencyManagemeβ¦
Update Truth to 0.42
Update Truth, ErrorProne, and NullAway (#266)
Update Truth to 0.44.
Use AutoService as a proper annotation processor.
Use AutoService as a proper annotation processor.
Update Truth, ErrorProne, and NullAway (#266)
cowwoc commentedon May 23, 2024
If anyone runs into this problem while using Java Modules, see #7233 (comment) for a solution.