Skip to content

Commit

Permalink
Enable the NonFinalStaticField check
Browse files Browse the repository at this point in the history
  • Loading branch information
jtraglia committed Oct 21, 2024
1 parent 74afe16 commit 16dc733
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 48 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public abstract class AbstractBlockProcessor implements BlockProcessor {
* Setting to <code>false</code> significantly speeds up state initialization
*/
@VisibleForTesting
@SuppressWarnings("NonFinalStaticField")
public static BLSSignatureVerifier depositSignatureVerifier = DEFAULT_DEPOSIT_SIGNATURE_VERIFIER;

private static final Logger LOG = LogManager.getLogger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class BLS {

private static final Logger LOG = LogManager.getLogger();

@SuppressWarnings("NonFinalStaticField")
private static BLS12381 blsImpl;

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public interface TestType {
SERIALIZABLE_ONE_OF_TYPE_DEFINITION =
new SerializableOneOfTypeDefinitionBuilder<TestType>()
.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 {
Expand Down Expand Up @@ -82,7 +82,7 @@ public int hashCode() {
return Objects.hash(name);
}

static Predicate<TestType> isInstance = testType -> testType instanceof TestObjA;
static final Predicate<TestType> IS_INSTANCE = testType -> testType instanceof TestObjA;
}

public static class TestObjB implements TestType {
Expand All @@ -104,6 +104,6 @@ public void setName(final String name) {
this.name = name;
}

static Predicate<TestType> isInstance = testType -> testType instanceof TestObjB;
static final Predicate<TestType> IS_INSTANCE = testType -> testType instanceof TestObjB;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

public class SszCompositeListTest {

static SszSchema<TestView> testType =
static final SszSchema<TestView> TEST_TYPE =
new SszSchema<>() {

@Override
Expand Down Expand Up @@ -126,7 +126,7 @@ public TestView(final TreeNode node) {

@Override
public SszSchema<?> getSchema() {
return testType;
return TEST_TYPE;
}

@Override
Expand All @@ -145,7 +145,7 @@ public SszMutableData createWritableCopy() {

@Test
public void simpleTest1() {
SszListSchema<TestView, ?> listType = SszListSchema.create(testType, 3);
SszListSchema<TestView, ?> listType = SszListSchema.create(TEST_TYPE, 3);
SszMutableList<TestView> list = listType.getDefault().createWritableCopy();
TreeNode n0 = list.commitChanges().getBackingNode();
list.set(0, new TestView(0x111));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,46 +41,46 @@

public class SszBitlistTest implements SszPrimitiveListTestBase {

static Random random = new Random(1);
static SszBitlistSchema<SszBitlist> emptySchema = SszBitlistSchema.create(0);
static SszBitlistSchema<SszBitlist> schema = SszBitlistSchema.create(500);
static SszBitlistSchema<SszBitlist> hugeSchema = SszBitlistSchema.create(1L << 62);
static final Random RANDOM = new Random(1);
static final SszBitlistSchema<SszBitlist> EMPTY_SCHEMA = SszBitlistSchema.create(0);
static final SszBitlistSchema<SszBitlist> SCHEMA = SszBitlistSchema.create(500);
static final SszBitlistSchema<SszBitlist> 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<SszBitlist> 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<Arguments> bitlistArgs() {
Expand Down Expand Up @@ -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());
Expand All @@ -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);
}

Expand Down Expand Up @@ -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)));
Expand Down

0 comments on commit 16dc733

Please sign in to comment.