Introduction
In this article, I want to share with you a powerful Java Compiler plugin:
Error Prone. Error Prone is an annotation processor
that can be plugged into the Java compiler to augment the compiler’s
type analysis. After reading this article, you will understand:
- Why should we use Error Prone?
- How to use it in Maven?
- Some bug patterns in real
- How to suppress warnings?
- Some limits of Error Prone
- How to go further in this topic?
Now, let’s get started!
Motivation
Why should I use Error Prone?
Error Prone makes the Java compiler more powerful by analyzing the code during
compile time. It has several advantages:
- Shift-left. It makes errors discovered early in the software development
lifecycle. Instead of being identified at build time, during code review, or
in production, now they are identified at compile time. They are caught before
they cost your time. - Neutral to build system. Google Error Prone is a Java annotation processor
that is plugged in the compiler. So it can be used in any build system, e.g.
Bazel, Maven, Gradle, Ant. - Suggestions for fixes. The fix of the problem is usually suggested at the
same time when the bug is identified.
If you know others, please let
me know by leaving a comment
Maven
How to use Error Prone in Maven?
To use Error Prone in Maven, you need to register the Google Error Prone Core
artifact in the list of annotation processor paths of the Maven Compiler
Plugin. It should look something like this in your POM file (pom.xml
):
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>8</source>
<target>8</target>
<compilerArgs>
<arg>-XDcompilePolicy=simple</arg>
<arg>-Xplugin:ErrorProne</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>2.4.0</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
If you are running on JDK 8, you need to use error-prone-javac
instead of the
standard javac
. More detail can be reached in the official installation guide
here: https://errorprone.info/docs/installation. In that page, you can also
find the solutions for other build systems, such as Bazel, Gradle, Ant.
Bug Patterns
How does the error look like when a bug is discovered?
In this section, let’s take a look at some demos extracted from my pull-request
https://github.com/mincong-h/java-examples/pull/155 to see how the source code
looks like and how the error message and suggestion looks like.
ReturnValueIgnored
Code:
LocalDateTime d = LocalDateTime.parse("2009-06-15T13:45:30");
d.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME); // ERROR
assertEquals("2009-06-15T13:45:30", d.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
Error:
lang: en
Error: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile (default-testCompile) on project java-examples-date: Compilation failure
Error: /home/runner/work/java-examples/java-examples/date/src/test/java/io/mincongh/date/so42364818/DateTest.java:[23,13] [ReturnValueIgnored] Return value of this method must be used
Error: (see https://errorprone.info/bugpattern/ReturnValueIgnored)
Error: Did you mean to remove this line?
From the error message provided by Error Prone, you can see the explanation of
the failure and a link for the official website for more detail. Now, focusing
on this error, it is triggered because the return value of the method
LocalDateTime.format(String)
is not used. Local date-time in Java Time is an
immutable class, so it means that I wrote one line of dead code and simply need
to remove it:
LocalDateTime d = LocalDateTime.parse("2009-06-15T13:45:30");
- d.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
assertEquals("2009-06-15T13:45:30", d.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
EqualsHashCode
Code:
public class PhoneNumberNoHash {
...
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof PhoneNumberNoHash)) return false;
PhoneNumberNoHash pn = (PhoneNumberNoHash) o;
return pn.lineNumber == lineNumber && pn.prefix == prefix && pn.areaCode == areaCode;
}
// Broken - no hashCode method!
}
Error:
Error: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project java-examples-hashcode: Compilation failure: Compilation failure:
Error: /home/runner/work/java-examples/java-examples/hashcode/src/main/java/io/mincongh/hashcode/bad/PhoneNumberNoHash.java:[26,18] [EqualsHashCode] Classes that override equals should also override hashCode.
Error: (see https://errorprone.info/bugpattern/EqualsHashCode)
Error: /home/runner/work/java-examples/java-examples/hashcode/src/main/java/io/mincongh/hashcode/bad/AthleteOnlyOverrideEquals.java:[24,18] [EqualsHashCode] Classes that override equals should also override hashCode.
Error: (see https://errorprone.info/bugpattern/EqualsHashCode)
As you can see, this is triggered because the class only overrides the equals
and does not override the hashCode
. By doing so, it causes broken behavior
when trying to store the object in a collection.
More Bug Patterns
Now we understand how the bug patterns look like, I’m not going to go further in
this section. If you want to know the complete list of patterns, you can visit
the “Bug patterns” page of the official website:
https://errorprone.info/bugpatterns to find the complete list.
Suppress Warnings
Sometimes, you may want to suppress warnings because you find those bugs
identified by Error Prone unsuitable in your situation. Here are some ways to
suppress warnings.
Use @SuppressWarnings
. You can suppress false positives by adding the
suppression annotation @SuppressWarnings("MyBugPattern")
to the enclosing
element. In other words, you can add this annotation to the variable
declaration, method block, class block, etc. The value to use inside the
annotation is the exact name of the bug-pattern defined by Error Prone. You can
also suppress multiple warnings by providing a string array instead of a single
value.
@SuppressWarnings("FormatString")
public class FormattingTest { ... }
@SuppressWarnings({"FormatString", "ArrayToString"})
public class FormattingTest { ... }
Disable one check. If you want to disable one check completely, you can
turn off the check as a compiler option. Each check has a severity, it is one of
the values of “OFF”, “WARN”, and “ERROR”. For example, to turn off the check
ReferenceEquality
, you can do:
# A valid Error Prone command-line option looks like:
#
# -Xep:<checkName>[:severity]
#
# To turn off ReferenceEquality check:
-Xep:ReferenceEquality:OFF
Disable all checks. You may also want to disable all checks. This can be
useful when you have a big codebase with a large number of existing bug patterns
identified. These bugs are low-priority and cannot be fixed immediately.
Therefore, you need to adapt Error Prone progressively by enabling patterns
explicitly one after another. To disable all the checks, you need to pass the
following option to the compiler:
#
# Disable all checks
#
-XepDisableAllChecks
#
# Then enable some of them
#
-Xep:UnusedMethod:ERROR
-Xep:RemoveUnusedImports:ERROR
Exclude some paths. You can also define paths to exclude as a regular
expression. It allows matching against a source file’s path to determine
whether it should be excluded.
# Exclude generated files
-XepExcludedPaths:.*/build/generated/.*
You can see more information from the command-line flags page of the official
website: https://errorprone.info/docs/flags
Limitation
What are the limits of Error Prone?
Error Prone cannot be the only code analysis tool. It’s great to have a code
analysis tool running at compile-time, but I think other code analysis tools
still have their place. Some tools, such as Sonar, can be executed at build time and generate
report which can be stored in a server. It aggregates historical data, attaches code
coverage report, assigns to people, evaluates the quality score, etc. These cannot
be handled by Error Prone.
Error Prone is limited to Java. We cannot use it for other languages.
Error Prone command-line options cannot be defined at a module level in Maven.
At least I don’t know how to do… Centralizing everything inside the parent
POM is not a very flexible solution. Sometimes I would like to custom the checks
by modules, but I cannot do that.
Error Prone is sometimes annoying. Whenever you have an error, it fails at
compile time. Some other errors may not be displayed until the current one
is fixed. This fail-fast strategy makes it a bit annoying when you are actively
writing code. Maybe Google developers are so good that they only write bug-free
software :p
Going Further
How to go further from here?
- To know more about the Error Prone, visit their official website
https://errorprone.info/. Some additional topics that are not
covered by this blog, such as writing a custom check, automatic refactoring using
Refaster
, but they can be found from the official website. - To see the source code of Error Prone, visit GitHub project:
https://github.com/google/error-prone - Annotation processor is a powerful tool to bring additional capacity to Java
compiler, such as code generation, compile-time type checks. To learn more
about annotation processing, visit Gunnar Morling’s GitHub page “Awesome Java
Annotation Processing” https://github.com/gunnarmorling/awesome-annotation-processing/ - Want to eliminate
NullPointerException
s (NPEs)? Uber has developed
“NullAway”, an Error Prone plugin to check the null-ability in your code. Visit
this project on GitHub: https://github.com/uber/NullAway
Conclusion
In this article, we discovered Google Error-Prone, a Java annotation processing
tool to detect code errors at compile-time. We saw the advantages of using Error
Prone, the usage in Maven, some bug patterns, the ways to suppress warnings, the
limitation, and finally, how to go further from here.
Interested to know more? You can subscribe to the feed of my blog, follow me
on Twitter or
GitHub. Hope you enjoy this article, see you the next time!
References
- Error Prone developers, “Error Prone”, 2020. https://errorprone.info/
- Wikipedia, “Shift-left testing”, Wikipedia, 2020.
https://en.wikipedia.org/wiki/Shift-left_testing
google / error-prone
Goto Github
PK
View Code? Open in Web Editor
NEW
171.0
716.0
113.43 MB
Catch common Java mistakes as compile-time errors
Home Page: https://errorprone.info
License: Apache License 2.0
Shell 0.02%
Mustache 0.02%
Starlark 0.01%
static-analysis
error-prone’s Introduction
Error Prone is a static analysis tool for Java that catches common programming
mistakes at compile-time.
public class ShortSet { public static void main (String[] args) { Set<Short> s = new HashSet<>(); for (short i = 0; i < 100; i++) { s.add(i); s.remove(i - 1); } System.out.println(s.size()); } }
error: [CollectionIncompatibleType] Argument 'i - 1' should not be passed to this method;
its type int is not compatible with its collection's type argument Short
s.remove(i - 1);
^
(see https://errorprone.info/bugpattern/CollectionIncompatibleType)
1 error
Getting Started
Our documentation is at errorprone.info.
Error Prone works with Bazel,
Maven, Ant, and
Gradle. See our installation
instructions for details.
Developing Error Prone
Developing and building Error Prone is documented on the
wiki.
Links
- Mailing lists
- General
discussion - Announcements
- General
- Javadoc
- Pre-release snapshots are available from Sonatype’s snapshot
repository.
error-prone’s People
error-prone’s Issues
Release 0.9 has bad tools jar dependency
Original issue created by [email protected] on 2012-05-30 at 04:31 AM
The maven release automatically resolved a variable from my local path, which isn’t valid outside of my machine.
The current 0.9 release has this in the POM:
<dependencies>
<dependency>
<groupId>openjdk</groupId>
<artifactId>tools</artifactId>
<version>1.6</version>
<scope>system</scope>
<systemPath>/usr/local/buildtools/java/jdk6-google-v4/jre/../lib/tools.jar</systemPath>
</dependency>
Filler for Non-Existent Issue
Filler for non-existent Google Code issue 22.
This issue only exists to ensure that GitHub issues have the same IDs they had on Google Code. Please ignore it.
Disallow annotating a non-static method with @BeforeClass
Original issue created by [email protected] on 2012-07-16 at 07:18 PM
The JUnit @BeforeClass annotation should only be applied to a public static void no-arg method, otherwise it throws a runtime error. We should detect this at compile time.
There may also be other JUnit-specific checks we can write. For example, JUnit doesn’t run tests that are not marked public. This can cause someone to mistakenly think that their newly created tests are runnign when they’re actually not. Some other reason tests weren’t being run:
- The test class did not extend TestCase
- The test method wasn’t public
- The test method didn’t start with «test» (e.g. tesSomething)
- The test method took a parameter
Check that @Override annotation is used in all appropriate places
Original issue created by [email protected] on 2012-08-28 at 09:42 PM
Check that any method that overrides another method is annotated with @Override. Perhaps this shouldn’t be an error but rather a warning.
Code review request
Original issue created by [email protected] on 2011-10-21 at 05:58 PM
If you have some time, I’ve made some more commits which are unreviewed and I’d be interested in feedback.
Like we just discussed, there are still cases where the Exception reference escapes and this code reports a false positive error.
private Fields which should not be reassigned, but cannot be marked with final keyword
Original issue created by [email protected] on 2012-07-30 at 05:15 PM
Suggested by David Mankin:
In Guice, we have @Inject fields, which should only be set by the injector when creating the class. Since they can’t be marked final, we often prefer to use constructor injection instead, even though it’s quite bulky.
Similarly in GWT, fields cannot be marked final because the serialization mechanism needs to be able to set the values in the server when populating a data object.
We should be able to enforce that such fields are never re-assigned in code within the class.
We might want an annotation for this, maybe in JSR305, or maybe JSR330 (which would be nice since other DI frameworks should take advantage). For Guice, you could imagine @Inject(finalish=true) but if we do GWT, may as well make an annotation.
Probably not practical to do this with non-private fields since we’d have to scan outside the enclosing class.
Code review request
Original issue created by [email protected] on 2011-10-28 at 09:26 AM
Purpose of code changes on this branch:
Checking and fixing String.format() calls in Guava Preconditions calls.
When reviewing my code changes, please focus on:
General code review — I’m a beginner to this code, so I’m probably doing things in a non-optimal way.
After the review, I’ll merge this branch into:
master
Disallow non-static methods to be annotated org.junit.BeforeClass
Original issue created by [email protected] on 2012-07-16 at 06:48 PM
The BeforeClass method is called reflectively by JUnit before creating instances of the test class. So a non-static implementation causes an error.
Code review request
Original issue created by [email protected] on 2011-09-26 at 11:56 PM
Branch name:
importfix
Purpose of code changes on this branch:
Fixed a failing test case where the Preconditions.checkNotNull() method being called was a different one from the one the check should match. Fixed this by altering the system to process import statements.
After the review, I’ll merge this branch into:
master
Matchers set to severity level WARNING still produce hard errors
Original issue created by [email protected] on 2012-07-25 at 12:23 AM
JavacErrorDescriptionListener unconditionally calls log.error() regardless of the matcher’s severity level. I think it should call log.warning() if the severity level is set to WARNING.
Code review request
Original issue created by [email protected] on 2012-09-07 at 10:22 PM
Purpose of code changes on this branch:
Provide a way for matchers to request an arbitrary type. This is a fix for Issue 30: #30
Filler for Non-Existent Issue
Filler for non-existent Google Code issue 21.
This issue only exists to ensure that GitHub issues have the same IDs they had on Google Code. Please ignore it.
Types generation from strings.
Original issue created by [email protected] on 2012-07-27 at 11:14 AM
As far as I dug into the error-prone and javac there is no convenient way to get a Type from String. And sometimes you need to check if the result type is a subtype of/castable to java.lang.Object[] or java.util.List<Integer>, etc.
Of course for plain classes (e.g. java.lang.Object) you can make a look-up in symtab, but you can’t do the same for array types and parametrized classes. (Am I wrong here?)
I think it would be great to have such a method in error-prone library.
Something like «Type getType(String typeName)».
Code review request
Run checks in Eclipse
Original issue created by [email protected] on 2012-01-29 at 07:56 PM
ECJ (eclipse compiler for Java) has its own representation of the source. We need to abstract our usage of the AST and symbol table to be able to operate on this representation. Then, we need to figure out where to wire in the execution of our TreeScanners.
Code review request
Original issue created by [email protected] on 2011-11-30 at 04:40 PM
Purpose of code changes:
Added a empty-if-statements checker
When reviewing my code changes, please focus on:
Did I construct the new matchers correctly? Some of the type signatures were confusing. Everything does work.
Disallow lowercase l in long literals
Original issue created by [email protected] on 2012-07-16 at 05:50 PM
Representing a long literal with 5432L is far superior to 5432l for obvious reasons, and I think we should at least consider making the latter an error.
Validate literal regular expressions
Original issue created by [email protected] on 2012-10-19 at 02:10 AM
When a string literal is passed for a parameter that is known to expect a regex (Pattern.compile, String.split, etc.), try to actually compile that regex, and fail the build if that throws an exception.
(Perhaps also when the value of some constant is passed, and that constant is set to a literal. Etc.)
Check that @Override annotation is used in all appropriate places
Original issue created by [email protected] on 2012-08-28 at 09:42 PM
Check that any method that overrides another method is annotated with @Override. Perhaps this shouldn’t be an error but rather a warning.
Wiki generator includes .class files in wiki pages
Original issue created by [email protected] on 2012-01-28 at 01:18 AM
The wiki generator includes .class files in the generated wiki pages. It should only include .java files.
Code review request
Original issue created by [email protected] on 2012-07-21 at 12:30 AM
Refactored tests to make them more consistent and to share common code via a helper class.
ReturnValueIgnored checker should support javax.annotation.CheckReturnValue annotation
Original issue created by aftandilian on 2012-09-20 at 05:42 PM
Our ReturnValueIgnored checker should support the javax.annotation.CheckReturnValue annotation from JSR 305.
Code review request
Original issue created by [email protected] on 2012-09-11 at 11:21 AM
Branch name: longliteral
Purpose of code changes on this branch: Add checker for long literals ending with lower case ell, e.g. 123432l rather than 123432L. See #23
After the review, I’ll merge this branch into: /master
Code review request
Original issue created by [email protected] on 2012-07-26 at 09:54 PM
Please take a look at my 3 commits from today (7/26). I reworked ErrorReportingJavaCompiler to scan compilation units all at once, so that file-level nodes like imports and package declarations are scanned.
errorMessageTemplates in Guava Preconditions class can only accept «%s» format variables
Original issue created by [email protected] on 2012-10-24 at 06:06 PM
Several methods in the Guava Preconditions class take an errorMessageTemplate that may be customized by substituting for «%s» in the template. Often the templates actually include other format specifiers («%d», «%f», etc.), but those are not supported by the formatter.
Example:
Preconditions.checkArgument(i > 0, «i (%d) must be greater than zero», i);
should be
Preconditions.checkArgument(i > 0, «i (%s) must be greater than zero», i);
Code review request
Original issue created by [email protected] on 2012-03-02 at 11:01 PM
Fixed a bug in which compiling files that contain multiple top-level classes causes NullPointerExceptions. Please take a look at revision 66f9b5b and let me know what you think.
Code review request
Original issue created by [email protected] on 2012-03-24 at 12:45 AM
Added support to SuggestedFix to add or remove imports. Please take a look and let me know what you think.
Consider supporting JSR 305 annotations
Investigate operator precedence check
Code review request
Original issue created by [email protected] on 2011-09-30 at 06:24 PM
Several commits to fix problems, and to move the JSR-269 dependency out of the ASTvisitor
Code review request
Original issue created by [email protected] on 2012-10-18 at 09:42 AM
Branch name: unneeded-ternary
Purpose of code changes on this branch:
Add new check for an unnecessary conditional operator
After the review, I’ll merge this branch into:
/trunk
Error messages show only the first line of a multi-line fix
Original issue created by [email protected] on 2012-06-11 at 10:28 PM
Error messages show only the first line of a multi-line fix. We need to think about how to present larger fixes, such as those for covariant equals where we make changes to the whole method.
Code review request
Original issue created by [email protected] on 2011-09-27 at 10:30 PM
Branch name:
fixmultipleimports
Purpose of code changes on this branch:
Fixed two problems: (1) Matcher now checks all imports, and (2) matcher now supports fully-qualified method calls.
When reviewing my code changes, please focus on:
After the review, I’ll merge this branch into:
master
Code review request
Original issue created by [email protected] on 2012-08-29 at 03:39 PM
Better suggested fix and test case for the Ordering.from refactoring:
Ordering.from(new Comparator<T>() { … })
to
new Ordering<T>() { … }
There might be a nicer way of getting hold of the «…» than the way I’ve found (which is basically to re-construct the AST object and pretty-print it): hints welcome.
Code review request
Original issue created by [email protected] on 2012-10-01 at 10:34 PM
I fixed a bug with the compiler in the case that we are trying to scan a compilation unit that hasn’t had all of its classes attributed yet.
Previously I had assumed that flow() would be called once on each class; that turns out not to be the case. We now track which classes error-prone has seen, and we only scan a compilation unit when we’ve seen all of its contained classes.
Calling getAnnotation on an annotation type that does not have runtime retention
Original issue created by [email protected] on 2012-08-29 at 12:46 AM
The Class.getAnnotation method may be called with an annotation type that is not retained a runtime, and thus it will always return null. error-prone should detect this and issue an error.
AST is missing comments
Original issue created by [email protected] on 2012-01-30 at 05:20 PM
When we scan an AST, the comments are missing. This prevents us checking file contents in comments, and also means that our suggested fix/refactoring loses comments in the tree being modified.
Invoking a static method from an instance
Original issue created by [email protected] on 2012-08-03 at 03:52 PM
someFoo.someStaticMethod() is a piece of awfulness that leads nowhere good. I think many teams would love to just make it an error.
EmptyIf diagnostic places caret at different AST node than javac
Original issue created by [email protected] on 2012-05-30 at 05:01 PM
CheckpointCopier.java:91: [empty] empty statement after if
if(true);
^
CheckpointCopier.java:91: [EmptyIf] Empty statement after if
if(true);
^
2 errors
GWT SafeHtml check
Original issue created by [email protected] on 2012-07-19 at 08:35 PM
GWT has an API called «SafeHtml» that has certain documented restrictions on how you’re supposed to use it, and assuming developers use it correctly they should be largely protected against XSS vulnerabilities. Using it correctly amounts to two requirements:
1. Some methods like SafeHtmlUtils.fromSafeConstant(String) are documented as requiring a «safe» string literal as the argument. Safe is defined here as a string that correctly parses as a sequence of complete HTML tags and leaves the parser in standard HTML context. (E.g., «<b>» is okay; «<a href='» and «<script>» are not.)
2. GWT has legacy methods like Element.setInnerHTML(String) that predate the introduction of SafeHtml APIs and subvert the protections offered, so they should be avoided in favor of the SafeHtml-variants.
My FindBugs works by recognizing the following expressions as safe:
1. String literals that return true for com.google.gwt.safehtml.shared.SafeHtmlHostedModeUtils.isCompleHtml(String).
2. String values returned from a call to SafeHtml.asString().
3. A concatenation of string expressions recognized as safe (e.g., «<b> + safeHtmlValue.asString() + «</b>» is still safe).
It then warns about calls to methods like SafeHtmlUtils.fromSafeConstant(String) or Element.setInnerHTML(String) that aren’t using safe arguments. Recognizing «safe» expressions this way is intentionally lenient to avoid needless code churn due to obviously safe (and incredibly common) code constructs like element.setInnerHTML(«»).
(It’s complicated somewhat further because there are some methods that have an interface like setTextOrHTML(String text, boolean isHtml), and I further only warn on these methods if I can’t statically determine the isHtml boolean argument is always false.)
Add PreconditionsTooManyArgs bug pattern
Original issue created by [email protected] on 2012-10-26 at 10:47 PM
Branch name: preconditions-toomanyargs
Purpose of code changes on this branch:
Add a new bug pattern to match (especially) cases in which the wrong Precondition formatting placeholders have been used.
When reviewing my code changes, please focus on:
I have no idea what I’m doing.
After the review, I’ll merge this branch into:
/trunk
Code review request
Original issue created by [email protected] on 2012-09-04 at 10:55 AM
Branch name: suppress
Purpose of code changes on this branch:
Checks for incorrectly spelled @SuppressWarnings() annotation values («deprecated» instead of «deprecation» — cleaned it up recently with several dozen instances in google3).
I’ve refactored some of the code from the FallThroughSuppression check
into an abstract superclass.
After the review, I’ll merge this branch into:
/master
Code review request
Original issue created by [email protected] on 2012-10-20 at 12:53 AM
Please take a look at commit 6f8ddb6. I changed the ObjectEqualsSelfComparsion checker to also check for foo.equals(foo).
Check that equals() and hashCode() read the same fields
Original issue created by [email protected] on 2012-08-06 at 08:48 PM
If I add a new field to a class, I can remember to update equals() but forget to update hashCode(). How would we detect this? In many cases, both methods should read all fields of a class, but that’s probably too strong a check. (For example, a List.equals() implementation might read no fields directly, preferring to operation on the public size() and get() methods.) A weaker but probably still useful check is that the two methods read the same set of fields. False positives are still possible. For example, the check would flag a field containing a cached hash code, which would likely be read in hashCode() but not equals(). This particular example is avoidable by requiring the hashCode() looks at a subset of the fields that equals() looks at. I conjecture that it’s more common for programmers to update equals() but forget to update hashCode() than vice versa, so this further weakened check would likely still catch most problems.
Code review request
Original issue created by [email protected] on 2011-10-16 at 03:02 AM
Please review recent unreviewed changes, when you have a few minutes.
No particular standards yet. Thanks!
Code review request
Original issue created by [email protected] on 2011-11-04 at 02:16 PM
Purpose of code changes on this branch:
When reviewing my code changes, please focus on:
After the review, I’ll merge this branch into:
/trunk
Doesn’t work on OpenJDK
Original issue created by [email protected] on 2012-01-30 at 05:19 PM
Our compile is broken against OpenJDK right now.
Additionally, the javac.util.Messages API in jdk6 has become javac.util.JavacMessages in jdk7, so we’ll need to compile correctly against either version.
Fallthrough suppression shouldn’t be on by default
Original issue created by [email protected] on 2012-05-24 at 04:29 PM
Tried turning on error prone in the Guava maven build.
Get lots of errors like:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project guava: Compilation failure: Compilation failure:
[ERROR] /Users/alexeagle/guava-libraries/guava/src/com/google/common/math/LongMath.java:[74,3] [FallthroughSuppression] Fallthrough warning suppression has no effect if warning is suppressed
[ERROR](see http://code.google.com/p/error-prone/wiki/FallthroughSuppression)
[ERROR] did you mean to remove this line?
Printed error messages are sometimes incorrect
Original issue created by [email protected] on 2012-01-10 at 12:55 AM
When a fix is to delete a line, but the line is not the same one where the error was found, the error message is incorrect. For example, this code:
if (i == 10)
;
{
foo…
}
Will produce the following error message:
[Empty if] Empty statement after if; did you mean to remove this line?
if (i == 10)
^
When you intend it to delete the line with the semicolon.
I’ve added a test case in emptyifstatement/PositiveCases.java under test5().
Support Apple-provided JDK
Original issue created by [email protected] on 2012-05-21 at 03:22 AM
Currently, the way we hook into javac has only been tested with OpenJDK 6 and 7. Not sure how many developers expect to compile with Apple’s JDK, since it is probably going to be sunset and Oracle will start maintaining the Mac version.
Recommend Projects
-
ReactA declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
TypescriptTypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlowAn Open Source Machine Learning Framework for Everyone
-
DjangoThe Web framework for perfectionists with deadlines.
-
LaravelA PHP framework for web artisans
-
D3Bring data to life with SVG, Canvas and HTML. 📊📈🎉
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
FacebookWe are working to build community through open source technology. NB: members must have two-factor auth.
-
MicrosoftOpen source projects and samples from Microsoft.
-
GoogleGoogle ❤️ Open Source for everyone.
-
AlibabaAlibaba Open Source for everyone
-
D3Data-Driven Documents codes.
-
TencentChina tencent open source team.
-
JDK 14/15 compatibility
What version of Error Prone are you using?
2.3.4 (originally 2.3.1)
Does this issue reproduce with the latest release?
Yes
What did you do?
Error-prone does not work with JDK12 EA b09 and produces the following exception:
[javac] 1 warning [javac] An exception has occurred in the compiler (12-ea). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you. [javac] java.lang.NoSuchMethodError: com.sun.tools.javac.util.Log.error(Lcom/sun/tools/javac/util/JCDiagnostic$DiagnosticPosition;Ljava/lang/String;[Ljava/lang/Object;)V [javac] at com.google.errorprone.ErrorProneError.logFatalError(ErrorProneError.java:55) [javac] at com.google.errorprone.ErrorProneAnalyzer.finished(ErrorProneAnalyzer.java:155) [javac] at jdk.compiler/com.sun.tools.javac.api.MultiTaskListener.finished(MultiTaskListener.java:132) [javac] at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1418) [javac] at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1365) [javac] at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:960) [javac] at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:311) [javac] at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:170) [javac] at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57) [javac] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [javac] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [javac] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [javac] at java.base/java.lang.reflect.Method.invoke(Method.java:566) [javac] at org.apache.tools.ant.taskdefs.compilers.Javac13.execute(Javac13.java:57) [javac] at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1404) [javac] at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:1133) [javac] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292) [javac] at jdk.internal.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) [javac] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [javac] at java.base/java.lang.reflect.Method.invoke(Method.java:566) [javac] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99) [javac] at org.apache.tools.ant.Task.perform(Task.java:350) [javac] at org.apache.tools.ant.Target.execute(Target.java:449) [javac] at org.apache.tools.ant.Target.performTasks(Target.java:470) [javac] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1388) [javac] at org.apache.tools.ant.Project.executeTarget(Project.java:1361) [javac] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41) [javac] at org.apache.tools.ant.Project.executeTargets(Project.java:1251) [javac] at org.apache.tools.ant.Main.runBuild(Main.java:834) [javac] at org.apache.tools.ant.Main.startAnt(Main.java:223) [javac] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:284) [javac] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:101)
It works fine with previous build (JDK 12 EA b08). I don’t know what change causes this error.
opened by don-vip 48
-
Full Java 8 support
Original issue created by [email protected] on 2014-03-27 at 04:19 PM
Right now we have a build for javac 8 but are missing two important items needed for full support:
-
Our Jenkins continuous build does not run Java 8 yet, only 6 and 7.
-
We don’t yet distribute the error-prone 8 jars to Sonatype. We probably want to distribute two sets of jars, one for versions 6 and 7, and one for 8. It would be nice if Maven could figure out which dependency to use based on the version of javac installed.
Priority-High migrated Status-Accepted
opened by cushon 26
-
-
‘An illegal reflective access operation has occurred’ warnings
The warning:
Changes detected - recompiling the module! Compiling 8 source files to /home/my_stuff/target/classes WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by com.google.errorprone.bugpatterns.FutureReturnValueIgnored (file:/my_home/.m2/repository/com/google/errorprone/error_prone_core/2.3.2/error_prone_core-2.3.2.jar) to field com.sun.tools.javac.code.Type$StructuralTypeMapping$4.this$0 WARNING: Please consider reporting this to the maintainers of com.google.errorprone.bugpatterns.FutureReturnValueIgnored WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release
$ java --version openjdk 11.0.1 2018-10-16 OpenJDK Runtime Environment 18.9 (build 11.0.1+13) OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)
Java code that (rightfully) triggers the warning:
@SuppressWarnings("FutureReturnValueIgnored") private void schedule(Runnable runnable, long delayMs) { try { scheduledExecutorService.schedule(runnable, delayMs, TimeUnit.MILLISECONDS); } catch (RejectedExecutionException ex) { // shutting down, no more checks } }
I’m using the maven plugin as such:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <configuration> <release>11</release> <debug>true</debug> <showDeprecation>true</showDeprecation> <showWarnings>true</showWarnings> <compilerArgument>-parameters</compilerArgument> <compilerArgs> <arg>-Xlint:all</arg> <arg>-Xlint:-processing</arg> <arg>-Werror</arg> <arg>-XDcompilePolicy=simple</arg> <arg>-Xplugin:ErrorProne</arg> </compilerArgs> <annotationProcessorPaths> <path> <groupId>com.google.errorprone</groupId> <artifactId>error_prone_core</artifactId> <version>2.3.2</version> </path> </annotationProcessorPaths> </configuration> </plugin>
opened by zimmi 24
-
lombok causes an IndexOutOfBoundsException in ParameterName
After #690 was fixed, I removed the exclusions for the problematic bug patterns and tried to compile a project using Lombok, but it looks like the new bug pattern
ParameterName
also does not work well with Lombok it seems. Next time I’ll make sure to try out Error Prone snapshots before a releaseVersions
Error Prone version:
2.1.2
Lombok version:1.16.18
/1.16.16
Maven version:Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-04T04:39:06+09:00)
Java version:1.8.0_144
, vendor: Oracle CorporationNote that I am also able to reproduce the issue with JDK 9.
Reproducing Class:
import lombok.Data; @Data public class SomeData {}
Stack trace
[ERROR] Please report this at https://github.com/google/error-prone/issues/new and include the following: [ERROR] [ERROR] error-prone version: 2.1.2 [ERROR] Stack Trace: [ERROR] java.lang.IndexOutOfBoundsException [ERROR] at java.nio.HeapCharBuffer.subSequence(HeapCharBuffer.java:580) [ERROR] at java.nio.HeapCharBuffer.subSequence(HeapCharBuffer.java:42) [ERROR] at com.google.errorprone.bugpatterns.ParameterName.checkArguments(ParameterName.java:85) [ERROR] at com.google.errorprone.bugpatterns.ParameterName.matchMethodInvocation(ParameterName.java:64) [ERROR] at com.google.errorprone.scanner.ErrorProneScanner.visitMethodInvocation(ErrorProneScanner.java:907) [ERROR] at com.google.errorprone.scanner.ErrorProneScanner.visitMethodInvocation(ErrorProneScanner.java:146) [ERROR] at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1644) [ERROR] at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82) [ERROR] at com.google.errorprone.scanner.Scanner.scan(Scanner.java:82) [ERROR] at com.google.errorprone.scanner.Scanner.scan(Scanner.java:42) [ERROR] at com.sun.source.util.TreeScanner.visitUnary(TreeScanner.java:612) [ERROR] at com.google.errorprone.scanner.ErrorProneScanner.visitUnary(ErrorProneScanner.java:1126) [ERROR] at com.google.errorprone.scanner.ErrorProneScanner.visitUnary(ErrorProneScanner.java:146) [ERROR] at com.sun.tools.javac.tree.JCTree$JCUnary.accept(JCTree.java:1956) [ERROR] at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82) [ERROR] at com.google.errorprone.scanner.Scanner.scan(Scanner.java:82) [ERROR] at com.google.errorprone.scanner.Scanner.scan(Scanner.java:42) [ERROR] at com.sun.source.util.TreeScanner.visitIf(TreeScanner.java:418) [ERROR] at com.google.errorprone.scanner.ErrorProneScanner.visitIf(ErrorProneScanner.java:758) [ERROR] at com.google.errorprone.scanner.ErrorProneScanner.visitIf(ErrorProneScanner.java:146) [ERROR] at com.sun.tools.javac.tree.JCTree$JCIf.accept(JCTree.java:1427) [ERROR] at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82) [ERROR] at com.google.errorprone.scanner.Scanner.scan(Scanner.java:82) [ERROR] at com.google.errorprone.scanner.Scanner.scan(Scanner.java:42) [ERROR] at com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:90) [ERROR] at com.sun.source.util.TreeScanner.scan(TreeScanner.java:105) [ERROR] at com.sun.source.util.TreeScanner.visitBlock(TreeScanner.java:248) [ERROR] at com.google.errorprone.scanner.ErrorProneScanner.visitBlock(ErrorProneScanner.java:530) [ERROR] at com.google.errorprone.scanner.ErrorProneScanner.visitBlock(ErrorProneScanner.java:146) [ERROR] at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1026) [ERROR] at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82) [ERROR] at com.google.errorprone.scanner.Scanner.scan(Scanner.java:82) [ERROR] at com.google.errorprone.scanner.Scanner.scan(Scanner.java:42) [ERROR] at com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:90) [ERROR] at com.sun.source.util.TreeScanner.visitMethod(TreeScanner.java:206) [ERROR] at com.google.errorprone.scanner.ErrorProneScanner.visitMethod(ErrorProneScanner.java:898) [ERROR] at com.google.errorprone.scanner.ErrorProneScanner.visitMethod(ErrorProneScanner.java:146) [ERROR] at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:898) [ERROR] at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82) [ERROR] at com.google.errorprone.scanner.Scanner.scan(Scanner.java:82) [ERROR] at com.google.errorprone.scanner.Scanner.scan(Scanner.java:42) [ERROR] at com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:90) [ERROR] at com.sun.source.util.TreeScanner.scan(TreeScanner.java:105) [ERROR] at com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:113) [ERROR] at com.sun.source.util.TreeScanner.visitClass(TreeScanner.java:187) [ERROR] at com.google.errorprone.scanner.ErrorProneScanner.visitClass(ErrorProneScanner.java:590) [ERROR] at com.google.errorprone.scanner.ErrorProneScanner.visitClass(ErrorProneScanner.java:146) [ERROR] at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:808) [ERROR] at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82) [ERROR] at com.google.errorprone.scanner.Scanner.scan(Scanner.java:82) [ERROR] at com.google.errorprone.scanner.Scanner.scan(Scanner.java:42) [ERROR] at com.sun.source.util.TreeScanner.scan(TreeScanner.java:105) [ERROR] at com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:113) [ERROR] at com.sun.source.util.TreeScanner.visitCompilationUnit(TreeScanner.java:144) [ERROR] at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:605) [ERROR] at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:146) [ERROR] at com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:591) [ERROR] at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:56) [ERROR] at com.google.errorprone.scanner.Scanner.scan(Scanner.java:64) [ERROR] at com.google.errorprone.scanner.ErrorProneScannerTransformer.apply(ErrorProneScannerTransformer.java:41) [ERROR] at com.google.errorprone.ErrorProneAnalyzer.finished(ErrorProneAnalyzer.java:145) [ERROR] at com.sun.tools.javac.api.MultiTaskListener.finished(MultiTaskListener.java:120) [ERROR] at com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1425) [ERROR] at com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1374) [ERROR] at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:973) [ERROR] at com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:100) [ERROR] at com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:142) [ERROR] at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:96) [ERROR] at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:90) [ERROR] at com.google.errorprone.BaseErrorProneCompiler.run(BaseErrorProneCompiler.java:137) [ERROR] at com.google.errorprone.BaseErrorProneCompiler.run(BaseErrorProneCompiler.java:108) [ERROR] at com.google.errorprone.ErrorProneCompiler.run(ErrorProneCompiler.java:118) [ERROR] at org.codehaus.plexus.compiler.javac.errorprone.JavacCompilerWithErrorProne$CompilerInvoker.compile(JavacCompilerWithErrorProne.java:222) [ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [ERROR] at java.lang.reflect.Method.invoke(Method.java:498) [ERROR] at org.codehaus.plexus.compiler.javac.errorprone.JavacCompilerWithErrorProne.performCompile(JavacCompilerWithErrorProne.java:91) [ERROR] at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:1075) [ERROR] at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:168) [ERROR] at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134) [ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208) [ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154) [ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146) [ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117) [ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81) [ERROR] at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51) [ERROR] at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128) [ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309) [ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194) [ERROR] at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107) [ERROR] at org.apache.maven.cli.MavenCli.execute(MavenCli.java:993) [ERROR] at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345) [ERROR] at org.apache.maven.cli.MavenCli.main(MavenCli.java:191) [ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [ERROR] at java.lang.reflect.Method.invoke(Method.java:498) [ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) [ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) [ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) [ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356) [ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [ERROR] at java.lang.reflect.Method.invoke(Method.java:498) [ERROR] at org.apache.maven.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:39) [ERROR] at org.apache.maven.wrapper.WrapperExecutor.execute(WrapperExecutor.java:122) [ERROR] at org.apache.maven.wrapper.MavenWrapperMain.main(MavenWrapperMain.java:50)
Workaround
Disable the newly introduced
ParameterName
bug pattern via a compiler argument:-Xep:ParameterName:OFF
lombok
opened by shakuzen 24
-
NullPointerException in 2.1.1 in Android compilation
I can’t see an obvious check that’s failing here. This is compiling an Android application.
3 warnings An exception has occurred in the compiler (1.8.0_112-release). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you. java.lang.NullPointerException at com.sun.tools.javac.comp.Flow$FlowAnalyzer.visitApply(Flow.java:1233) at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1628) at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49) at com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:393) at com.sun.tools.javac.tree.TreeScanner.visitExec(TreeScanner.java:213) at com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1446) at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49) at com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:393) at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57) at com.sun.tools.javac.comp.Flow$FlowAnalyzer.visitBlock(Flow.java:995) at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1014) at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49) at com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:393) at com.sun.tools.javac.comp.Flow$FlowAnalyzer.visitMethodDef(Flow.java:962) at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:866) at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49) at com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:393) at com.sun.tools.javac.comp.Flow$FlowAnalyzer.visitClassDef(Flow.java:925) at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:774) at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49) at com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:393) at com.sun.tools.javac.comp.Flow$FlowAnalyzer.analyzeTree(Flow.java:1325) at com.sun.tools.javac.comp.Flow$FlowAnalyzer.analyzeTree(Flow.java:1315) at com.sun.tools.javac.comp.Flow.analyzeTree(Flow.java:213) at com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1410) at com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1374) at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:973) at com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:100) at com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:142) at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:96) at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:90) at com.google.errorprone.BaseErrorProneCompiler.run(BaseErrorProneCompiler.java:137) at com.google.errorprone.BaseErrorProneCompiler.run(BaseErrorProneCompiler.java:108) at com.google.errorprone.ErrorProneCompiler.run(ErrorProneCompiler.java:118) at com.google.errorprone.ErrorProneCompiler.compile(ErrorProneCompiler.java:65) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at net.ltgt.gradle.errorprone.ErrorProneCompiler.execute(ErrorProneCompiler.java:76) at net.ltgt.gradle.errorprone.ErrorProneCompiler.execute(ErrorProneCompiler.java:26) at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:104) at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:53) at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:38) at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:35) at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:25) at org.gradle.api.tasks.compile.JavaCompile.performCompilation(JavaCompile.java:206) at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:187) at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:130) at com.android.build.gradle.tasks.factory.AndroidJavaCompile.compile(AndroidJavaCompile.java:49) at sun.reflect.GeneratedMethodAccessor1187.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73) at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:163) at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134) at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:123) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:95) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:76) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:55) at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62) at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58) at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88) at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:46) at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51) at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54) at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43) at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34) at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:236) at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:228) at org.gradle.internal.Transformers$4.transform(Transformers.java:169) at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106) at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:61) at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:228) at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:215) at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:77) at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:58) at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54) at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) FAILED FAILURE: Build failed with an exception.
opened by leepa 24
-
Infinite compilation on JDK11
When upgrading to JDK 11.01, the compilation never finishes but has high CPU activity. When removing ErrorProne, the compilation completes without a problem. I am unsure how to debug, e.g. to see what the javac process is doing, to provide more details.
Environment:
- JDK 11.01 (upgrading from 10+46)
- Mac OS X Mojave
- Gradle 5.0
- ErrorProne:
- core: 2.3.2
- javac: 9+181-r4173-1
- plugin: 0.6
- Annotation Processors:
- autoFactory: 1.0-beta6
- autoValue: 1.6.3
- autoValueBuilder: 2.9.1
Of course if I disable the annotation processors then it fails due to the missing generated classes, but does terminate. Removing
autoFactory
leads to the hang, whileautoValue
is used too frequently to get a hang prior. So there is a chance that it is related to annotation processing (such as due to Gradle’s incremental support), but could be something else.
opened by ben-manes 21
-
Lombok breaks NestedInstanceOfConditions and InstanceOfAndCastMatchWrongType
Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-03T15:39:06-04:00)
Java version: 1.8.0_131, vendor: Oracle Corporation
Lombok version: 1.16.16java.lang.NullPointerException at lombok.javac.apt.LombokFileObjects.createEmpty(LombokFileObjects.java:123) at lombok.javac.apt.InterceptingJavaFileManager.getJavaFileForOutput(InterceptingJavaFileManager.java:47) at com.sun.tools.javac.processing.JavacFiler.createSourceOrClassFile(JavacFiler.java:478) at com.sun.tools.javac.processing.JavacFiler.createSourceFile(JavacFiler.java:417) at lombok.javac.apt.LombokProcessor.forceNewRound(LombokProcessor.java:333) at lombok.javac.apt.LombokProcessor.process(LombokProcessor.java:322) at lombok.core.AnnotationProcessor$JavacDescriptor.process(AnnotationProcessor.java:114) at lombok.core.AnnotationProcessor.process(AnnotationProcessor.java:164) at lombok.launch.AnnotationProcessorHider$AnnotationProcessor.process(AnnotationProcessor.java:74) at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:968) at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:884) at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$2200(JavacProcessingEnvironment.java:108) at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1204) at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1313) at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1267) at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:943) at com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:100) at com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:142) at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:96) at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:90) at com.google.errorprone.BaseErrorProneCompiler.run(BaseErrorProneCompiler.java:137) at com.google.errorprone.BaseErrorProneCompiler.run(BaseErrorProneCompiler.java:108) at com.google.errorprone.ErrorProneCompiler.run(ErrorProneCompiler.java:118) at com.google.errorprone.ErrorProneCompiler.compile(ErrorProneCompiler.java:65) at org.codehaus.plexus.compiler.javac.errorprone.JavacCompilerWithErrorProne$CompilerInvoker.compile(JavacCompilerWithErrorProne.java:219) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.plexus.compiler.javac.errorprone.JavacCompilerWithErrorProne.performCompile(JavacCompilerWithErrorProne.java:91) at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:825) at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:993) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345) at org.apache.maven.cli.MavenCli.main(MavenCli.java:191) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
error-prone version: 2.0.21 Stack Trace: java.lang.ClassCastException: com.sun.tools.javac.tree.JCTree$JCBinary cannot be cast to com.sun.source.tree.ParenthesizedTree at com.google.errorprone.bugpatterns.NestedInstanceOfConditions.matchIf(NestedInstanceOfConditions.java:53) at com.google.errorprone.scanner.ErrorProneScanner.visitIf(ErrorProneScanner.java:752) at com.google.errorprone.scanner.ErrorProneScanner.visitIf(ErrorProneScanner.java:146) at com.sun.tools.javac.tree.JCTree$JCIf.accept(JCTree.java:1427) at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82) at com.google.errorprone.scanner.Scanner.scan(Scanner.java:82) at com.google.errorprone.scanner.Scanner.scan(Scanner.java:42) at com.sun.source.util.TreeScanner.scan(TreeScanner.java:105) at com.sun.source.util.TreeScanner.visitBlock(TreeScanner.java:248) at com.google.errorprone.scanner.ErrorProneScanner.visitBlock(ErrorProneScanner.java:530) at com.google.errorprone.scanner.ErrorProneScanner.visitBlock(ErrorProneScanner.java:146) at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1026) at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82) at com.google.errorprone.scanner.Scanner.scan(Scanner.java:82) at com.google.errorprone.scanner.Scanner.scan(Scanner.java:42) at com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:90) at com.sun.source.util.TreeScanner.visitMethod(TreeScanner.java:206) at com.google.errorprone.scanner.ErrorProneScanner.visitMethod(ErrorProneScanner.java:898) at com.google.errorprone.scanner.ErrorProneScanner.visitMethod(ErrorProneScanner.java:146) at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:898) at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82) at com.google.errorprone.scanner.Scanner.scan(Scanner.java:82) at com.google.errorprone.scanner.Scanner.scan(Scanner.java:42) at com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:90) at com.sun.source.util.TreeScanner.scan(TreeScanner.java:105) at com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:113) at com.sun.source.util.TreeScanner.visitClass(TreeScanner.java:187) at com.google.errorprone.scanner.ErrorProneScanner.visitClass(ErrorProneScanner.java:590) at com.google.errorprone.scanner.ErrorProneScanner.visitClass(ErrorProneScanner.java:146) at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:808) at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82) at com.google.errorprone.scanner.Scanner.scan(Scanner.java:82) at com.google.errorprone.scanner.Scanner.scan(Scanner.java:42) at com.sun.source.util.TreeScanner.scan(TreeScanner.java:105) at com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:113) at com.sun.source.util.TreeScanner.visitCompilationUnit(TreeScanner.java:144) at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:605) at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:146) at com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:591) at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:56) at com.google.errorprone.scanner.Scanner.scan(Scanner.java:64) at com.google.errorprone.scanner.ErrorProneScannerTransformer.apply(ErrorProneScannerTransformer.java:41) at com.google.errorprone.ErrorProneAnalyzer.finished(ErrorProneAnalyzer.java:145) at com.sun.tools.javac.api.MultiTaskListener.finished(MultiTaskListener.java:120) at com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1425) at com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1374) at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:973) at com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:100) at com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:142) at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:96) at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:90) at com.google.errorprone.BaseErrorProneCompiler.run(BaseErrorProneCompiler.java:137) at com.google.errorprone.BaseErrorProneCompiler.run(BaseErrorProneCompiler.java:108) at com.google.errorprone.ErrorProneCompiler.run(ErrorProneCompiler.java:118) at com.google.errorprone.ErrorProneCompiler.compile(ErrorProneCompiler.java:65) at org.codehaus.plexus.compiler.javac.errorprone.JavacCompilerWithErrorProne$CompilerInvoker.compile(JavacCompilerWithErrorProne.java:219) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.plexus.compiler.javac.errorprone.JavacCompilerWithErrorProne.performCompile(JavacCompilerWithErrorProne.java:91) at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:825) at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:993) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345) at org.apache.maven.cli.MavenCli.main(MavenCli.java:191) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
opened by davidmontoyago 20
-
Upgrade javac to JDK10 to support classfile version 54
When running error-prone with JDK 10-ea+35 we get the following compilation warnings:
[javac] warning: /modules/java.base/java/lang/Deprecated.class: major version 54 is newer than 53, the highest major version supported by this compiler. [javac] It is recommended that the compiler be upgraded.
for each class of the JDK. This is due to JDK-8188870: Bump classfile version number to 54.
With the new release cycle, the compiler will have to be updated every 6 months to support the new classfile version.
Maybe you could directly switch to JDK11 as classfile version 55 is coming soon, see JDK-8191913: Bump classfile version number to 55.
opened by don-vip 19
-
Calling Map/Collection methods with arguments that are not compatible with type parameters
Original issue created by [email protected] on 2013-03-05 at 03:23 PM
There are some methods on Map<K,V> or Collection<V> that accept Object because of compatibility reasons, while in fact they should accept <V>. We can check that arguments passed to those methods are compatible with V.
Example:
Map<MyProto, Integer> map = …;
MyProto.Builder proto = MyProto.newBuilder()…;
if (map.get(proto)) { … };Following checks can be introduced for all «Map<K,V> map» and «T arg» variables:
- map.containsKey(arg) —> check that either «T extends K» or «T super K»
- map.containsValue(arg) —> check that either «T extends V» or «T super V»
- map.get(arg) —> check that either «T extends K» or «T super K»
- map.remove(arg) —> check that either «T extends K» or «T super K»
Following checks can be introduced for all «Collection<V> coll» and «T arg» variables:
- coll.contains(arg) —> check that either «T extends V» or «T super V»
- coll.remove(arg) —> check that either «T extends V» or «T super V»
Same for List.indexOf, List.lastIndexOf.
Priority-High Type-NewCheck migrated Status-Accepted
opened by cushon 19
-
error_prone_core 2.0.6 adds Objects.requireNonNull() to source (which can crash Android)
I’ve been using the error-prone compiler for my Android application.
java.util.Objects
was only added recently to Android (API 19). The most recent version of error_prone_core (2.0.6) can addObjects.requireNonNull()
to the source, which causes the Android app to crash if run on an older device.I haven’t been able to track down exactly how this happens; I’m not super familiar with error-prone’s internals.
I’ve been using error-prone via the gradle-errorprone-plugin for Android builds. By default it pulls in the latest error_prone_core for use. As a workaround you can force it to use 2.0.5.
As an aside, the stack traces that result are quite mystifying since the source will contain no references to
java.util.Objects
. For example:Fatal Exception: java.lang.NoClassDefFoundError: java.util.Objects at com.trello.syncadapter.StarredBoardsSync.execute(StarredBoardsSync.java:66) at com.trello.syncadapter.StarredBoardsSync.performSync(StarredBoardsSync.java:58) at com.trello.syncadapter.TSyncAdapter.onPerformSync(TSyncAdapter.java:49) at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:254)
…Where
StarredBoardsSync
didn’t even importjava.util.Objects
in the original source.
opened by dlew 17
-
Checks on exception handling code
In our recent research paper with the title «Simple Testing Can Prevent Most Critical Failures», we found that a large number of the most deadly failures in production distributed systems are the result of trivial mistakes in exception handling code. Exception handling code is particularly critical to distributed systems as they’re often the last line of defence. We observed three simple, yet deadly, bug patterns:
- «TODO»/»FIXME» in the catch block
- Empty catch block
- Abort in exception over-catch
We implemented a simple checker called Aspirator to detect these three types of mistakes, and it found and fixed hundreds of bugs from Hadoop, HBase, Spark, etc. HBase developers asked us to implement these checks into error-prone, therefore I’m providing these three checks in this pull request.
Type-NewCheck cla: yes
opened by diy1 17
-
False positive for infinite recursion check on overloaded methods
The infinite recursion check incorrectly reports infinite recursion in the following code:
protected int findDirectoryGraphDistance(SourceFile a, SourceFile b) { return findDirectoryGraphDistance(a.getPath(), b.getPath()); } protected int findDirectoryGraphDistance(FilePath a, FilePath b) { return 1234; }
This is not even recursion, it’s just a method calling another overloaded method with the same name but different types.
I’m not sure why this happens, but one of the reasons could be that
SourceFile
is part of our own code base whileFilePath
is a library class. That might influence ErrorProne’s ability to resolve parameter types.Sure, the quick fix would be to either rename one of the methods or to add a
@SuppressWarnings
, but for other users it would be nice if we can avoid this false positive altogether.
opened by dennis-sig 1
-
Error Prone is not recoginizing the symbols and imports
Hi all. I am trying to add error prone to the EasyPost Java repo. Currently, I am using the below shell script to run the error prone check, however, the error prone would throw hundreds of errors saying cannot find the path and cannot recognize the import. Has anyone encountered this in the past? Any advice would be much appreciated!
# This script must be used with Java 9+ # Error Prone newer than 2.10.0 doesn't work on Java 8-10 EP_VERSION="2.10.0" # Install needed jars wget -nc -q https://repo1.maven.org/maven2/com/google/errorprone/error_prone_core/${EP_VERSION?}/error_prone_core-${EP_VERSION?}-with-dependencies.jar wget -nc -q https://repo1.maven.org/maven2/org/checkerframework/dataflow-errorprone/3.15.0/dataflow-errorprone-3.15.0.jar wget -nc -q https://repo1.maven.org/maven2/com/google/code/findbugs/jFormatString/3.0.0/jFormatString-3.0.0.jar # Run Error Prone on the library and test suite javac -J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED -J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED -J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED -J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED -J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED -J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED -J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED -J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED -J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED -J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED -XDcompilePolicy=simple -processorpath error_prone_core-${EP_VERSION?}-with-dependencies.jar:dataflow-errorprone-3.15.0.jar:jFormatString-3.0.0.jar '-Xplugin:ErrorProne' src/main/java/com/easypost/**/*.java
opened by jchen293 6
-
refactor: refactor bad smell ToArrayCallWithZeroLengthArrayArgument
Repairing Code Style Issues
ToArrayCallWithZeroLengthArrayArgument
The performance of the empty array version is the same, and sometimes even better, compared
to the pre-sized version. Also, passing a pre-sized array is dangerous for a concurrent or
synchronized collection as a data race is possible between thesize
andtoArray
calls. This may result in extranull
s at the end of the array if the collection was concurrently
shrunk during the operation.See https://shipilev.net/blog/2016/arrays-wisdom-ancients/ for more details.
Repairing Code Style Issues
- ToArrayCallWithZeroLengthArrayArgument (1)
opened by MartinWitt 0
-
ClassCanBeStatic: Exclude JUnit `@Nested` classes
Exclude inner classes annotated with JUnit’s
@Nested
annotation from theClassCanBeStatic
check. JUnit requires them to not bestatic
.From the JUnit docs:
Only non-static nested classes (i.e. inner classes) can serve as
@Nested
test classes.Fixes #956.
opened by ljrmorgan 1
Error Prone, a Java compiler plugin open sourced by Google, performs static analysis during compilation to detect bugs or suggest possible improvements. The plugin contains more than 500 pre-defined bug checks and allows third party and custom plugins. After detecting issues, Error Prone can display a warning or automatically change the code with a predefined solution. Error Prone supports Java 8, 11 and 17 and may be used for bug fixing or large scale refactoring.Installation and configuration instructions for Maven, Bazel, Ant or Gradle can be found in the documentation. The compiler should be configured to use Error Prone as an annotation processor, for example when creating a test project with Maven:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<release>17</release>
<encoding>UTF-8</encoding>
<compilerArgs>
<arg>-XDcompilePolicy=simple</arg>
<arg>-Xplugin:ErrorProne</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>2.15.0</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
Now an example class can be created. Consider the following method that uses equals
to compare two arrays, more precisely it compares the objects and not the content of the arrays:
public boolean compare(String firstList[], String secondList[]) {
return firstList.equals(secondList);
}
Executing mvn clean verify
triggers the Error Prone analysis and results in the following error message:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:
compile (default-compile) on project ErrorProne: Compilation failure
[ERROR] …/ErrorProne/src/main/java/org/example/Main.java:[5,28]
[ArrayEquals] Reference equality used to compare arrays
[ERROR] (see https://errorprone.info/bugpattern/ArrayEquals)
[ERROR] Did you mean 'return Arrays.equals(firstList, secondList);'?
The ArrayEquals bug pattern is found and Error Prone suggests to change the implementation in order to compare the content of the array instead of the objects:
return Arrays.equals(firstList, secondList);
Receiving an error helps to improve the code, but it’s also possible to let Error Prone apply the solution automatically. The -XepPatchChecks
argument should contain a comma separated list of bug patterns to apply. In this case, only the ArrayEquals solution is applied to the codebase. The -XepPatchLocation
argument is used to specify the location of the solution file. In this case the original file is modified:
<compilerArgs>
<arg>-XDcompilePolicy=simple</arg>
<arg>-Xplugin:ErrorProne -XepPatchChecks:ArrayEquals
-XepPatchLocation:IN_PLACE</arg>
</compilerArgs>
Now, after executing mvn clean verify
the class file is automatically changed to:
public boolean compare(String firstList[], String secondList[]) {
return Arrays.equals(firstList, secondList);
}
The documentation provides more information about the command-line flags.
Apart from the built-in bug patterns, it’s also possible to use patterns from other organizations such as SLF4J or to create a custom plugin. The source code for the built-in rules provides various examples that may be used as the basis for a new plugin. For example, a custom Error Prone plugin can replace the older @Before
JUnit annotation with the new JUnit 5 @BeforeEach
annotation.
The custom Error Prone plugin should be placed in another Maven module than the example project shown earlier. Error Prone uses the service loader mechanism to load the bug checks. Normally, that requires some configuration, however Google’s AutoService project simplifies the configuration by using the @AutoService
annotation. The @BugPattern
annotation is used to configure the name, summary and severity of the bug. The following example returns Description.NO_MATCH
if no @Before
annotation is found or the SuggestedFix
which replaces the @Before
annotation with an @BeforeEach
annotation:
@AutoService(BugChecker.class)
@BugPattern(
name = "BeforeCheck",
summary = "JUnit 4's @Before is replaced by JUnit 5's @BeforeEach",
severity = BugPattern.SeverityLevel.SUGGESTION
)
public class BeforeCheck extends BugChecker implements BugChecker.AnnotationTreeMatcher {
private static final Matcher<AnnotationTree> matcher =
isType("org.junit.Before");
@Override
public Description matchAnnotation(AnnotationTree annotationTree,
VisitorState visitorState) {
if (!matcher.matches(annotationTree, visitorState)) {
return Description.NO_MATCH;
}
return describeMatch(annotationTree,
SuggestedFix.replace(annotationTree, "@BeforeEach"));
}
}
Error Prone and AutoService dependencies are required to build the custom Error Prone plugin:
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_annotations</artifactId>
<version>2.15.0</version>
</dependency>
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_check_api</artifactId>
<version>2.15.0</version>
</dependency>
<dependency>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service-annotations</artifactId>
<version>1.0.1</version>
</dependency>
The AutoService should be configured as an annotation processor:
<annotationProcessorPaths>
<path>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<version>1.0.1</version>
</path>
</annotationProcessorPaths>
Now the custom Error Prone plugin can be installed to the local Maven repository with the mvn install
command. After executing the command, the example project should be configured to use the new custom plugin as an annotation processor:
<annotationProcessorPaths>
<path>
<groupId>org.example.custom.plugin</groupId>
<artifactId>ErrorProneBeforeCheck</artifactId>
<version>1.0-SNAPSHOT</version>
</path>
</annotationProcessorPaths>
The new BeforeCheck
should be added to the Error Prone analysis:
<compilerArgs>
<arg>-XDcompilePolicy=simple</arg>
<arg>-Xplugin:ErrorProne -XepPatchChecks:BeforeCheck
-XepPatchLocation:IN_PLACE</arg>
</compilerArgs>
An example Test class may be added which contains a mix of both @Before
and @BeforeEach
annotations:
public class ErrorProneTest {
@Before
void before() {
}
@BeforeEach
void beforeEach() {
}
}
When running mvn verify
the new custom Error Prone plugin replaces the @Before
annotation with the @BeforeEach
annotation:
public class ErrorProneTest {
@BeforeEach
void before() {
}
@BeforeEach
void beforeEach() {
}
}
Error Prone uses Java internals, that are nowadays hidden, which might result in errors such as:
java.lang.IllegalAccessError: class com.google.errorprone.BaseErrorProneJavaCompiler
(in unnamed module @0x1a6cf771)
cannot access class com.sun.tools.javac.api.BasicJavacTask (in module jdk.compiler)
because module jdk.compiler does not export
com.sun.tools.javac.api to unnamed module @0x1a6cf771
The solution for Maven is to expose the Java internals by creating a directory called .mvn in the root of the project containing a jvm.config file with the following content:
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED
Alternatively the --add-exports
and --add-opens
configuration may be supplied to the Maven Compiler Plugin’s arguments in the pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<compilerArgs>
<arg>--add-exports</arg>
<arg>jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
…
More information about using Error Prone with Bazel, Ant and Gradle can be found in the installation instructions.
About the Author
Johan Janssen
google / error-prone
Goto Github
PK
View Code? Open in Web Editor
NEW
171.0
716.0
113.43 MB
Catch common Java mistakes as compile-time errors
Home Page: https://errorprone.info
License: Apache License 2.0
Java 99.95%
Shell 0.02%
Mustache 0.02%
Starlark 0.01%
java
static-analysis
error-prone’s Introduction
Error Prone is a static analysis tool for Java that catches common programming
mistakes at compile-time.
public class ShortSet { public static void main (String[] args) { Set<Short> s = new HashSet<>(); for (short i = 0; i < 100; i++) { s.add(i); s.remove(i - 1); } System.out.println(s.size()); } }
error: [CollectionIncompatibleType] Argument 'i - 1' should not be passed to this method;
its type int is not compatible with its collection's type argument Short
s.remove(i - 1);
^
(see https://errorprone.info/bugpattern/CollectionIncompatibleType)
1 error
Getting Started
Our documentation is at errorprone.info.
Error Prone works with Bazel,
Maven, Ant, and
Gradle. See our installation
instructions for details.
Developing Error Prone
Developing and building Error Prone is documented on the
wiki.
Links
- Mailing lists
- General
discussion - Announcements
- General
- Javadoc
- Pre-release snapshots are available from Sonatype’s snapshot
repository.
error-prone’s People
error-prone’s Issues
GWT SafeHtml check
Original issue created by [email protected] on 2012-07-19 at 08:35 PM
GWT has an API called «SafeHtml» that has certain documented restrictions on how you’re supposed to use it, and assuming developers use it correctly they should be largely protected against XSS vulnerabilities. Using it correctly amounts to two requirements:
1. Some methods like SafeHtmlUtils.fromSafeConstant(String) are documented as requiring a «safe» string literal as the argument. Safe is defined here as a string that correctly parses as a sequence of complete HTML tags and leaves the parser in standard HTML context. (E.g., «<b>» is okay; «<a href='» and «<script>» are not.)
2. GWT has legacy methods like Element.setInnerHTML(String) that predate the introduction of SafeHtml APIs and subvert the protections offered, so they should be avoided in favor of the SafeHtml-variants.
My FindBugs works by recognizing the following expressions as safe:
1. String literals that return true for com.google.gwt.safehtml.shared.SafeHtmlHostedModeUtils.isCompleHtml(String).
2. String values returned from a call to SafeHtml.asString().
3. A concatenation of string expressions recognized as safe (e.g., «<b> + safeHtmlValue.asString() + «</b>» is still safe).
It then warns about calls to methods like SafeHtmlUtils.fromSafeConstant(String) or Element.setInnerHTML(String) that aren’t using safe arguments. Recognizing «safe» expressions this way is intentionally lenient to avoid needless code churn due to obviously safe (and incredibly common) code constructs like element.setInnerHTML(«»).
(It’s complicated somewhat further because there are some methods that have an interface like setTextOrHTML(String text, boolean isHtml), and I further only warn on these methods if I can’t statically determine the isHtml boolean argument is always false.)
Add PreconditionsTooManyArgs bug pattern
Original issue created by [email protected] on 2012-10-26 at 10:47 PM
Branch name: preconditions-toomanyargs
Purpose of code changes on this branch:
Add a new bug pattern to match (especially) cases in which the wrong Precondition formatting placeholders have been used.
When reviewing my code changes, please focus on:
I have no idea what I’m doing.
After the review, I’ll merge this branch into:
/trunk
Code review request
Original issue created by [email protected] on 2011-10-21 at 05:58 PM
If you have some time, I’ve made some more commits which are unreviewed and I’d be interested in feedback.
Like we just discussed, there are still cases where the Exception reference escapes and this code reports a false positive error.
Fallthrough suppression shouldn’t be on by default
Original issue created by [email protected] on 2012-05-24 at 04:29 PM
Tried turning on error prone in the Guava maven build.
Get lots of errors like:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project guava: Compilation failure: Compilation failure:
[ERROR] /Users/alexeagle/guava-libraries/guava/src/com/google/common/math/LongMath.java:[74,3] [FallthroughSuppression] Fallthrough warning suppression has no effect if warning is suppressed
[ERROR](see http://code.google.com/p/error-prone/wiki/FallthroughSuppression)
[ERROR] did you mean to remove this line?
Disallow lowercase l in long literals
Original issue created by [email protected] on 2012-07-16 at 05:50 PM
Representing a long literal with 5432L is far superior to 5432l for obvious reasons, and I think we should at least consider making the latter an error.
Doesn’t work on OpenJDK
Original issue created by [email protected] on 2012-01-30 at 05:19 PM
Our compile is broken against OpenJDK right now.
Additionally, the javac.util.Messages API in jdk6 has become javac.util.JavacMessages in jdk7, so we’ll need to compile correctly against either version.
Code review request
Original issue created by [email protected] on 2012-09-07 at 10:22 PM
Purpose of code changes on this branch:
Provide a way for matchers to request an arbitrary type. This is a fix for Issue 30: #30
Filler for Non-Existent Issue
Filler for non-existent Google Code issue 22.
This issue only exists to ensure that GitHub issues have the same IDs they had on Google Code. Please ignore it.
Types generation from strings.
Original issue created by [email protected] on 2012-07-27 at 11:14 AM
As far as I dug into the error-prone and javac there is no convenient way to get a Type from String. And sometimes you need to check if the result type is a subtype of/castable to java.lang.Object[] or java.util.List<Integer>, etc.
Of course for plain classes (e.g. java.lang.Object) you can make a look-up in symtab, but you can’t do the same for array types and parametrized classes. (Am I wrong here?)
I think it would be great to have such a method in error-prone library.
Something like «Type getType(String typeName)».
Code review request
Original issue created by [email protected] on 2011-10-28 at 09:26 AM
Purpose of code changes on this branch:
Checking and fixing String.format() calls in Guava Preconditions calls.
When reviewing my code changes, please focus on:
General code review — I’m a beginner to this code, so I’m probably doing things in a non-optimal way.
After the review, I’ll merge this branch into:
master
Code review request
Original issue created by [email protected] on 2012-07-26 at 09:54 PM
Please take a look at my 3 commits from today (7/26). I reworked ErrorReportingJavaCompiler to scan compilation units all at once, so that file-level nodes like imports and package declarations are scanned.
Code review request
Original issue created by [email protected] on 2012-10-20 at 12:53 AM
Please take a look at commit 6f8ddb6. I changed the ObjectEqualsSelfComparsion checker to also check for foo.equals(foo).
Consider supporting JSR 305 annotations
errorMessageTemplates in Guava Preconditions class can only accept «%s» format variables
Original issue created by [email protected] on 2012-10-24 at 06:06 PM
Several methods in the Guava Preconditions class take an errorMessageTemplate that may be customized by substituting for «%s» in the template. Often the templates actually include other format specifiers («%d», «%f», etc.), but those are not supported by the formatter.
Example:
Preconditions.checkArgument(i > 0, «i (%d) must be greater than zero», i);
should be
Preconditions.checkArgument(i > 0, «i (%s) must be greater than zero», i);
Printed error messages are sometimes incorrect
Original issue created by [email protected] on 2012-01-10 at 12:55 AM
When a fix is to delete a line, but the line is not the same one where the error was found, the error message is incorrect. For example, this code:
if (i == 10)
;
{
foo…
}
Will produce the following error message:
[Empty if] Empty statement after if; did you mean to remove this line?
if (i == 10)
^
When you intend it to delete the line with the semicolon.
I’ve added a test case in emptyifstatement/PositiveCases.java under test5().
Calling getAnnotation on an annotation type that does not have runtime retention
Original issue created by [email protected] on 2012-08-29 at 12:46 AM
The Class.getAnnotation method may be called with an annotation type that is not retained a runtime, and thus it will always return null. error-prone should detect this and issue an error.
Code review request
Original issue created by [email protected] on 2011-10-16 at 03:02 AM
Please review recent unreviewed changes, when you have a few minutes.
No particular standards yet. Thanks!
Code review request
Original issue created by [email protected] on 2011-09-27 at 10:30 PM
Branch name:
fixmultipleimports
Purpose of code changes on this branch:
Fixed two problems: (1) Matcher now checks all imports, and (2) matcher now supports fully-qualified method calls.
When reviewing my code changes, please focus on:
After the review, I’ll merge this branch into:
master
Invoking a static method from an instance
Original issue created by [email protected] on 2012-08-03 at 03:52 PM
someFoo.someStaticMethod() is a piece of awfulness that leads nowhere good. I think many teams would love to just make it an error.
Code review request
Original issue created by [email protected] on 2012-07-21 at 12:30 AM
Refactored tests to make them more consistent and to share common code via a helper class.
Code review request
Original issue created by [email protected] on 2012-08-29 at 03:39 PM
Better suggested fix and test case for the Ordering.from refactoring:
Ordering.from(new Comparator<T>() { … })
to
new Ordering<T>() { … }
There might be a nicer way of getting hold of the «…» than the way I’ve found (which is basically to re-construct the AST object and pretty-print it): hints welcome.
EmptyIf diagnostic places caret at different AST node than javac
Original issue created by [email protected] on 2012-05-30 at 05:01 PM
CheckpointCopier.java:91: [empty] empty statement after if
if(true);
^
CheckpointCopier.java:91: [EmptyIf] Empty statement after if
if(true);
^
2 errors
Code review request
Original issue created by [email protected] on 2011-09-26 at 11:56 PM
Branch name:
importfix
Purpose of code changes on this branch:
Fixed a failing test case where the Preconditions.checkNotNull() method being called was a different one from the one the check should match. Fixed this by altering the system to process import statements.
After the review, I’ll merge this branch into:
master
Filler for Non-Existent Issue
Filler for non-existent Google Code issue 21.
This issue only exists to ensure that GitHub issues have the same IDs they had on Google Code. Please ignore it.
Code review request
Original issue created by [email protected] on 2012-10-18 at 09:42 AM
Branch name: unneeded-ternary
Purpose of code changes on this branch:
Add new check for an unnecessary conditional operator
After the review, I’ll merge this branch into:
/trunk
private Fields which should not be reassigned, but cannot be marked with final keyword
Original issue created by [email protected] on 2012-07-30 at 05:15 PM
Suggested by David Mankin:
In Guice, we have @Inject fields, which should only be set by the injector when creating the class. Since they can’t be marked final, we often prefer to use constructor injection instead, even though it’s quite bulky.
Similarly in GWT, fields cannot be marked final because the serialization mechanism needs to be able to set the values in the server when populating a data object.
We should be able to enforce that such fields are never re-assigned in code within the class.
We might want an annotation for this, maybe in JSR305, or maybe JSR330 (which would be nice since other DI frameworks should take advantage). For Guice, you could imagine @Inject(finalish=true) but if we do GWT, may as well make an annotation.
Probably not practical to do this with non-private fields since we’d have to scan outside the enclosing class.
Code review request
Original issue created by [email protected] on 2011-11-04 at 02:16 PM
Purpose of code changes on this branch:
When reviewing my code changes, please focus on:
After the review, I’ll merge this branch into:
/trunk
Code review request
Original issue created by [email protected] on 2012-09-11 at 11:21 AM
Branch name: longliteral
Purpose of code changes on this branch: Add checker for long literals ending with lower case ell, e.g. 123432l rather than 123432L. See #23
After the review, I’ll merge this branch into: /master
Investigate operator precedence check
Disallow annotating a non-static method with @BeforeClass
Original issue created by [email protected] on 2012-07-16 at 07:18 PM
The JUnit @BeforeClass annotation should only be applied to a public static void no-arg method, otherwise it throws a runtime error. We should detect this at compile time.
There may also be other JUnit-specific checks we can write. For example, JUnit doesn’t run tests that are not marked public. This can cause someone to mistakenly think that their newly created tests are runnign when they’re actually not. Some other reason tests weren’t being run:
- The test class did not extend TestCase
- The test method wasn’t public
- The test method didn’t start with «test» (e.g. tesSomething)
- The test method took a parameter
Code review request
Original issue created by [email protected] on 2012-03-02 at 11:01 PM
Fixed a bug in which compiling files that contain multiple top-level classes causes NullPointerExceptions. Please take a look at revision 66f9b5b and let me know what you think.
Validate literal regular expressions
Original issue created by [email protected] on 2012-10-19 at 02:10 AM
When a string literal is passed for a parameter that is known to expect a regex (Pattern.compile, String.split, etc.), try to actually compile that regex, and fail the build if that throws an exception.
(Perhaps also when the value of some constant is passed, and that constant is set to a literal. Etc.)
AST is missing comments
Original issue created by [email protected] on 2012-01-30 at 05:20 PM
When we scan an AST, the comments are missing. This prevents us checking file contents in comments, and also means that our suggested fix/refactoring loses comments in the tree being modified.
Code review request
Original issue created by [email protected] on 2012-03-24 at 12:45 AM
Added support to SuggestedFix to add or remove imports. Please take a look and let me know what you think.
Wiki generator includes .class files in wiki pages
Original issue created by [email protected] on 2012-01-28 at 01:18 AM
The wiki generator includes .class files in the generated wiki pages. It should only include .java files.
Check that equals() and hashCode() read the same fields
Original issue created by [email protected] on 2012-08-06 at 08:48 PM
If I add a new field to a class, I can remember to update equals() but forget to update hashCode(). How would we detect this? In many cases, both methods should read all fields of a class, but that’s probably too strong a check. (For example, a List.equals() implementation might read no fields directly, preferring to operation on the public size() and get() methods.) A weaker but probably still useful check is that the two methods read the same set of fields. False positives are still possible. For example, the check would flag a field containing a cached hash code, which would likely be read in hashCode() but not equals(). This particular example is avoidable by requiring the hashCode() looks at a subset of the fields that equals() looks at. I conjecture that it’s more common for programmers to update equals() but forget to update hashCode() than vice versa, so this further weakened check would likely still catch most problems.
Check that @Override annotation is used in all appropriate places
Original issue created by [email protected] on 2012-08-28 at 09:42 PM
Check that any method that overrides another method is annotated with @Override. Perhaps this shouldn’t be an error but rather a warning.
Code review request
Original issue created by [email protected] on 2012-10-01 at 10:34 PM
I fixed a bug with the compiler in the case that we are trying to scan a compilation unit that hasn’t had all of its classes attributed yet.
Previously I had assumed that flow() would be called once on each class; that turns out not to be the case. We now track which classes error-prone has seen, and we only scan a compilation unit when we’ve seen all of its contained classes.
Code review request
Code review request
Original issue created by [email protected] on 2012-09-04 at 10:55 AM
Branch name: suppress
Purpose of code changes on this branch:
Checks for incorrectly spelled @SuppressWarnings() annotation values («deprecated» instead of «deprecation» — cleaned it up recently with several dozen instances in google3).
I’ve refactored some of the code from the FallThroughSuppression check
into an abstract superclass.
After the review, I’ll merge this branch into:
/master
Disallow non-static methods to be annotated org.junit.BeforeClass
Original issue created by [email protected] on 2012-07-16 at 06:48 PM
The BeforeClass method is called reflectively by JUnit before creating instances of the test class. So a non-static implementation causes an error.
Code review request
Original issue created by [email protected] on 2011-09-30 at 06:24 PM
Several commits to fix problems, and to move the JSR-269 dependency out of the ASTvisitor
Release 0.9 has bad tools jar dependency
Original issue created by [email protected] on 2012-05-30 at 04:31 AM
The maven release automatically resolved a variable from my local path, which isn’t valid outside of my machine.
The current 0.9 release has this in the POM:
<dependencies>
<dependency>
<groupId>openjdk</groupId>
<artifactId>tools</artifactId>
<version>1.6</version>
<scope>system</scope>
<systemPath>/usr/local/buildtools/java/jdk6-google-v4/jre/../lib/tools.jar</systemPath>
</dependency>
Check that @Override annotation is used in all appropriate places
Original issue created by [email protected] on 2012-08-28 at 09:42 PM
Check that any method that overrides another method is annotated with @Override. Perhaps this shouldn’t be an error but rather a warning.
Error messages show only the first line of a multi-line fix
Original issue created by [email protected] on 2012-06-11 at 10:28 PM
Error messages show only the first line of a multi-line fix. We need to think about how to present larger fixes, such as those for covariant equals where we make changes to the whole method.
ReturnValueIgnored checker should support javax.annotation.CheckReturnValue annotation
Original issue created by aftandilian on 2012-09-20 at 05:42 PM
Our ReturnValueIgnored checker should support the javax.annotation.CheckReturnValue annotation from JSR 305.
Support Apple-provided JDK
Original issue created by [email protected] on 2012-05-21 at 03:22 AM
Currently, the way we hook into javac has only been tested with OpenJDK 6 and 7. Not sure how many developers expect to compile with Apple’s JDK, since it is probably going to be sunset and Oracle will start maintaining the Mac version.
Code review request
Original issue created by [email protected] on 2011-11-30 at 04:40 PM
Purpose of code changes:
Added a empty-if-statements checker
When reviewing my code changes, please focus on:
Did I construct the new matchers correctly? Some of the type signatures were confusing. Everything does work.
Matchers set to severity level WARNING still produce hard errors
Original issue created by [email protected] on 2012-07-25 at 12:23 AM
JavacErrorDescriptionListener unconditionally calls log.error() regardless of the matcher’s severity level. I think it should call log.warning() if the severity level is set to WARNING.
Run checks in Eclipse
Original issue created by [email protected] on 2012-01-29 at 07:56 PM
ECJ (eclipse compiler for Java) has its own representation of the source. We need to abstract our usage of the AST and symbol table to be able to operate on this representation. Then, we need to figure out where to wire in the execution of our TreeScanners.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
Introduction
In this article, we’ll learn how to install Java artifact error_prone_annotations
from com.google.errorprone group in version 2.3.4.
The artifact is available in 53 versions:
2.18.0
2.17.0
2.16
2.15.0
2.15
2.14.0
2.13.1
2.13.0
2.12.1
2.12.0
2.11.0
2.10.0
2.9.0
2.8.1
2.8.0
2.7.1
2.7.0
2.6.0
2.5.1
2.5.0
2.4.0
2.3.4
2.3.3
2.3.2
2.3.1
2.3.0
2.2.0
2.1.3
2.1.2
2.1.1
2.1.0
2.0.21
2.0.20
2.0.19
2.0.18
2.0.17
2.0.16
2.0.15
2.0.14
2.0.13
2.0.12
2.0.11
2.0.10
2.0.9
2.0.8
2.0.7
2.0.6
2.0.5
2.0.4
2.0.3
2.0.2
2.0.1
2.0
. The error-prone annotations project has been released under Apache 2.0
license.
The parent project is: com.google.errorprone::error_prone_parent::2.3.4
How To Install Java Artifact com.google.errorprone.error_prone_annotations In Version 2.3.4
To install the error-prone annotations artifact in version 2.3.4 add the following dependency to your pom.xml file for Maven Project.
The dependency needs to be added in the dependencies section which is located in the main project tag of the pom.xml file.
The sample pom.xml file that uses error-prone annotations dependency could look as follows:
Other dependency snippets for Gradle, SBT, Ivy, Grape, Leiningen, and Buildr
Below you can find code snippets for other project build tools like Gradle, SBT, Ivy, Grape, Leiningen, and Buildr.
- Gradle
- SBT
- Ivy
- Grape
- Leiningen
- Buildr