Skip to content

Commit

Permalink
Rip out GuardedBy:CheckMemberReferences.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 497001370
  • Loading branch information
graememorgan authored and Error Prone Team committed Dec 21, 2022
1 parent 63fb30b commit b92c9b1
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import com.google.common.base.Joiner;
import com.google.errorprone.BugPattern;
import com.google.errorprone.ErrorProneFlags;
import com.google.errorprone.VisitorState;
import com.google.errorprone.bugpatterns.BugChecker;
import com.google.errorprone.bugpatterns.BugChecker.LambdaExpressionTreeMatcher;
Expand Down Expand Up @@ -61,11 +60,7 @@ public class GuardedByChecker extends BugChecker

private static final String JUC_READ_WRITE_LOCK = "java.util.concurrent.locks.ReadWriteLock";

private final GuardedByFlags flags;

public GuardedByChecker(ErrorProneFlags flags) {
this.flags = GuardedByFlags.from(flags);
}
private final GuardedByFlags flags = GuardedByFlags.allOn();

@Override
public Description matchMethod(MethodTree tree, VisitorState state) {
Expand All @@ -92,9 +87,6 @@ public Description matchLambdaExpression(LambdaExpressionTree tree, VisitorState

@Override
public Description matchMemberReference(MemberReferenceTree tree, VisitorState state) {
if (!flags.checkMemberReferences()) {
return NO_MATCH;
}
var parent = state.getPath().getParentPath().getLeaf();
if (parent instanceof MethodInvocationTree
&& INVOKES_LAMBDAS_IMMEDIATELY.matches((ExpressionTree) parent, state)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package com.google.errorprone.bugpatterns.threadsafety;

import com.google.auto.value.AutoValue;
import com.google.errorprone.ErrorProneFlags;

/**
* Flags that control the behavior of threadsafety utils to facilitate rolling out new
Expand All @@ -26,14 +25,7 @@
*/
@AutoValue
public abstract class GuardedByFlags {
public abstract boolean checkMemberReferences();

public static GuardedByFlags allOn() {
return new AutoValue_GuardedByFlags(true);
}

public static GuardedByFlags from(ErrorProneFlags flags) {
return new AutoValue_GuardedByFlags(
flags.getBoolean("GuardedBy:CheckMemberReferences").orElse(true));
return new AutoValue_GuardedByFlags();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,7 @@ public Void visitLambdaExpression(LambdaExpressionTree node, HeldLockSet heldLoc

@Override
public Void visitMemberReference(MemberReferenceTree tree, HeldLockSet locks) {
if (flags.checkMemberReferences()) {
checkMatch(tree, locks);
}
checkMatch(tree, locks);
scan(tree.getQualifierExpression(), locks);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1963,29 +1963,4 @@ public void methodReference_referencedMethodIsFlagged() {
"}")
.doTest();
}

@Test
public void methodReference_flaggedOff_methodReferencesNotFlagged() {
compilationHelper
.addSourceLines(
"Test.java",
"import java.util.ArrayList;",
"import java.util.List;",
"import java.util.Optional;",
"import java.util.function.Predicate;",
"import javax.annotation.concurrent.GuardedBy;",
"class Test {",
" private final List<Predicate<String>> preds = new ArrayList<>();",
" public synchronized void test() {",
" Optional.of(\"foo\").ifPresent(this::frobnicate);",
" preds.add(this::frobnicate);",
" }",
" @GuardedBy(\"this\")",
" public boolean frobnicate(String x) {",
" return true;",
" }",
"}")
.setArgs("-XepOpt:GuardedBy:CheckMemberReferences=false")
.doTest();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import com.google.errorprone.BugPattern;
import com.google.errorprone.CompilationTestHelper;
import com.google.errorprone.ErrorProneFlags;
import com.google.errorprone.VisitorState;
import com.google.errorprone.matchers.Description;
import com.sun.source.tree.Tree;
Expand Down Expand Up @@ -246,10 +245,6 @@ public void testLockMethodEnclosingAccess() {
/** A customized {@link GuardedByChecker} that prints more test-friendly diagnostics. */
@BugPattern(name = "GuardedByLockSet", summary = "", explanation = "", severity = ERROR)
public static class GuardedByLockSetAnalyzer extends GuardedByChecker {
public GuardedByLockSetAnalyzer(ErrorProneFlags flags) {
super(flags);
}

@Override
protected Description checkGuardedAccess(
Tree tree, GuardedByExpression guard, HeldLockSet live, VisitorState state) {
Expand Down

0 comments on commit b92c9b1

Please sign in to comment.