Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: google/error-prone
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.13.0
Choose a base ref
...
head repository: google/error-prone
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.13.1
Choose a head ref
  • 6 commits
  • 18 files changed
  • 3 contributors

Commits on Apr 14, 2022

  1. Fix handling of foo.new A() {}.

    This is awful.
    
    PiperOrigin-RevId: 441825465
    graememorgan authored and Error Prone Team committed Apr 14, 2022
    Copy the full SHA
    2d20166 View commit details
  2. Hardcode AlwaysThrows:MatchUuidParse.

    PiperOrigin-RevId: 441882375
    graememorgan authored and Error Prone Team committed Apr 14, 2022
    Copy the full SHA
    cb15103 View commit details

Commits on Apr 15, 2022

  1. Update release.yml

    cushon authored Apr 15, 2022
    Copy the full SHA
    460d6c2 View commit details
  2. Fix a crash in UnnecessaryBoxedVariable

    Don't assume that return statements are enclosed by a method with a return
    type, to handle statement lambdas inside constructors.
    
    Fixes #3115
    
    PiperOrigin-RevId: 442056569
    cushon authored and Error Prone Team committed Apr 15, 2022
    Copy the full SHA
    ed35fda View commit details
  3. Include the unicode character in the diagnostic message

    To help debug #3092
    
    PiperOrigin-RevId: 442071506
    cushon authored and Error Prone Team committed Apr 15, 2022
    Copy the full SHA
    726d179 View commit details
  4. Release Error Prone 2.13.1

    cushon committed Apr 15, 2022
    Copy the full SHA
    2076780 View commit details
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -61,6 +61,7 @@ jobs:
uses: softprops/action-gh-release@v0.1.14
with:
draft: true
name: ${{ github.event.input.version }}
name: Error Prone ${{ github.event.input.version }}
generate_release_notes: true
tag_name: "v${{ github.event.inputs.version }}"
target_commitish: ${{ env.TARGET_COMMITISH }}
2 changes: 1 addition & 1 deletion annotation/pom.xml
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
<parent>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_parent</artifactId>
<version>HEAD-SNAPSHOT</version>
<version>2.13.1</version>
</parent>

<name>@BugPattern annotation</name>
2 changes: 1 addition & 1 deletion annotations/pom.xml
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
<parent>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_parent</artifactId>
<version>HEAD-SNAPSHOT</version>
<version>2.13.1</version>
</parent>

<name>error-prone annotations</name>
2 changes: 1 addition & 1 deletion check_api/pom.xml
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
<parent>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_parent</artifactId>
<version>HEAD-SNAPSHOT</version>
<version>2.13.1</version>
</parent>

<name>error-prone check api</name>
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
<parent>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_parent</artifactId>
<version>HEAD-SNAPSHOT</version>
<version>2.13.1</version>
</parent>

<name>error-prone library</name>
Original file line number Diff line number Diff line change
@@ -134,11 +134,9 @@ void validate(MethodInvocationTree tree, String argument) {
}

private final ConstantExpressions constantExpressions;
private final boolean matchUuidParse;

public AlwaysThrows(ErrorProneFlags flags) {
this.constantExpressions = ConstantExpressions.fromFlags(flags);
this.matchUuidParse = flags.getBoolean("AlwaysThrows:MatchUuidParse").orElse(true);
}

@Override
@@ -170,11 +168,7 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState
}
}
Api api =
stream(Api.values())
.filter(a -> matchUuidParse || !a.equals(Api.UUID_PARSE))
.filter(m -> m.matcher.matches(tree, state))
.findAny()
.orElse(null);
stream(Api.values()).filter(m -> m.matcher.matches(tree, state)).findAny().orElse(null);
if (api == null) {
return NO_MATCH;
}
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@
import static com.google.errorprone.BugPattern.SeverityLevel.ERROR;
import static com.google.errorprone.matchers.Description.NO_MATCH;
import static com.google.errorprone.util.ErrorProneTokens.getTokens;
import static java.lang.String.format;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableRangeSet;
@@ -31,10 +32,11 @@
import com.google.errorprone.fixes.FixedPosition;
import com.google.errorprone.matchers.Description;
import com.google.errorprone.util.ErrorProneToken;
import com.google.errorprone.util.SourceCodeEscapers;
import com.sun.source.tree.CompilationUnitTree;
import com.sun.tools.javac.parser.Tokens.TokenKind;
import java.util.ArrayList;
import java.util.List;
import java.util.LinkedHashMap;
import java.util.Map;

/** Bans using non-ASCII Unicode characters outside string literals and comments. */
@BugPattern(
@@ -47,27 +49,36 @@ public final class UnicodeInCode extends BugChecker implements CompilationUnitTr
public Description matchCompilationUnit(CompilationUnitTree tree, VisitorState state) {
ImmutableRangeSet<Integer> commentsAndLiterals = commentsAndLiterals(state);

List<Integer> violatingLocations = new ArrayList<>();
Map<Integer, Character> violations = new LinkedHashMap<>();

CharSequence sourceCode = state.getSourceCode();

for (int i = 0; i < sourceCode.length(); ++i) {
char c = sourceCode.charAt(i);

if (!isAcceptableAscii(c) && !commentsAndLiterals.contains(i)) {
violatingLocations.add(i);
violations.put(i, c);
}
}

if (violatingLocations.isEmpty()) {
if (violations.isEmpty()) {
return NO_MATCH;
}

ImmutableRangeSet<Integer> suppressedRegions = suppressedRegions(state);

for (Integer violatingLocation : violatingLocations) {
for (var e : violations.entrySet()) {
int violatingLocation = e.getKey();
char c = e.getValue();
if (!suppressedRegions.contains(violatingLocation)) {
state.reportMatch(describeMatch(new FixedPosition(tree, violatingLocation)));
state.reportMatch(
buildDescription(new FixedPosition(tree, violatingLocation))
.setMessage(
format(
"Avoid using non-ASCII Unicode character (%s) outside of comments and"
+ " literals, as they can be confusing.",
SourceCodeEscapers.javaCharEscaper().escape(Character.toString(c))))
.build());
}
}
return NO_MATCH;
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
import static com.google.errorprone.util.ASTHelpers.getGeneratedBy;
import static com.google.errorprone.util.ASTHelpers.getSymbol;
import static com.google.errorprone.util.ASTHelpers.getType;
import static com.google.errorprone.util.ASTHelpers.isGeneratedConstructor;
import static com.google.errorprone.util.FindIdentifiers.findIdent;
import static com.sun.tools.javac.code.Kinds.KindSelector.VAL_TYP;
import static java.util.stream.Collectors.toCollection;
@@ -37,10 +38,12 @@
import com.google.errorprone.fixes.SuggestedFix;
import com.google.errorprone.matchers.Description;
import com.google.errorprone.util.ASTHelpers;
import com.sun.source.tree.ClassTree;
import com.sun.source.tree.CompilationUnitTree;
import com.sun.source.tree.IdentifierTree;
import com.sun.source.tree.ImportTree;
import com.sun.source.tree.MemberSelectTree;
import com.sun.source.tree.MethodTree;
import com.sun.source.tree.Tree;
import com.sun.source.util.SimpleTreeVisitor;
import com.sun.source.util.TreePath;
@@ -86,6 +89,25 @@ public Void visitImport(ImportTree importTree, Void unused) {
return null;
}

@Override
public Void visitClass(ClassTree tree, Void unused) {
scan(tree.getModifiers(), null);
scan(tree.getTypeParameters(), null);
// Some anonymous classes have an extends clause which is fully qualified. Just ignore it.
if (!getSymbol(tree).isAnonymous()) {
scan(tree.getExtendsClause(), null);
scan(tree.getImplementsClause(), null);
}
scan(tree.getMembers(), null);
return null;
}

@Override
public Void visitMethod(MethodTree tree, Void unused) {
// Some generated constructors sneak in a fully qualified argument.
return isGeneratedConstructor(tree) ? null : super.visitMethod(tree, null);
}

@Override
public Void visitMemberSelect(MemberSelectTree memberSelectTree, Void unused) {
if (!shouldIgnore()) {
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@
import static com.google.errorprone.matchers.Matchers.anyOf;
import static com.google.errorprone.matchers.method.MethodMatchers.instanceMethod;
import static com.google.errorprone.matchers.method.MethodMatchers.staticMethod;
import static com.google.errorprone.util.ASTHelpers.findEnclosingMethod;
import static com.google.errorprone.util.ASTHelpers.getSymbol;

import com.google.common.collect.ArrayListMultimap;
@@ -429,11 +430,12 @@ public Void visitReturn(ReturnTree node, Void unused) {
// Don't count a return value as a boxed usage, except if we are returning a parameter, and
// the method's return type is boxed.
if (nodeSymbol.getKind() == ElementKind.PARAMETER) {
MethodTree enclosingMethod =
ASTHelpers.findEnclosingNode(getCurrentPath(), MethodTree.class);
Type returnType = ASTHelpers.getType(enclosingMethod.getReturnType());
if (!returnType.isPrimitive()) {
boxedUsageFound.add((VarSymbol) nodeSymbol);
MethodTree enclosingMethod = findEnclosingMethod(state.withPath(getCurrentPath()));
if (enclosingMethod != null) {
Type returnType = ASTHelpers.getType(enclosingMethod.getReturnType());
if (!returnType.isPrimitive()) {
boxedUsageFound.add((VarSymbol) nodeSymbol);
}
}
}
return null;
Original file line number Diff line number Diff line change
@@ -78,7 +78,7 @@ public void positive() {
.addSourceLines(
"Test.java", //
"class Test {",
" // BUG: Diagnostic contains:",
" // BUG: Diagnostic contains: Unicode character (\\u03c0)",
" static final double \u03C0 = 3;",
"}")
.doTest();
Original file line number Diff line number Diff line change
@@ -195,6 +195,22 @@ public void exemptedNames() {
.doTest();
}

@Test
public void innerClass() {
helper
.addInputLines(
"A.java", //
"package test;",
"public class A {",
" class B {}",
" void test (A a) {",
" a.new B() {};",
" }",
"}")
.expectUnchanged()
.doTest();
}

@Test
public void packageInfo() {
CompilationTestHelper.newInstance(UnnecessarilyFullyQualified.class, getClass())
Original file line number Diff line number Diff line change
@@ -69,4 +69,22 @@ public void lambdas() {
"}")
.doTest();
}

@Test
public void lambdaReturn() {
compilationTestHelper
.addSourceLines(
"Test.java",
"class Test {",
" interface F {",
" int f(Integer i);",
" }",
" Test() {",
" F f = (Integer i) -> {",
" return i;",
" };",
" }",
"}")
.doTest();
}
}
2 changes: 1 addition & 1 deletion docgen/pom.xml
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
<parent>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_parent</artifactId>
<version>HEAD-SNAPSHOT</version>
<version>2.13.1</version>
</parent>

<name>Documentation tool for generating Error Prone bugpattern documentation</name>
2 changes: 1 addition & 1 deletion docgen_processor/pom.xml
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
<parent>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_parent</artifactId>
<version>HEAD-SNAPSHOT</version>
<version>2.13.1</version>
</parent>

<name>JSR-269 annotation processor for @BugPattern annotation</name>
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
<name>Error Prone parent POM</name>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_parent</artifactId>
<version>HEAD-SNAPSHOT</version>
<version>2.13.1</version>
<packaging>pom</packaging>

<description>Error Prone is a static analysis tool for Java that catches common programming mistakes at compile-time.</description>
2 changes: 1 addition & 1 deletion refaster/pom.xml
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@
<parent>
<artifactId>error_prone_parent</artifactId>
<groupId>com.google.errorprone</groupId>
<version>HEAD-SNAPSHOT</version>
<version>2.13.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

2 changes: 1 addition & 1 deletion test_helpers/pom.xml
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
<parent>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_parent</artifactId>
<version>HEAD-SNAPSHOT</version>
<version>2.13.1</version>
</parent>

<name>error-prone test helpers</name>
2 changes: 1 addition & 1 deletion type_annotations/pom.xml
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
<parent>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_parent</artifactId>
<version>HEAD-SNAPSHOT</version>
<version>2.13.1</version>
</parent>

<name>error-prone type annotations</name>