Skip to content

Commit

Permalink
Replace deprecated EP API buildDescriptionFromChecker with BugChecker…
Browse files Browse the repository at this point in the history
…#buildDescription (#447)

This PR replaces calls to the deprecated static `BugChecker.buildDescriptionFromChecker` method with calls to `BugChecker#buildDescription`, which was made public in google/error-prone@3ffb9ba and available in 2.4.0 and up.

This is necessary to use NullAway with Error Prone 2.5.0 and up, as google/error-prone@704e8a1 removed `BugChecker.buildDescriptionFromChecker` in favour of `BugChecker#buildDescription`. Attempting to use NullAway 0.8.0 with Error Prone 2.5.1 results in errors such as the following (preceeding stack trace from [`gradle-errorprone-plugin`](https://github.com/tbroyer/gradle-errorprone-plugin/) omitted for brevity):

```
Caused by: java.lang.NoSuchMethodError: 'com.google.errorprone.matchers.Description$Builder com.google.errorprone.BugCheckerInfo.buildDescriptionFromChecker(com.sun.source.tree.Tree, com.google.errorprone.bugpatterns.BugChecker)'
        at com.uber.nullaway.handlers.ContractHandler.reportMatch(ContractHandler.java:231)
        at com.uber.nullaway.handlers.ContractHandler.onDataflowVisitMethodInvocation(ContractHandler.java:130)
        at com.uber.nullaway.handlers.CompositeHandler.onDataflowVisitMethodInvocation(CompositeHandler.java:191)
        at com.uber.nullaway.dataflow.AccessPathNullnessPropagation.visitMethodInvocation(AccessPathNullnessPropagation.java:867)
        at com.uber.nullaway.dataflow.AccessPathNullnessPropagation.visitMethodInvocation(AccessPathNullnessPropagation.java:138)
        at shadow.checkerframework.dataflow.cfg.node.MethodInvocationNode.accept(MethodInvocationNode.java:76)
        at shadow.checkerframework.dataflow.analysis.Analysis.callTransferFunction(Analysis.java:408)
        at shadow.checkerframework.dataflow.analysis.Analysis.performAnalysisBlock(Analysis.java:234)
        at shadow.checkerframework.dataflow.analysis.Analysis.performAnalysis(Analysis.java:187)
        at com.uber.nullaway.dataflow.DataFlow$1.load(DataFlow.java:87)
        at com.uber.nullaway.dataflow.DataFlow$1.load(DataFlow.java:78)
        at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3529)
        at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2278)
        at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2155)
        at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2045)
        ... 219 more
```

This change unfortunately requires bumping the minimum required version of Error Prone up to 2.4.0, so I've also amended the README.md in light of this.
  • Loading branch information
mdcfe authored Feb 22, 2021
1 parent 875cf56 commit 5bfb130
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ NullAway is *fast*. It is built as a plugin to [Error Prone](http://errorprone.

### Overview

NullAway requires that you build your code with [Error Prone](http://errorprone.info), version 2.1.1 or higher. See the [Error Prone documentation](http://errorprone.info/docs/installation) for instructions on getting started with Error Prone and integration with your build system. The instructions below assume you are using Gradle; see [the docs](https://github.com/uber/NullAway/wiki/Configuration#other-build-systems) for discussion of other build systems.
NullAway requires that you build your code with [Error Prone](http://errorprone.info), version 2.4.0 or higher. See the [Error Prone documentation](http://errorprone.info/docs/installation) for instructions on getting started with Error Prone and integration with your build system. The instructions below assume you are using Gradle; see [the docs](https://github.com/uber/NullAway/wiki/Configuration#other-build-systems) for discussion of other build systems.

### Gradle

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

package com.uber.nullaway.handlers;

import static com.google.errorprone.BugCheckerInfo.buildDescriptionFromChecker;

import com.google.common.base.Preconditions;
import com.google.errorprone.VisitorState;
import com.google.errorprone.util.ASTHelpers;
Expand Down Expand Up @@ -154,7 +152,7 @@ protected boolean validateAnnotationSyntax(
.createErrorDescription(
new ErrorMessage(ErrorMessage.MessageTypes.ANNOTATION_VALUE_INVALID, message),
tree,
buildDescriptionFromChecker(tree, analysis),
analysis.buildDescription(tree),
state));
return false;
} else {
Expand All @@ -175,7 +173,7 @@ protected boolean validateAnnotationSyntax(
new ErrorMessage(
ErrorMessage.MessageTypes.ANNOTATION_VALUE_INVALID, message),
tree,
buildDescriptionFromChecker(tree, analysis),
analysis.buildDescription(tree),
state));
return false;
} else {
Expand All @@ -198,7 +196,7 @@ protected boolean validateAnnotationSyntax(
.createErrorDescription(
new ErrorMessage(ErrorMessage.MessageTypes.ANNOTATION_VALUE_INVALID, message),
tree,
buildDescriptionFromChecker(tree, analysis),
analysis.buildDescription(tree),
state));
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

package com.uber.nullaway.handlers.contract;

import static com.google.errorprone.BugCheckerInfo.buildDescriptionFromChecker;
import static com.uber.nullaway.NullabilityUtil.getAnnotationValue;
import static com.uber.nullaway.handlers.contract.ContractHandler.CONTRACT_ANNOTATION_NAME;
import static com.uber.nullaway.handlers.contract.ContractUtils.getAntecedent;
Expand Down Expand Up @@ -148,7 +147,7 @@ public Void visitReturn(ReturnTree returnTree, Void unused) {
new ErrorMessage(
ErrorMessage.MessageTypes.ANNOTATION_VALUE_INVALID, errorMessage),
returnTree,
buildDescriptionFromChecker(returnTree, analysis),
analysis.buildDescription(returnTree),
returnState));
}
return super.visitReturn(returnTree, unused);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

package com.uber.nullaway.handlers.contract;

import static com.google.errorprone.BugCheckerInfo.buildDescriptionFromChecker;
import static com.uber.nullaway.handlers.contract.ContractUtils.getAntecedent;
import static com.uber.nullaway.handlers.contract.ContractUtils.getConsequent;

Expand Down Expand Up @@ -159,7 +158,7 @@ public NullnessHint onDataflowVisitMethodInvocation(
new ErrorMessage(
ErrorMessage.MessageTypes.ANNOTATION_VALUE_INVALID, errorMessage),
node.getTree(),
buildDescriptionFromChecker(node.getTree(), analysis),
analysis.buildDescription(node.getTree()),
state));
supported = false;
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.uber.nullaway.handlers.contract;

import static com.google.errorprone.BugCheckerInfo.buildDescriptionFromChecker;

import com.google.common.base.Function;
import com.google.errorprone.VisitorState;
import com.sun.source.tree.Tree;
Expand Down Expand Up @@ -54,7 +52,7 @@ static String getConsequent(
.createErrorDescription(
new ErrorMessage(ErrorMessage.MessageTypes.ANNOTATION_VALUE_INVALID, message),
tree,
buildDescriptionFromChecker(tree, analysis),
analysis.buildDescription(tree),
state));
}
return parts[1].trim();
Expand Down Expand Up @@ -101,7 +99,7 @@ static String[] getAntecedent(
.createErrorDescription(
new ErrorMessage(ErrorMessage.MessageTypes.ANNOTATION_VALUE_INVALID, message),
tree,
buildDescriptionFromChecker(tree, analysis),
analysis.buildDescription(tree),
state));
}
return antecedent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

package com.uber.nullaway.handlers.contract.fieldcontract;

import static com.google.errorprone.BugCheckerInfo.buildDescriptionFromChecker;
import static com.uber.nullaway.NullabilityUtil.getAnnotationValueArray;

import com.google.common.base.Preconditions;
Expand Down Expand Up @@ -106,7 +105,7 @@ protected boolean validateAnnotationSemantics(
.createErrorDescription(
new ErrorMessage(ErrorMessage.MessageTypes.POSTCONDITION_NOT_SATISFIED, message),
tree,
buildDescriptionFromChecker(tree, analysis),
analysis.buildDescription(tree),
state));
return false;
}
Expand Down Expand Up @@ -162,7 +161,7 @@ protected void validateOverridingRules(
ErrorMessage.MessageTypes.WRONG_OVERRIDE_POSTCONDITION,
errorMessage.toString()),
tree,
buildDescriptionFromChecker(tree, analysis),
analysis.buildDescription(tree),
state));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

package com.uber.nullaway.handlers.contract.fieldcontract;

import static com.google.errorprone.BugCheckerInfo.buildDescriptionFromChecker;
import static com.uber.nullaway.NullabilityUtil.getAnnotationValueArray;

import com.google.common.base.Preconditions;
Expand Down Expand Up @@ -119,7 +118,7 @@ protected void validateOverridingRules(
new ErrorMessage(
ErrorMessage.MessageTypes.WRONG_OVERRIDE_PRECONDITION, errorMessage.toString()),
tree,
buildDescriptionFromChecker(tree, analysis),
analysis.buildDescription(tree),
state));
}

Expand Down Expand Up @@ -163,7 +162,7 @@ public void onMatchMethodInvocation(
.createErrorDescription(
new ErrorMessage(ErrorMessage.MessageTypes.PRECONDITION_NOT_SATISFIED, message),
tree,
buildDescriptionFromChecker(tree, analysis),
analysis.buildDescription(tree),
state));
}
}
Expand Down

0 comments on commit 5bfb130

Please sign in to comment.