Skip to content

Many warning messages related to errorprone "CompatibleWith"Β #2721

Closed

Description

@enwired

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.

Activity

  1. cpovirk commented on Jan 20, 2017

    @cpovirk
    Member

    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)?

  2. enwired commented on Jan 20, 2017

    @enwired
    Author

    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>

  3. enwired commented on Jan 20, 2017

    @enwired
    Author

    Ok. So this is related to annotation processors of some basic sort. My standard build involves this:

    <build>
      <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
              <source>1.8</source>
              <target>1.8</target>
              <compilerArgs>
                <arg>-Xlint:all</arg>
                <arg>-Xlint:-serial</arg>
              </compilerArgs>
              <showWarnings>true</showWarnings>
              <showDeprecation>true</showDeprecation>
            </configuration>
          </plugin>
      </plugins>
    </build>

    The warnings are shown only when I include Xlint along with either of showWarnings or showDeprecation.

    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 ImmutableTable or 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.

  4. stevenschlansker commented on Jan 21, 2017

    @stevenschlansker

    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
    
  5. cpovirk commented on Jan 23, 2017

    @cpovirk
    Member

    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?

  6. stevenschlansker commented on Jan 23, 2017

    @stevenschlansker

    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

  7. PhilippWendler commented on Jan 25, 2017

    @PhilippWendler

    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.

  8. enwired commented on Jan 25, 2017

    @enwired
    Author

    @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.

  9. PhilippWendler commented on Jan 25, 2017

    @PhilippWendler

    I tested with javac 1.8.0_111 from OpenJDK.

  10. cpovirk commented on Jan 25, 2017

    @cpovirk
    Member

    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).

  11. cpovirk commented on Jan 25, 2017

    @cpovirk
    Member

    In the meantime, as a workaround, you can probably add an explicit dependency on:

        <groupId>com.google.errorprone</groupId>
        <artifactId>error_prone_annotations</artifactId>
        <version>2.0.15</version>
    
  12. Stephan202 commented on Jan 25, 2017

    @Stephan202
    Contributor

    ^ 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.

  13. PhilippWendler commented on Jan 25, 2017

    @PhilippWendler

    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).

  14. enwired commented on Jan 25, 2017

    @enwired
    Author

    @cpovirk To reproduce the problem in Maven you must use both Xlint 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:

    public class GuavaTest {
      private ImmutableTable.Builder table = ImmutableTable.builder();
    }
  15. cpovirk commented on Jan 25, 2017

    @cpovirk
    Member

    @PhilippWendler , thanks, I'm now seeing the error. I'll poke around some more.

  16. 16 remaining items

  17. cpovirk commented on Oct 30, 2017

    @cpovirk
    Member

    That links to https://bugs.openjdk.org/browse/JDK-6365854, which says:

    The rationale [for the warning] is that the missing annotation can cause problems when running the program.

    And also:

    The compiler cannot determine if the missing annotation has the meta-annotation @Inherited. This can cause problems for annotation processors.

  18. enwired commented on Oct 30, 2017

    @enwired
    Author

    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.

  19. garretwilson commented on Nov 4, 2017

    @garretwilson

    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.

  20. zalimeni commented on Nov 5, 2017

    @zalimeni

    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.

  21. cpovirk commented on Nov 6, 2017

    @cpovirk
    Member

    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.

  22. added a commit that references this issue on Apr 25, 2019
  23. cowwoc commented on May 23, 2024

    @cowwoc

    If anyone runs into this problem while using Java Modules, see #7233 (comment) for a solution.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions