diff --git a/build.gradle b/build.gradle index 39d7a3bf7d6..cf37263fd83 100644 --- a/build.gradle +++ b/build.gradle @@ -259,6 +259,7 @@ allprojects { check('InterfaceWithOnlyStatics', net.ltgt.gradle.errorprone.CheckSeverity.WARN) check('MethodInputParametersMustBeFinal', net.ltgt.gradle.errorprone.CheckSeverity.WARN) check('MissingBraces', net.ltgt.gradle.errorprone.CheckSeverity.WARN) + check('NonFinalStaticField', net.ltgt.gradle.errorprone.CheckSeverity.WARN) check('PackageLocation', net.ltgt.gradle.errorprone.CheckSeverity.WARN) check('RedundantOverride', net.ltgt.gradle.errorprone.CheckSeverity.WARN) check('RedundantThrows', net.ltgt.gradle.errorprone.CheckSeverity.WARN) diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/block/AbstractBlockProcessor.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/block/AbstractBlockProcessor.java index 89f38f02d82..587db7557c3 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/block/AbstractBlockProcessor.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/block/AbstractBlockProcessor.java @@ -91,6 +91,7 @@ public abstract class AbstractBlockProcessor implements BlockProcessor { * Setting to false significantly speeds up state initialization */ @VisibleForTesting + @SuppressWarnings("NonFinalStaticField") public static BLSSignatureVerifier depositSignatureVerifier = DEFAULT_DEPOSIT_SIGNATURE_VERIFIER; private static final Logger LOG = LogManager.getLogger(); diff --git a/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/BLS.java b/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/BLS.java index a9abbd0cefb..94e6b32cfbc 100644 --- a/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/BLS.java +++ b/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/BLS.java @@ -41,6 +41,7 @@ public class BLS { private static final Logger LOG = LogManager.getLogger(); + @SuppressWarnings("NonFinalStaticField") private static BLS12381 blsImpl; static { diff --git a/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/BLSConstants.java b/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/BLSConstants.java index 352825f5e00..6bcce332e43 100644 --- a/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/BLSConstants.java +++ b/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/BLSConstants.java @@ -27,6 +27,7 @@ public class BLSConstants { static final BigInteger CURVE_ORDER_BI = CURVE_ORDER_BYTES.toUnsignedBigInteger(ByteOrder.BIG_ENDIAN); + @SuppressWarnings("NonFinalStaticField") public static boolean verificationDisabled = false; public static void disableBLSVerification() { diff --git a/infrastructure/io/src/main/java/tech/pegasys/teku/infrastructure/io/JemallocDetector.java b/infrastructure/io/src/main/java/tech/pegasys/teku/infrastructure/io/JemallocDetector.java index ab364a0f618..51646430168 100644 --- a/infrastructure/io/src/main/java/tech/pegasys/teku/infrastructure/io/JemallocDetector.java +++ b/infrastructure/io/src/main/java/tech/pegasys/teku/infrastructure/io/JemallocDetector.java @@ -23,6 +23,7 @@ @SuppressWarnings("JavaCase") public class JemallocDetector { private static final Logger LOG = LogManager.getLogger(); + @SuppressWarnings("NonFinalStaticField") private static String _jemalloc; public static void logJemallocPresence() { diff --git a/infrastructure/json/src/test/java/tech/pegasys/teku/infrastructure/json/types/DeserializableOneOfTypeDefinitionBuilderTest.java b/infrastructure/json/src/test/java/tech/pegasys/teku/infrastructure/json/types/DeserializableOneOfTypeDefinitionBuilderTest.java index 3fd23cdaf81..fb6f1f7a88d 100644 --- a/infrastructure/json/src/test/java/tech/pegasys/teku/infrastructure/json/types/DeserializableOneOfTypeDefinitionBuilderTest.java +++ b/infrastructure/json/src/test/java/tech/pegasys/teku/infrastructure/json/types/DeserializableOneOfTypeDefinitionBuilderTest.java @@ -27,11 +27,11 @@ public class DeserializableOneOfTypeDefinitionBuilderTest { DeserializableOneOfTypeDefinition.object(OneOfTypeTestTypeDefinition.TestType.class) .description("meaningful description") .withType( - OneOfTypeTestTypeDefinition.TestObjA.isInstance, + OneOfTypeTestTypeDefinition.TestObjA.IS_INSTANCE, s -> s.contains("value1"), TYPE_A) .withType( - OneOfTypeTestTypeDefinition.TestObjB.isInstance, + OneOfTypeTestTypeDefinition.TestObjB.IS_INSTANCE, s -> s.contains("value2"), TYPE_B) .build(); diff --git a/infrastructure/json/src/testFixtures/java/tech/pegasys/teku/infrastructure/json/types/OneOfTypeTestTypeDefinition.java b/infrastructure/json/src/testFixtures/java/tech/pegasys/teku/infrastructure/json/types/OneOfTypeTestTypeDefinition.java index 83ded29ac48..d2222dd17c8 100644 --- a/infrastructure/json/src/testFixtures/java/tech/pegasys/teku/infrastructure/json/types/OneOfTypeTestTypeDefinition.java +++ b/infrastructure/json/src/testFixtures/java/tech/pegasys/teku/infrastructure/json/types/OneOfTypeTestTypeDefinition.java @@ -42,8 +42,8 @@ public interface TestType { SERIALIZABLE_ONE_OF_TYPE_DEFINITION = new SerializableOneOfTypeDefinitionBuilder() .description("meaningful description") - .withType(TestObjA.isInstance, TYPE_A) - .withType(TestObjB.isInstance, TYPE_B) + .withType(TestObjA.IS_INSTANCE, TYPE_A) + .withType(TestObjB.IS_INSTANCE, TYPE_B) .build(); public static class TestObjA implements TestType { @@ -82,7 +82,7 @@ public int hashCode() { return Objects.hash(name); } - static Predicate isInstance = testType -> testType instanceof TestObjA; + static final Predicate IS_INSTANCE = testType -> testType instanceof TestObjA; } public static class TestObjB implements TestType { @@ -104,6 +104,6 @@ public void setName(final String name) { this.name = name; } - static Predicate isInstance = testType -> testType instanceof TestObjB; + static final Predicate IS_INSTANCE = testType -> testType instanceof TestObjB; } } diff --git a/infrastructure/kzg/src/main/java/tech/pegasys/teku/kzg/CKZG4844.java b/infrastructure/kzg/src/main/java/tech/pegasys/teku/kzg/CKZG4844.java index 33b14a6fbd0..52a2d27b0a4 100644 --- a/infrastructure/kzg/src/main/java/tech/pegasys/teku/kzg/CKZG4844.java +++ b/infrastructure/kzg/src/main/java/tech/pegasys/teku/kzg/CKZG4844.java @@ -31,6 +31,7 @@ final class CKZG4844 implements KZG { // used for FK20 proof computations (PeerDAS) so can default to 0 for now private static final int PRECOMPUTE_DEFAULT = 0; + @SuppressWarnings("NonFinalStaticField") private static CKZG4844 instance; static synchronized CKZG4844 getInstance() { diff --git a/infrastructure/logging/src/main/java/tech/pegasys/teku/infrastructure/logging/LoggingConfigurator.java b/infrastructure/logging/src/main/java/tech/pegasys/teku/infrastructure/logging/LoggingConfigurator.java index 085d03da718..44280bba40d 100644 --- a/infrastructure/logging/src/main/java/tech/pegasys/teku/infrastructure/logging/LoggingConfigurator.java +++ b/infrastructure/logging/src/main/java/tech/pegasys/teku/infrastructure/logging/LoggingConfigurator.java @@ -51,16 +51,24 @@ public class LoggingConfigurator { private static final String FILE_MESSAGE_FORMAT = "%d{yyyy-MM-dd HH:mm:ss.SSSZZZ} | %t | %-5level | %c{1} | %msg%n"; private static final AtomicBoolean COLOR = new AtomicBoolean(); + private static final StatusLogger STATUS_LOG = StatusLogger.getLogger(); + @SuppressWarnings("NonFinalStaticField") private static LoggingDestination destination; + @SuppressWarnings("NonFinalStaticField") private static boolean includeEvents; + @SuppressWarnings("NonFinalStaticField") private static boolean includeValidatorDuties; + @SuppressWarnings("NonFinalStaticField") private static boolean includeP2pWarnings; + @SuppressWarnings("NonFinalStaticField") private static String file; + @SuppressWarnings("NonFinalStaticField") private static String filePattern; + @SuppressWarnings("NonFinalStaticField") private static Level rootLogLevel = Level.INFO; + @SuppressWarnings("NonFinalStaticField") private static int dbOpAlertThresholdMillis; - private static final StatusLogger STATUS_LOG = StatusLogger.getLogger(); public static boolean isColorEnabled() { return COLOR.get(); diff --git a/infrastructure/ssz/src/test/java/tech/pegasys/teku/infrastructure/ssz/SszCompositeListTest.java b/infrastructure/ssz/src/test/java/tech/pegasys/teku/infrastructure/ssz/SszCompositeListTest.java index 5108cddcfc7..377b08ff7fe 100644 --- a/infrastructure/ssz/src/test/java/tech/pegasys/teku/infrastructure/ssz/SszCompositeListTest.java +++ b/infrastructure/ssz/src/test/java/tech/pegasys/teku/infrastructure/ssz/SszCompositeListTest.java @@ -35,7 +35,7 @@ public class SszCompositeListTest { - static SszSchema testType = + static final SszSchema TEST_TYPE = new SszSchema<>() { @Override @@ -126,7 +126,7 @@ public TestView(final TreeNode node) { @Override public SszSchema getSchema() { - return testType; + return TEST_TYPE; } @Override @@ -145,7 +145,7 @@ public SszMutableData createWritableCopy() { @Test public void simpleTest1() { - SszListSchema listType = SszListSchema.create(testType, 3); + SszListSchema listType = SszListSchema.create(TEST_TYPE, 3); SszMutableList list = listType.getDefault().createWritableCopy(); TreeNode n0 = list.commitChanges().getBackingNode(); list.set(0, new TestView(0x111)); diff --git a/infrastructure/ssz/src/test/java/tech/pegasys/teku/infrastructure/ssz/collections/SszBitlistTest.java b/infrastructure/ssz/src/test/java/tech/pegasys/teku/infrastructure/ssz/collections/SszBitlistTest.java index 207de309b75..bfa64d46f41 100644 --- a/infrastructure/ssz/src/test/java/tech/pegasys/teku/infrastructure/ssz/collections/SszBitlistTest.java +++ b/infrastructure/ssz/src/test/java/tech/pegasys/teku/infrastructure/ssz/collections/SszBitlistTest.java @@ -41,46 +41,46 @@ public class SszBitlistTest implements SszPrimitiveListTestBase { - static Random random = new Random(1); - static SszBitlistSchema emptySchema = SszBitlistSchema.create(0); - static SszBitlistSchema schema = SszBitlistSchema.create(500); - static SszBitlistSchema hugeSchema = SszBitlistSchema.create(1L << 62); + static final Random RANDOM = new Random(1); + static final SszBitlistSchema EMPTY_SCHEMA = SszBitlistSchema.create(0); + static final SszBitlistSchema SCHEMA = SszBitlistSchema.create(500); + static final SszBitlistSchema HUGE_SCHEMA = SszBitlistSchema.create(1L << 62); static SszBitlist random(final SszBitlistSchema schema, final int size) { return schema.ofBits( - size, IntStream.range(0, size).filter(__ -> random.nextBoolean()).toArray()); + size, IntStream.range(0, size).filter(__ -> RANDOM.nextBoolean()).toArray()); } @Override public Stream sszData() { return Stream.of( - emptySchema.empty(), - schema.empty(), - hugeSchema.empty(), - random(schema, 1), - random(hugeSchema, 1), - random(schema, 2), - random(hugeSchema, 2), - random(schema, 254), - schema.ofBits(254), - schema.ofBits(254, IntStream.range(0, 254).toArray()), - random(hugeSchema, 254), - random(schema, 255), - schema.ofBits(255), - schema.ofBits(255, IntStream.range(0, 255).toArray()), - random(hugeSchema, 255), - random(schema, 256), - schema.ofBits(256), - schema.ofBits(256, IntStream.range(0, 256).toArray()), - random(hugeSchema, 256), - random(schema, 257), - random(hugeSchema, 257), - random(schema, 499), - random(schema, 500), - random(hugeSchema, 511), - random(hugeSchema, 512), - random(hugeSchema, 513), - random(hugeSchema, 10000)); + EMPTY_SCHEMA.empty(), + SCHEMA.empty(), + HUGE_SCHEMA.empty(), + random(SCHEMA, 1), + random(HUGE_SCHEMA, 1), + random(SCHEMA, 2), + random(HUGE_SCHEMA, 2), + random(SCHEMA, 254), + SCHEMA.ofBits(254), + SCHEMA.ofBits(254, IntStream.range(0, 254).toArray()), + random(HUGE_SCHEMA, 254), + random(SCHEMA, 255), + SCHEMA.ofBits(255), + SCHEMA.ofBits(255, IntStream.range(0, 255).toArray()), + random(HUGE_SCHEMA, 255), + random(SCHEMA, 256), + SCHEMA.ofBits(256), + SCHEMA.ofBits(256, IntStream.range(0, 256).toArray()), + random(HUGE_SCHEMA, 256), + random(SCHEMA, 257), + random(HUGE_SCHEMA, 257), + random(SCHEMA, 499), + random(SCHEMA, 500), + random(HUGE_SCHEMA, 511), + random(HUGE_SCHEMA, 512), + random(HUGE_SCHEMA, 513), + random(HUGE_SCHEMA, 10000)); } public Stream bitlistArgs() { @@ -149,8 +149,8 @@ void wrapBitSet_shouldDropBitsIfBitSetIsLarger() { bitSet.set(99); assertThat(bitSet.stream().count()).isEqualTo(1); - final SszBitlist sszBitlist = schema.wrapBitSet(10, bitSet); - final SszBitlist expectedSszBitlist = schema.ofBits(10); + final SszBitlist sszBitlist = SCHEMA.wrapBitSet(10, bitSet); + final SszBitlist expectedSszBitlist = SCHEMA.ofBits(10); assertThat(sszBitlist).isEqualTo(expectedSszBitlist); assertThat(sszBitlist.hashCode()).isEqualTo(expectedSszBitlist.hashCode()); @@ -161,7 +161,7 @@ void wrapBitSet_shouldDropBitsIfBitSetIsLarger() { @Test void wrapBitSet_shouldThrowIfSizeIsLargerThanSchemaMaxLength() { assertThatThrownBy( - () -> schema.wrapBitSet(Math.toIntExact(schema.getMaxLength() + 1), new BitSet())) + () -> SCHEMA.wrapBitSet(Math.toIntExact(SCHEMA.getMaxLength() + 1), new BitSet())) .isInstanceOf(IllegalArgumentException.class); } @@ -331,12 +331,12 @@ void testOrWithEmptyBitlist(final SszBitlist bitlist) { @Test void testEmptyHashTreeRoot() { - assertThat(emptySchema.empty().hashTreeRoot()) + assertThat(EMPTY_SCHEMA.empty().hashTreeRoot()) .isEqualTo(Hash.sha256(Bytes.concatenate(Bytes32.ZERO, Bytes32.ZERO))); - assertThat(schema.empty().hashTreeRoot()) + assertThat(SCHEMA.empty().hashTreeRoot()) .isEqualTo( Hash.sha256(Bytes.concatenate(TreeUtil.ZERO_TREES[1].hashTreeRoot(), Bytes32.ZERO))); - assertThat(hugeSchema.empty().hashTreeRoot()) + assertThat(HUGE_SCHEMA.empty().hashTreeRoot()) .isEqualTo( Hash.sha256( Bytes.concatenate(TreeUtil.ZERO_TREES[62 - 8].hashTreeRoot(), Bytes32.ZERO)));