Error Prone is a new Java compiler plugin created by Google which checks your code for common errors at compile-time. Not does only Error Prone identify issues but suggests their fixes too by analyzing the code’s abstract syntax tree (AST).
An example from the official documentation will make its use clear :
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;
This incompatibility is an example of a bug pattern that Error Prone is looking for. It comes with many default such patterns, for instance :
AlwaysThrows Detects calls that will fail at runtime
ArrayFillIncompatibleType Arrays. fill(Object[], Object) called with incompatible types.
ComparingThisWithNull this == null is always false, this != null is always true
FormatString Invalid printf-style format string
Immutable Type declaration annotated with @Immutable is not immutable
The treats do not stop here though. You can also create your own Bug patterns although not a straightforward endeavor since you need to use Error Prone's api and interact with the code's AST.
Recognizing the difficulty, Google released another tool that ships with Error Prone called Refaster. Refaster is a tool that refactors your code using before-and-after templates. Once you write these templates, you compile them into .refaster files, then use the Error Prone compiler to refactor your code according to those rules. Refaster then scans for code that matches the before-template which replaces with the code found in the after-template.
An example
public class StringIsEmpty { @BeforeTemplate boolean equalsEmptyString(String string) { return string.equals(""); }
JetBrains has released its annual analysis of the developer ecosystem, and this year's results show the ever-increasing hold of AI along with a rise in the importance of virtual reality.
Microsoft has announced version 8.4 of the .NET Community Toolkit, a collection of helpers and APIs that work for all .NET developers. The new version adds support for partial properties for the MVVM [ ... ]