Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,12 @@ private boolean isTypeValid(Type instanceOfTarget, VisitorState state) {

@Nullable
private static String unwrapBlock(StatementTree statement, VisitorState state) {
if (statement.getKind() == Tree.Kind.BLOCK) {
if (statement instanceof BlockTree blockStatement) {
CharSequence source = state.getSourceCode();
if (source == null) {
return null;
}
BlockTree blockStatement = (BlockTree) statement;

List<? extends StatementTree> statements = blockStatement.getStatements();
if (statements.isEmpty()) {
return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import com.sun.source.tree.ClassTree;
import com.sun.source.tree.MethodTree;
import com.sun.source.tree.Tree;
import com.sun.source.tree.Tree.Kind;
import com.sun.source.tree.VariableTree;
import com.sun.tools.javac.code.Symbol.ClassSymbol;
import com.sun.tools.javac.code.Symbol.MethodSymbol;
import com.sun.tools.javac.tree.JCTree;
Expand Down Expand Up @@ -72,7 +72,7 @@ public Description matchClass(ClassTree tree, VisitorState state) {
+ 1;

for (Tree member : tree.getMembers()) {
if (member.getKind() == Kind.VARIABLE) {
if (member instanceof VariableTree) {
int endPosition = state.getEndPosition(member);
if (endPosition > constructorPosition) {
constructorPosition = endPosition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
import com.google.errorprone.matchers.method.MethodMatchers;
import com.google.errorprone.util.ASTHelpers;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.IdentifierTree;
import com.sun.source.tree.MemberSelectTree;
import com.sun.source.tree.MethodInvocationTree;
import com.sun.source.tree.Tree;
import com.sun.source.tree.VariableTree;
import com.sun.tools.javac.code.Symbol;

Expand Down Expand Up @@ -72,7 +72,7 @@ public Description matchVariable(VariableTree tree, VisitorState state) {
return Description.NO_MATCH;
}
if (!memberSelectTree.getIdentifier().contentEquals("class")
|| memberSelectTree.getExpression().getKind() != Tree.Kind.IDENTIFIER) {
|| !(memberSelectTree.getExpression() instanceof IdentifierTree)) {
return Description.NO_MATCH;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState
}
ExpressionTree functionParameter =
ASTHelpers.stripParentheses(tree.getArguments().get(0));
if (functionParameter.getKind() != Tree.Kind.LAMBDA_EXPRESSION) {
if (!(functionParameter instanceof LambdaExpressionTree lambdaExpressionTree)) {
return Description.NO_MATCH;
}
LambdaExpressionTree lambdaExpressionTree = (LambdaExpressionTree) functionParameter;

Optional<ExpressionTree> maybeExpression = finalExpression(lambdaExpressionTree);
if (!maybeExpression.isPresent()) {
return Description.NO_MATCH;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import com.sun.source.tree.LiteralTree;
import com.sun.source.tree.MemberSelectTree;
import com.sun.source.tree.MethodInvocationTree;
import com.sun.source.tree.Tree;

@AutoService(BugChecker.class)
@BugPattern(
Expand All @@ -55,11 +54,10 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState

ExpressionTree orElseGetArg = tree.getArguments().get(0);

if (orElseGetArg.getKind() != Tree.Kind.LAMBDA_EXPRESSION) {
if (!(orElseGetArg instanceof LambdaExpressionTree lambdaExpressionTree)) {
return Description.NO_MATCH;
}

LambdaExpressionTree lambdaExpressionTree = (LambdaExpressionTree) orElseGetArg;
LambdaExpressionTree.BodyKind bodyKind = lambdaExpressionTree.getBodyKind();

if (bodyKind != LambdaExpressionTree.BodyKind.EXPRESSION) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ private Description testType(Tree type, VisitorState state) {
+ "where necessary, such as when interacting with older library code.")
.build();
}
if (type.getKind() == Tree.Kind.PARAMETERIZED_TYPE) {
return testTypes(((ParameterizedTypeTree) type).getTypeArguments(), state);
if (type instanceof ParameterizedTypeTree parameterizedTypeTree) {
return testTypes(parameterizedTypeTree.getTypeArguments(), state);
}
return Description.NO_MATCH;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,11 @@ private static ImmutableList<SuggestedFix> buildUnusedVarFixes(
SuggestedFix.Builder fix = SuggestedFix.builder().setShortDescription("remove unused variable");
for (TreePath usagePath : usagePaths) {
StatementTree statement = (StatementTree) usagePath.getLeaf();
if (statement.getKind() == Tree.Kind.VARIABLE) {
if (statement instanceof VariableTree variableTree) {
if (getSymbol(statement).getKind() == ElementKind.PARAMETER) {
continue;
}
VariableTree variableTree = (VariableTree) statement;

ExpressionTree initializer = variableTree.getInitializer();
if (hasSideEffect(initializer) && TOP_LEVEL_EXPRESSIONS.contains(initializer.getKind())) {
if (varKind == ElementKind.FIELD) {
Expand All @@ -491,8 +491,8 @@ private static ImmutableList<SuggestedFix> buildUnusedVarFixes(
fix.merge(SuggestedFixes.replaceIncludingComments(usagePath, replacement, state));
}
continue;
} else if (statement.getKind() == Tree.Kind.EXPRESSION_STATEMENT) {
JCTree tree = (JCTree) ((ExpressionStatementTree) statement).getExpression();
} else if (statement instanceof ExpressionStatementTree expressionStatementTree) {
JCTree tree = (JCTree) expressionStatementTree.getExpression();

if (tree instanceof CompoundAssignmentTree compoundAssignmentTree) {
if (hasSideEffect(compoundAssignmentTree.getExpression())) {
Expand Down Expand Up @@ -832,7 +832,7 @@ private FilterUsedVariables(Map<Symbol, TreePath> unusedElements, ListMultimap<S

private boolean isInExpressionStatementTree() {
Tree parent = getCurrentPath().getParentPath().getLeaf();
return parent != null && parent.getKind() == Tree.Kind.EXPRESSION_STATEMENT;
return parent != null && parent instanceof ExpressionStatementTree;
}

private boolean isUsed(@Nullable Symbol symbol) {
Expand Down Expand Up @@ -914,7 +914,7 @@ private void handleReassignment(AssignmentTree tree) {
if (!(parent instanceof StatementTree)) {
return;
}
if (tree.getVariable().getKind() != Tree.Kind.IDENTIFIER) {
if (!(tree.getVariable() instanceof IdentifierTree)) {
return;
}
if (ASTHelpers.findEnclosingNode(getCurrentPath(), ForLoopTree.class) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public Description matchMethod(MethodTree tree, VisitorState state) {
return Description.NO_MATCH;
}
Types types = state.getTypes();
if (ASTHelpers.findSuperMethod(ASTHelpers.getSymbol(tree), types).isPresent()) {
if (!ASTHelpers.findSuperMethods(ASTHelpers.getSymbol(tree), types).isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this flip?

Copy link
Contributor Author

@CRogers CRogers Jul 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

findSuperMethod got deleted, we have to use findSuperMethods that returns a Set instead of a single value from the set. So checking the set is non-empty should be the same as the old logic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah - didn't see the change of the "s"

return Description.NO_MATCH;
}
ExpressionTree throwsExpression = Iterables.getOnlyElement(throwsExpressions);
Expand Down
19 changes: 19 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,25 @@ allprojects {
}
}

pluginManager.withPlugin('net.ltgt.errorprone') {
dependencies {
// This forces all errorprone configurations to use the same versions of dependencies used in the baseline-error-prone
// repo at the time the baseline-error-prone was published (notably, the same version of error-prone itself). This
// only works as GCV includes all the constraints from the `versions.props` in the `<dependencyManagement>` section
// of the pom (like a bom would). We need this as when there are error-prone breaks, if the version of
// error-prone is forced to be the same between the error-prone running this build and the error-prone being
// used for compilation, we can't move past the breaks as our baseline-error-prones in this build are broken by
// the new version of error-prone. So we force error-prone in this build back to the version that
// baseline-error-prone expects while still using the new error-prone for compilation.
// This trick could conceivable be used for suppressible-error-prone consumers in the gradle-suppressible-error-prone
// plugin, but this would stop the version of error_prone_core etc lining up with error_prone_annotation(s) that
// is being used by dependencies, which is less than ideal.
// If baseline-error-prone was ever moved out of the gradle-baseline repo, this would not be needed in
// gradle-baseline anymore.
errorprone enforcedPlatform('com.palantir.baseline:baseline-error-prone')
}
}

apply plugin: 'com.palantir.java-format'
apply plugin: 'com.palantir.jakarta-package-alignment'

Expand Down
11 changes: 11 additions & 0 deletions changelog/@unreleased/pr-3165.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type: fix
fix:
description: |-
Upgrade error-prone to 2.40.0 and stop errors of the form when error-prone >2.39.0 is used:

```
java.lang.NoSuchMethodError: 'java.util.Optional com.google.errorprone.util.ASTHelpers.findSuperMethod(com.sun.tools.javac.code.Symbol$MethodSymbol, com.sun.tools.javac.code.Types)'
at com.palantir.baseline.errorprone.ThrowSpecificity.matchMethod(ThrowSpecificity.java:68)
```
links:
- https://github.com/palantir/gradle-baseline/pull/3165
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,17 @@ public abstract class BaselineErrorProneExtension {
// Built-in checks
"ArrayEquals",
"BadImport",
"BooleanLiteral",
"LongDoubleConversion",
"LoopOverCharArray",
"MissingBraces",
"MissingOverride",
"NarrowCalculation",
"ObjectsHashCodePrimitive",
"PreferInstanceofOverGetKind",
"ProtectedMembersInFinalClass",
"PatternMatchingInstanceof",
"UnnecessaryQualifier",
"UnnecessaryParentheses",
"ZoneIdOfZ");

Expand Down
14 changes: 7 additions & 7 deletions versions.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ com.google.auto.service:auto-service:1.1.1 (1 constraints: 0505f435)
com.google.auto.service:auto-service-annotations:1.1.1 (2 constraints: 8a20341c)
com.google.auto.value:auto-value-annotations:1.10.4 (3 constraints: ac2df2f5)
com.google.code.findbugs:jsr305:3.0.2 (2 constraints: 9e14e59e)
com.google.errorprone:error_prone_annotation:2.38.0 (3 constraints: d338ebf0)
com.google.errorprone:error_prone_annotations:2.38.0 (13 constraints: 8bcd885a)
com.google.errorprone:error_prone_check_api:2.38.0 (2 constraints: bc255f00)
com.google.errorprone:error_prone_core:2.38.0 (1 constraints: 3f054f3b)
com.google.googlejavaformat:google-java-format:1.24.0 (2 constraints: b025d4fe)
com.google.errorprone:error_prone_annotation:2.40.0 (3 constraints: be384fec)
com.google.errorprone:error_prone_annotations:2.40.0 (13 constraints: 76cd2d36)
com.google.errorprone:error_prone_check_api:2.40.0 (2 constraints: ae25a0fe)
com.google.errorprone:error_prone_core:2.40.0 (1 constraints: 38053b3b)
com.google.googlejavaformat:google-java-format:1.27.0 (2 constraints: b6258eff)
com.google.guava:failureaccess:1.0.3 (2 constraints: f3154f13)
com.google.guava:guava:33.4.8-jre (21 constraints: 5d88e8f1)
com.google.guava:guava:33.4.8-jre (21 constraints: 5188b0c9)
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava (1 constraints: bd17c918)
com.google.inject:guice:5.1.0 (1 constraints: e20b61f3)
com.google.j2objc:j2objc-annotations:3.0.0 (1 constraints: 150aeab4)
Expand Down Expand Up @@ -103,7 +103,7 @@ com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.19.1 (1 constraints: ea13
com.fasterxml.jackson.module:jackson-module-afterburner:2.19.1 (1 constraints: 3f054b3b)
com.github.stefanbirkner:system-rules:1.19.0 (1 constraints: 3d05443b)
com.google.auto.value:auto-value:1.10 (1 constraints: e711f8e8)
com.google.errorprone:error_prone_test_helpers:2.38.0 (1 constraints: 3f054f3b)
com.google.errorprone:error_prone_test_helpers:2.40.0 (1 constraints: 38053b3b)
com.google.jimfs:jimfs:1.3.0 (1 constraints: 5a141061)
com.google.testing.compile:compile-testing:0.21.0 (1 constraints: 89149575)
com.google.truth:truth:1.4.0 (2 constraints: 72265a6a)
Expand Down
2 changes: 1 addition & 1 deletion versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ org.slf4j:* = 2.0.17
org.immutables:* = 2.11.0
org.ow2.asm:asm = 9.8
com.google.code.findbugs:jsr305 = 3.0.2
com.google.errorprone:error_prone_* = 2.38.0
com.google.errorprone:error_prone_* = 2.40.0
com.googlecode.java-diff-utils:diffutils = 1.3.0
com.puppycrawl.tools:checkstyle = 10.26.1
com.palantir.gradle.utils:* = 0.15.0
Expand Down