Upgrade Errorprone (#3851)

* Upgrade Errorprone

Upgrade errorprone to 2.13.1.  Like all errorprone upgrades there are
new checks requiring code changes.

* Unused methods now cause compilation errors
* fields must be static and final
* Effectively constant booleans must now be returned as true/false.
* longs should not auto-cast to double.
* turn off errorprone javadocs

Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>

Co-authored-by: Sally MacFarlane <sally.macfarlane@consensys.net>
pull/3865/head
Danno Ferrin 2 years ago committed by GitHub
parent d88bb5867f
commit bdb00b299e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/OpenTelemetryAcceptanceTest.java
  2. 1
      besu/src/main/java/org/hyperledger/besu/cli/subcommands/PublicKeySubCommand.java
  3. 6
      config/src/main/java/org/hyperledger/besu/config/JsonGenesisConfigOptions.java
  4. 4
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftRound.java
  5. 4
      consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftRound.java
  6. 26
      errorprone-checks/build.gradle
  7. 1
      errorprone-checks/src/main/java/org/hyperledger/errorpronechecks/BannedMethod.java
  8. 1
      errorprone-checks/src/main/java/org/hyperledger/errorpronechecks/DoNotCreateSecureRandomDirectly.java
  9. 1
      errorprone-checks/src/main/java/org/hyperledger/errorpronechecks/DoNotInvokeMessageDigestDirectly.java
  10. 1
      errorprone-checks/src/main/java/org/hyperledger/errorpronechecks/DoNotReturnNullOptionals.java
  11. 1
      errorprone-checks/src/main/java/org/hyperledger/errorpronechecks/ExperimentalCliOptionMustBeCorrectlyDisplayed.java
  12. 1
      errorprone-checks/src/main/java/org/hyperledger/errorpronechecks/MethodInputParametersMustBeFinal.java
  13. 1
      errorprone-checks/src/main/java/org/hyperledger/errorpronechecks/PrivateStaticFinalLoggers.java
  14. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesTest.java
  15. 4
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java
  16. 30
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/feemarket/BaseFeeMarketBaseFeeTest.java
  17. 2
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java
  18. 5
      ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/AllowlistPersistor.java
  19. 5
      ethereum/trie/src/main/java/org/hyperledger/besu/ethereum/trie/TrieNodeDecoder.java
  20. 2
      gradle/versions.gradle
  21. 2
      metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetrySystem.java
  22. 2
      metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryTimer.java
  23. 2
      metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusCounter.java

@ -60,7 +60,7 @@ public class OpenTelemetryAcceptanceTest extends AcceptanceTestBase {
private static final class FakeCollector extends TraceServiceGrpc.TraceServiceImplBase { private static final class FakeCollector extends TraceServiceGrpc.TraceServiceImplBase {
private final List<ResourceSpans> receivedSpans = new ArrayList<>(); private final List<ResourceSpans> receivedSpans = new ArrayList<>();
private Status returnedStatus = Status.OK; private final Status returnedStatus = Status.OK;
@Override @Override
public void export( public void export(
@ -82,16 +82,12 @@ public class OpenTelemetryAcceptanceTest extends AcceptanceTestBase {
List<ResourceSpans> getReceivedSpans() { List<ResourceSpans> getReceivedSpans() {
return receivedSpans; return receivedSpans;
} }
void setReturnedStatus(final Status returnedStatus) {
this.returnedStatus = returnedStatus;
}
} }
private static final class FakeMetricsCollector private static final class FakeMetricsCollector
extends MetricsServiceGrpc.MetricsServiceImplBase { extends MetricsServiceGrpc.MetricsServiceImplBase {
private final List<ResourceMetrics> receivedMetrics = new ArrayList<>(); private final List<ResourceMetrics> receivedMetrics = new ArrayList<>();
private Status returnedStatus = Status.OK; private final Status returnedStatus = Status.OK;
@Override @Override
public void export( public void export(
@ -114,10 +110,6 @@ public class OpenTelemetryAcceptanceTest extends AcceptanceTestBase {
List<ResourceMetrics> getReceivedMetrics() { List<ResourceMetrics> getReceivedMetrics() {
return receivedMetrics; return receivedMetrics;
} }
void setReturnedStatus(final Status returnedStatus) {
this.returnedStatus = returnedStatus;
}
} }
private final FakeMetricsCollector fakeMetricsCollector = new FakeMetricsCollector(); private final FakeMetricsCollector fakeMetricsCollector = new FakeMetricsCollector();

@ -154,6 +154,7 @@ public class PublicKeySubCommand implements Runnable {
+ SignatureAlgorithmType.DEFAULT_EC_CURVE_NAME + SignatureAlgorithmType.DEFAULT_EC_CURVE_NAME
+ ")", + ")",
arity = "0..1") arity = "0..1")
@SuppressWarnings("FieldCanBeFinal")
protected String ecCurve = null; protected String ecCurve = null;
@Spec private final CommandSpec spec = null; @Spec private final CommandSpec spec = null;

@ -21,7 +21,6 @@ import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.datatypes.Wei;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
@ -80,11 +79,6 @@ public class JsonGenesisConfigOptions implements GenesisConfigOptions {
return new TransitionsConfigOptions(transitionsNode.get()); return new TransitionsConfigOptions(transitionsNode.get());
} }
private JsonGenesisConfigOptions(
final ObjectNode maybeConfig, final TransitionsConfigOptions transitionsConfig) {
this(maybeConfig, Collections.emptyMap(), transitionsConfig);
}
JsonGenesisConfigOptions( JsonGenesisConfigOptions(
final ObjectNode maybeConfig, final ObjectNode maybeConfig,
final Map<String, String> configOverrides, final Map<String, String> configOverrides,

@ -183,7 +183,7 @@ public class IbftRound {
commitSeal = createCommitSeal(block); commitSeal = createCommitSeal(block);
} catch (final SecurityModuleException e) { } catch (final SecurityModuleException e) {
LOG.warn("Failed to construct commit seal; {}", e.getMessage()); LOG.warn("Failed to construct commit seal; {}", e.getMessage());
return blockAccepted; return true;
} }
// There are times handling a proposed block is enough to enter prepared. // There are times handling a proposed block is enough to enter prepared.
@ -202,7 +202,7 @@ public class IbftRound {
roundState.addCommitMessage(localCommitMessage); roundState.addCommitMessage(localCommitMessage);
} catch (final SecurityModuleException e) { } catch (final SecurityModuleException e) {
LOG.warn("Failed to create signed Commit message; {}", e.getMessage()); LOG.warn("Failed to create signed Commit message; {}", e.getMessage());
return blockAccepted; return true;
} }
// It is possible sufficient commit seals are now available and the block should be imported // It is possible sufficient commit seals are now available and the block should be imported

@ -200,7 +200,7 @@ public class QbftRound {
commitSeal = createCommitSeal(block); commitSeal = createCommitSeal(block);
} catch (final SecurityModuleException e) { } catch (final SecurityModuleException e) {
LOG.warn("Failed to construct commit seal; {}", e.getMessage()); LOG.warn("Failed to construct commit seal; {}", e.getMessage());
return blockAccepted; return true;
} }
// There are times handling a proposed block is enough to enter prepared. // There are times handling a proposed block is enough to enter prepared.
@ -219,7 +219,7 @@ public class QbftRound {
roundState.addCommitMessage(localCommitMessage); roundState.addCommitMessage(localCommitMessage);
} catch (final SecurityModuleException e) { } catch (final SecurityModuleException e) {
LOG.warn("Failed to create signed Commit message; {}", e.getMessage()); LOG.warn("Failed to create signed Commit message; {}", e.getMessage());
return blockAccepted; return true;
} }
// It is possible sufficient commit seals are now available and the block should be imported // It is possible sufficient commit seals are now available and the block should be imported

@ -45,3 +45,29 @@ dependencies {
} }
test { testLogging { showStandardStreams = true } } test { testLogging { showStandardStreams = true } }
tasks.withType(JavaCompile) {
options.compilerArgs += [
'--add-exports',
'jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED',
'--add-exports',
'jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED',
'--add-exports',
'jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED',
'--add-exports',
'jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED',
'--add-exports',
'jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED',
'--add-exports',
'jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED',
'--add-exports',
'jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED',
'--add-exports',
'jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED'
]
}
javadoc {
enabled = false
}

@ -33,7 +33,6 @@ import com.sun.source.tree.MethodInvocationTree;
@AutoService(BugChecker.class) @AutoService(BugChecker.class)
@BugPattern( @BugPattern(
name = "BannedMethod",
summary = "Some methods should not be used, make sure that doesn't happen.", summary = "Some methods should not be used, make sure that doesn't happen.",
severity = WARNING, severity = WARNING,
linkType = BugPattern.LinkType.NONE) linkType = BugPattern.LinkType.NONE)

@ -30,7 +30,6 @@ import com.sun.tools.javac.code.Symbol;
@AutoService(BugChecker.class) @AutoService(BugChecker.class)
@BugPattern( @BugPattern(
name = "DoNotCreateSecureRandomDirectly",
summary = "Do not create SecureRandom directly.", summary = "Do not create SecureRandom directly.",
severity = WARNING, severity = WARNING,
linkType = BugPattern.LinkType.NONE) linkType = BugPattern.LinkType.NONE)

@ -26,7 +26,6 @@ import com.sun.source.tree.MethodInvocationTree;
@AutoService(BugChecker.class) @AutoService(BugChecker.class)
@BugPattern( @BugPattern(
name = "DoNotInvokeMessageDigestDirectly",
summary = "Do not invoke MessageDigest.getInstance directly.", summary = "Do not invoke MessageDigest.getInstance directly.",
severity = WARNING, severity = WARNING,
linkType = BugPattern.LinkType.NONE) linkType = BugPattern.LinkType.NONE)

@ -36,7 +36,6 @@ import com.sun.source.tree.Tree;
@AutoService(BugChecker.class) // the service descriptor @AutoService(BugChecker.class) // the service descriptor
@BugPattern( @BugPattern(
name = "DoNotReturnNullOptionals",
summary = "Do not return null optionals.", summary = "Do not return null optionals.",
severity = SUGGESTION, severity = SUGGESTION,
linkType = BugPattern.LinkType.NONE) linkType = BugPattern.LinkType.NONE)

@ -34,7 +34,6 @@ import com.sun.tools.javac.tree.JCTree;
@AutoService(BugChecker.class) @AutoService(BugChecker.class)
@BugPattern( @BugPattern(
name = "ExperimentalCliOptionMustBeCorrectlyDisplayed",
summary = "Experimental options must be hidden and not present in the BesuCommand class.", summary = "Experimental options must be hidden and not present in the BesuCommand class.",
severity = WARNING, severity = WARNING,
linkType = BugPattern.LinkType.NONE) linkType = BugPattern.LinkType.NONE)

@ -32,7 +32,6 @@ import com.sun.source.tree.VariableTree;
@AutoService(BugChecker.class) @AutoService(BugChecker.class)
@BugPattern( @BugPattern(
name = "MethodInputParametersMustBeFinal",
summary = "Method input parameters must be final.", summary = "Method input parameters must be final.",
severity = WARNING, severity = WARNING,
linkType = BugPattern.LinkType.NONE) linkType = BugPattern.LinkType.NONE)

@ -41,7 +41,6 @@ import com.sun.tools.javac.code.Type;
@AutoService(BugChecker.class) @AutoService(BugChecker.class)
@BugPattern( @BugPattern(
name = "PrivateStaticFinalLoggers",
summary = "Logger classes should be private, static, and final.", summary = "Logger classes should be private, static, and final.",
severity = WARNING, severity = WARNING,
linkType = BugPattern.LinkType.NONE) linkType = BugPattern.LinkType.NONE)

@ -569,7 +569,6 @@ public class BlockchainQueriesTest {
final List<BlockData> blockData; final List<BlockData> blockData;
final WorldStateArchive worldStateArchive; final WorldStateArchive worldStateArchive;
final BlockchainQueries blockchainQueries; final BlockchainQueries blockchainQueries;
final EthScheduler scheduler;
private BlockchainWithData( private BlockchainWithData(
final MutableBlockchain blockchain, final MutableBlockchain blockchain,
@ -579,7 +578,6 @@ public class BlockchainQueriesTest {
this.blockchain = blockchain; this.blockchain = blockchain;
this.blockData = blockData; this.blockData = blockData;
this.worldStateArchive = worldStateArchive; this.worldStateArchive = worldStateArchive;
this.scheduler = scheduler;
this.blockchainQueries = new BlockchainQueries(blockchain, worldStateArchive, scheduler); this.blockchainQueries = new BlockchainQueries(blockchain, worldStateArchive, scheduler);
} }
} }

@ -55,10 +55,6 @@ public class ProtocolScheduleBuilder {
public ProtocolSpecBuilder getBuilder() { public ProtocolSpecBuilder getBuilder() {
return builder; return builder;
} }
public Function<ProtocolSpecBuilder, ProtocolSpecBuilder> getModifier() {
return modifier;
}
} }
private static final Logger LOG = LoggerFactory.getLogger(ProtocolScheduleBuilder.class); private static final Logger LOG = LoggerFactory.getLogger(ProtocolScheduleBuilder.class);

@ -89,6 +89,7 @@ public class BaseFeeMarketBaseFeeTest {
.isEqualTo(expectedBaseFee); .isEqualTo(expectedBaseFee);
} }
@SuppressWarnings("unused")
private static class BaseFeeMarketBaseFeeTestCase { private static class BaseFeeMarketBaseFeeTestCase {
private Wei parentBaseFee; private Wei parentBaseFee;
@ -96,35 +97,6 @@ public class BaseFeeMarketBaseFeeTest {
private long parentTargetGasUsed; private long parentTargetGasUsed;
private Wei expectedBaseFee; private Wei expectedBaseFee;
public BaseFeeMarketBaseFeeTestCase() {}
public BaseFeeMarketBaseFeeTestCase(
final Wei parentBaseFee,
final long parentGasUsed,
final long parentTargetGasUsed,
final Wei expectedBaseFee) {
this.parentBaseFee = parentBaseFee;
this.parentGasUsed = parentGasUsed;
this.parentTargetGasUsed = parentTargetGasUsed;
this.expectedBaseFee = expectedBaseFee;
}
public Wei getParentBaseFee() {
return parentBaseFee;
}
public long getParentGasUsed() {
return parentGasUsed;
}
public long getParentTargetGasUsed() {
return parentTargetGasUsed;
}
public Wei getExpectedBaseFee() {
return expectedBaseFee;
}
public void setParentBaseFee(final Wei parentBaseFee) { public void setParentBaseFee(final Wei parentBaseFee) {
this.parentBaseFee = parentBaseFee; this.parentBaseFee = parentBaseFee;
} }

@ -164,7 +164,7 @@ public class DetermineCommonAncestorTaskTest {
final long range = maximumPossibleCommonAncestorNumber - minimumPossibleCommonAncestorNumber; final long range = maximumPossibleCommonAncestorNumber - minimumPossibleCommonAncestorNumber;
final int skipInterval = final int skipInterval =
DetermineCommonAncestorTask.calculateSkipInterval(range, headerRequestSize); DetermineCommonAncestorTask.calculateSkipInterval(range, headerRequestSize);
final int count = DetermineCommonAncestorTask.calculateCount(range, skipInterval); final int count = DetermineCommonAncestorTask.calculateCount((double) range, skipInterval);
assertThat(count).isEqualTo(11); assertThat(count).isEqualTo(11);
assertThat(skipInterval).isEqualTo(9); assertThat(skipInterval).isEqualTo(9);

@ -73,8 +73,7 @@ public class AllowlistPersistor {
? configItems.get(allowlistType) ? configItems.get(allowlistType)
: Collections.emptyList(); : Collections.emptyList();
boolean listsMatch = existingValues.containsAll(checkLists); if (!existingValues.containsAll(checkLists)) {
if (!listsMatch) {
debugLambda( debugLambda(
LOG, LOG,
"\n LISTS DO NOT MATCH configFile::", "\n LISTS DO NOT MATCH configFile::",
@ -83,7 +82,7 @@ public class AllowlistPersistor {
debugLambda(LOG, "\nLISTS DO NOT MATCH in-memory ::", checkLists::toString); debugLambda(LOG, "\nLISTS DO NOT MATCH in-memory ::", checkLists::toString);
throw new AllowlistFileSyncException(); throw new AllowlistFileSyncException();
} }
return listsMatch; return true;
} }
public boolean verifyConfigFileMatchesState( public boolean verifyConfigFileMatchesState(

@ -126,11 +126,6 @@ public class TrieNodeDecoder {
.ifPresent(currentNodes::add); .ifPresent(currentNodes::add);
} }
public static BreadthFirstIterator create(
final NodeLoader nodeLoader, final Bytes32 rootHash, final int maxDepth) {
return new BreadthFirstIterator(nodeLoader, rootHash, maxDepth);
}
@Override @Override
public boolean hasNext() { public boolean hasNext() {
return !currentNodes.isEmpty() && currentDepth <= maxDepth; return !currentNodes.isEmpty() && currentDepth <= maxDepth;

@ -32,7 +32,7 @@ dependencyManagement {
entry'dagger' entry'dagger'
} }
dependencySet(group: 'com.google.errorprone', version: '2.10.0') { dependencySet(group: 'com.google.errorprone', version: '2.13.1') {
entry 'error_prone_annotation' entry 'error_prone_annotation'
entry 'error_prone_check_api' entry 'error_prone_check_api'
entry 'error_prone_core' entry 'error_prone_core'

@ -277,7 +277,7 @@ public class OpenTelemetrySystem implements ObservableMetricsSystem {
resultLongObserver -> { resultLongObserver -> {
for (int i = 0; i < garbageCollectors.size(); i++) { for (int i = 0; i < garbageCollectors.size(); i++) {
resultLongObserver.observe( resultLongObserver.observe(
garbageCollectors.get(i).getCollectionTime(), labelSets.get(i)); (double) garbageCollectors.get(i).getCollectionTime(), labelSets.get(i));
} }
}); });
final AttributeKey<String> typeKey = AttributeKey.stringKey(TYPE_LABEL_KEY); final AttributeKey<String> typeKey = AttributeKey.stringKey(TYPE_LABEL_KEY);

@ -51,7 +51,7 @@ public class OpenTelemetryTimer implements LabelledMetric<OperationTimer> {
meter meter
.gaugeBuilder(metricName) .gaugeBuilder(metricName)
.setDescription(help) .setDescription(help)
.buildWithCallback((measurement) -> measurement.observe(elapsed, labels)); .buildWithCallback((measurement) -> measurement.observe((double) elapsed, labels));
return elapsed / 1e9; return elapsed / 1e9;
}; };
}; };

@ -44,7 +44,7 @@ class PrometheusCounter implements LabelledMetric<Counter> {
@Override @Override
public void inc(final long amount) { public void inc(final long amount) {
counter.inc(amount); counter.inc((double) amount);
} }
} }
} }

Loading…
Cancel
Save