Error-prone: [Feature Request] - Make all warnings errors

Created on 1 May 2017  路  9Comments  路  Source: google/error-prone

Example:

:24: Note: [ConstantField] Field name is CONSTANT_CASE, but field is not static and final
    private static String SUGGESTION_TYPE = "suggestion";
                          ^
    (see http://errorprone.info/bugpattern/ConstantField)
  Did you mean 'private static final String SUGGESTION_TYPE = "suggestion";' or 'private static String suggestionType = "suggestion";'?

Based on Bug Patterns, it is marked as "Experimental : SUGGESTION". Even using this with Javac's -Werror does not force it to be an error. Do I have to wait until this is not "experimental" anymore?

Explanation:

We have the "errors as warnings" flag here: https://github.com/google/error-prone/blob/90a792107506aeb67b2bc8a091bbc8b960eeafab/check_api/src/main/java/com/google/errorprone/ErrorProneOptions.java#L52. Can we add a "warnings as errors" flag?

This would be easier to do instead of doing "-Xep:ConstantField:ERROR" for each one.

Most helpful comment

The ability to fail on all warnings is actually pretty handy. Your build will fail for useless reasons and then you whitelist the errors that you don't want to fail then any unknown warnings that creep in fail your build until you decide what your policy is on them

All 9 comments

Unfortunately, we don't want to encourage everyone turning on all of the checks as ERRORs with a flag (many of the checks are somewhat speculative and not 100% errors).

You can promote individual checks to warnings or errors:

-Xep:ConstantField:WARN
-Xep:ConstantField:ERROR

@nglorioso Why not? I use the Gradle plugin and you can specify your own error prone version:

configurations.errorprone {
    // Prevent updates, careful when updating, you may need to update your Java version - See PR #3802
    resolutionStrategy.force "com.google.errorprone:error_prone_core:2.0.19"
}

This allows you to make sure that only the checks in that version have been fixed.

I mean more that the semantic content of the warning and suggestion level checks do not mean that the code it flags is broken and should be fixed.

http://errorprone.info/bugpattern/SizeGreaterThanOrEqualsZero (here, it's pretty clear that the programmer messed up, and it does not do what you want)
http://errorprone.info/bugpattern/ClassCanBeStatic (here, it's a minor issue that's probably worth pointing out for memory-leak purposes, but there's nothing wrong necessarily with the code)

The SUGGESTION-level checks have even less 'incorrectness' value: there is literally no performance or correctness issue with the code at runtime if you name your field in constant case, but you may find it valuable to think about and/or rename the field.

If your compiler broke your build on every minor detail, many of which are legitimate programming patterns in certain circumstances, then it's not very helpful as a tool, since you're going to disable the tool or just spray @SuppressWarnings everywhere.

If you want to turn Error Prone into that for your purposes, you can certainly enumerate all of the checks that are not on by default and add -Xep:Foo:ERROR flags to your compiler invocation. However, we don't recommend it.

As an alternative, you can use -XepAllDisabledChecksAsWarnings https://github.com/google/error-prone/blob/90a792107506aeb67b2bc8a091bbc8b960eeafab/check_api/src/main/java/com/google/errorprone/ErrorProneOptions.java#L53 to promote the disabled checks to warnings, and it _should_ work with -Werror.

That makes sense but I'd still love the option. @nglorioso I am already using -Werror. I get a "build successful" every time.

Are you using it in combination with -XepAllDisabledChecksAsWarnings (to promote all experimental checks to warning-level)?

Looks like you'll also need to use a newer version, see https://github.com/google/error-prone/issues/486 where we fixed this. I think we haven't made a production release since this change though.

Yes I am. I am using both -XepAllDisabledChecksAsWarnings and -Werror. So do I need to wait for 2.0.20? I am using 2.019 now. When is the next release?

Any updates?

The ability to fail on all warnings is actually pretty handy. Your build will fail for useless reasons and then you whitelist the errors that you don't want to fail then any unknown warnings that creep in fail your build until you decide what your policy is on them

Was this page helpful?
0 / 5 - 0 ratings

Related issues

edwardcarlfox picture edwardcarlfox  路  5Comments

sergeykad picture sergeykad  路  3Comments

ctabin picture ctabin  路  3Comments

cojoco picture cojoco  路  3Comments

JakeWharton picture JakeWharton  路  7Comments