-
Notifications
You must be signed in to change notification settings - Fork 745
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
fail if there any problems are detected, but report all problems found #4546
Comments
I'm not on the Error Prone team proper, but as someone who claimed that this was probably fixed on the issues you cited, I should probably say something :) Do you have an example project that demonstrates this? One thing that we've seen is that the exact behavior depends a lot on the specific build system. I have seen errors reported for multiple files in our internal Bazel integration and in Maven (like for this set of problems, for which I receive two errors in the same build), so it's possible that the build system you're using isn't covered by the fixes so far, or it's possible that upgrading some component (build system, compiler, Error Prone) could help. |
Oh, sorry, 2.30.0 is at least not the problem, then :) |
Actually, sorry again, I do have a trivial Gradle project lying around, too. I can introduce files in multiple problems there and see multiple errors in one build, too. (That's with Error Prone 2.20.0 because somehow I get a circular-dependencies error if I upgrade to 2.30.0? Ah, maybe it's because I'm building JSpecify itself, which is a dependency of Error Prone? jspecify/jspecify#604) |
@cpovirk I've created an example app that demonstrates the problem with Error Prone v2.30.0. If you check out the error-prone branch of this repo, then (using JDK v21) run
The build fails, but only reports an error in
then run |
Thanks! It looks like you can get errors reported in multiple files if you tell Error Prone to produce errors: --- a/build.gradle
+++ b/build.gradle
@@ -33,6 +33,6 @@ tasks.named('compileJava') {
options.errorprone {
// NullAway configuration options: https://github.com/uber/NullAway/wiki/Configuration
option("NullAway:AnnotatedPackages", "com.example.demo")
+ errorproneArgs.add("-Xep:NullAway:ERROR")
}
- options.compilerArgs << "-Werror"
}
That's interesting that Would the approach of requesting errors from Error Prone work in your case? (I don't know that there's an easy way to upgrade all the default warnings to errors (a hypothetical |
Not really, because there are too many bug patterns that emit warnings by default for it to practical to upgrade them all to errors one-by-one
This hypothetical flag to promote warnings to errors is what I'm asking for. There is a flag to downgrade errors to warnings, so it's surprising that the opposite doesn't seem to be possible |
There was some related discussion to I wondered if setting javac's error-prone/check_api/src/main/java/com/google/errorprone/ErrorProneAnalyzer.java Line 194 in 90d9390
But here Error Prone reports a diagnostic, and that causes javac to report a werror diagnostic, and Error Prone stops: I checked that hacking around that causes more diagnostics to be produced: --- a/check_api/src/main/java/com/google/errorprone/ErrorProneAnalyzer.java
+++ b/check_api/src/main/java/com/google/errorprone/ErrorProneAnalyzer.java
@@ -191,7 +191,7 @@ public class ErrorProneAnalyzer implements TaskListener {
if (taskEvent.getKind() != Kind.ANALYZE) {
return;
}
- if (JavaCompiler.instance(context).errorCount() > errorProneErrors) {
+ if (JavaCompiler.instance(context).errorCount() > errorProneErrors + 1) {
return;
}
TreePath path = JavacTrees.instance(context).getPath(taskEvent.getTypeElement()); diff --git a/build.gradle b/build.gradle
index 75cddee..0f55925 100644
--- a/build.gradle
+++ b/build.gradle
@@ -13,13 +13,14 @@ java {
}
repositories {
+ mavenLocal()
mavenCentral()
}
dependencies {
implementation "org.jspecify:jspecify:1.0.0"
errorprone "com.uber.nullaway:nullaway:0.11.2"
- errorprone "com.google.errorprone:error_prone_core:2.30.0"
+ errorprone "com.google.errorprone:error_prone_core:1.0-HEAD-SNAPSHOT"
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
@@ -35,4 +36,7 @@ tasks.named('compileJava') {
option("NullAway:AnnotatedPackages", "com.example.demo")
}
options.compilerArgs << "-Werror"
+ options.compilerArgs << "--should-stop=generate"
+ options.compilerArgs << "-XDcompilePolicy=simple"
+ options.compilerArgs << "-XDverboseCompilePolicy"
}
|
@cushon Thanks for the investigation. To be clear about my requirements:
Specifically, I don't really care whether the problems are reported as errors or warnings as long as the build fails. Instead of upgrading warnings to errors, would it be easier from an implementation point-of-view to add a flag |
I would like Error Prone to fail if it encounters any problems, but report all problems found. However it seems only the following are possible
(A) When problems are reported as warnings
(B) When problems are reported as errors
is encountered is that it's impossible to report problems in any other file.
The behaviour I want is A2 and B1, but this does not seem to be supported. When the flag
-Werror
is present, Error Prone behaves in mode (B), otherwise it behaves as per (A).I want all errors/warnings to fail the build in order to force people to fix them. However, if there are a large number of problems in the project (e.g. because Error Prone has just been introduced), it's tedious to discover them on a file-by-file basis.
I'm using Error Prone v2.30.0 with Gradle.
Relevant Issues
Example Application
I've create a sample application that reproduces the problem. Instructions are provided in this comment
The text was updated successfully, but these errors were encountered: