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

error-prone bug in ComparableType check #12270

Closed
benjaminp opened this issue Oct 14, 2020 · 2 comments
Closed

error-prone bug in ComparableType check #12270

benjaminp opened this issue Oct 14, 2020 · 2 comments
Labels
team-Rules-Java Issues for Java rules untriaged

Comments

@benjaminp
Copy link
Collaborator

Here's some apparently buggy error-prone behavior:

$ touch WORKSPACE
$ cat X.java
package com.example;

class C implements Comparable<C> {
   @Override
    public int compareTo(C o) {
        return 0;
    }
}

public class X {}
$ cat BUILD
java_library(
    name = 'X',
    srcs = ['X.java'],
)
$ bazel build //:X
$ ~/bin/bazel --batch build :X 
INFO: Analyzed target //:X (18 packages loaded, 322 targets configured).
INFO: Found 1 target...
ERROR: BUILD:1:13: Building libX.jar (1 source file) failed (Exit 1)
X.java:3: error: [ComparableType] Comparable should not be raw
class C implements Comparable<C> {
^
    (see https://errorprone.info/bugpattern/ComparableType)
Target //:X failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 3.994s, Critical Path: 1.73s
INFO: 0 processes.
FAILED: Build did NOT complete successfully

I'm reporting this here rather than https://github.com/google/error-prone because I can't reproduce it with raw javac:

$ javac   -XDcompilePolicy=simple   -processorpath error_prone_core-2.4.0-with-dependencies.jar:dataflow-shaded-3.1.2.jar:jFormatString-3.0.0.jar:threeten-extra-1.5.0.jar   '-Xplugin:ErrorProne  -Xep:ComparableType:ERROR'   X.java
$
@aiuto aiuto added team-Rules-Java Issues for Java rules untriaged labels Oct 15, 2020
@davido
Copy link
Contributor

davido commented Oct 22, 2020

/Cc @cushon .

@cushon
Copy link
Contributor

cushon commented Oct 22, 2020

@comius

If you include -XDcompilePolicy=simple (or -XDcompilePolicy=byfile) it doesn't repro with Bazel either:

$ bazel build :X 
...
X.java:3: error: [ComparableType] Comparable should not be raw
class C implements Comparable<C> {
^
    (see https://errorprone.info/bugpattern/ComparableType)
$ bazel build --javacopt=-XDcompilePolicy=simple :X
...
Build completed successfully

Error Prone doesn't work with the default policy. The usual Error Prone entry point has a check for that, but the Bazel integration doesn't do an equivalent check: https://github.com/google/error-prone/blob/650cbfda0d9f53eebf04154c0ed3c4db27d5bca7/check_api/src/main/java/com/google/errorprone/BaseErrorProneJavaCompiler.java#L162

There's a javac bug that affects the byfile policy too, but the javac we redistribute has a fix for that: google/error-prone-javac@94c6b72

Bazel should be passing -XDcompilePolicy=simple in the default toolchain (or byfile depending on the support level of stock javac).

@ghost ghost mentioned this issue Oct 26, 2020
10 tasks
katre pushed a commit that referenced this issue Nov 18, 2020
it is required by Error Prone, see linked bug.

Fixes #12270

PiperOrigin-RevId: 338634333
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Rules-Java Issues for Java rules untriaged
Projects
None yet
Development

No branches or pull requests

4 participants