Skip to content

Commit

Permalink
Fix a bunch of non-final static fields (elastic#119185)
Browse files Browse the repository at this point in the history
Fixing almost all missing `final` spots, who knows maybe we get a small speedup from
some constant folding here and there.
  • Loading branch information
original-brownbear authored Dec 26, 2024
1 parent 3c84517 commit e94f145
Show file tree
Hide file tree
Showing 140 changed files with 238 additions and 242 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
import java.util.List;

public class InternalElasticsearchDistributionTypes {
public static ElasticsearchDistributionType DEB = new DebElasticsearchDistributionType();
public static ElasticsearchDistributionType RPM = new RpmElasticsearchDistributionType();
public static ElasticsearchDistributionType DOCKER = new DockerElasticsearchDistributionType();
public static ElasticsearchDistributionType DOCKER_IRONBANK = new DockerIronBankElasticsearchDistributionType();
public static ElasticsearchDistributionType DOCKER_CLOUD_ESS = new DockerCloudEssElasticsearchDistributionType();
public static ElasticsearchDistributionType DOCKER_WOLFI = new DockerWolfiElasticsearchDistributionType();
public static final ElasticsearchDistributionType DEB = new DebElasticsearchDistributionType();
public static final ElasticsearchDistributionType RPM = new RpmElasticsearchDistributionType();
public static final ElasticsearchDistributionType DOCKER = new DockerElasticsearchDistributionType();
public static final ElasticsearchDistributionType DOCKER_IRONBANK = new DockerIronBankElasticsearchDistributionType();
public static final ElasticsearchDistributionType DOCKER_CLOUD_ESS = new DockerCloudEssElasticsearchDistributionType();
public static final ElasticsearchDistributionType DOCKER_WOLFI = new DockerWolfiElasticsearchDistributionType();

public static List<ElasticsearchDistributionType> ALL_INTERNAL = List.of(
public static final List<ElasticsearchDistributionType> ALL_INTERNAL = List.of(
DEB,
RPM,
DOCKER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class TestRerunTaskExtension {
/**
* The name of the extension added to each test task.
*/
public static String NAME = "rerun";
public static final String NAME = "rerun";

private final Property<Integer> maxReruns;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
import org.elasticsearch.gradle.ElasticsearchDistributionType;

public class ElasticsearchDistributionTypes {
public static ElasticsearchDistributionType ARCHIVE = new ArchiveElasticsearchDistributionType();
public static ElasticsearchDistributionType INTEG_TEST_ZIP = new IntegTestZipElasticsearchDistributionType();
public static final ElasticsearchDistributionType ARCHIVE = new ArchiveElasticsearchDistributionType();
public static final ElasticsearchDistributionType INTEG_TEST_ZIP = new IntegTestZipElasticsearchDistributionType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

public class PatternBank {

public static PatternBank EMPTY = new PatternBank(Map.of());
public static final PatternBank EMPTY = new PatternBank(Map.of());

private final Map<String, String> bank;

Expand Down
16 changes: 8 additions & 8 deletions libs/h3/src/main/java/org/elasticsearch/h3/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,27 @@ final class Constants {
/**
* sqrt(3) / 2.0
*/
public static double M_SQRT3_2 = 0.8660254037844386467637231707529361834714;
public static final double M_SQRT3_2 = 0.8660254037844386467637231707529361834714;
/**
* 2.0 * PI
*/
public static final double M_2PI = 2.0 * Math.PI;
/**
* The number of H3 base cells
*/
public static int NUM_BASE_CELLS = 122;
public static final int NUM_BASE_CELLS = 122;
/**
* The number of vertices in a hexagon
*/
public static int NUM_HEX_VERTS = 6;
public static final int NUM_HEX_VERTS = 6;
/**
* The number of vertices in a pentagon
*/
public static int NUM_PENT_VERTS = 5;
public static final int NUM_PENT_VERTS = 5;
/**
* H3 index modes
*/
public static int H3_CELL_MODE = 1;
public static final int H3_CELL_MODE = 1;
/**
* square root of 7
*/
Expand All @@ -64,14 +64,14 @@ final class Constants {
* (or distance between adjacent cell center points
* on the plane) to gnomonic unit length.
*/
public static double RES0_U_GNOMONIC = 0.38196601125010500003;
public static final double RES0_U_GNOMONIC = 0.38196601125010500003;
/**
* rotation angle between Class II and Class III resolution axes
* (asin(sqrt(3.0 / 28.0)))
*/
public static double M_AP7_ROT_RADS = 0.333473172251832115336090755351601070065900389;
public static final double M_AP7_ROT_RADS = 0.333473172251832115336090755351601070065900389;
/**
* threshold epsilon
*/
public static double EPSILON = 0.0000000000000001;
public static final double EPSILON = 0.0000000000000001;
}
2 changes: 1 addition & 1 deletion libs/h3/src/main/java/org/elasticsearch/h3/H3.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class H3 {
/**
* max H3 resolution; H3 version 1 has 16 resolutions, numbered 0 through 15
*/
public static int MAX_H3_RES = 15;
public static final int MAX_H3_RES = 15;

private static final long[] NORTH = new long[MAX_H3_RES + 1];
private static final long[] SOUTH = new long[MAX_H3_RES + 1];
Expand Down
32 changes: 16 additions & 16 deletions libs/h3/src/main/java/org/elasticsearch/h3/H3Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,22 @@ public static boolean H3_is_pentagon(long h3) {
return BaseCells.isBaseCellPentagon(H3Index.H3_get_base_cell(h3)) && H3Index.h3LeadingNonZeroDigit(h3) == 0;
}

public static long H3_INIT = 35184372088831L;
public static final long H3_INIT = 35184372088831L;

/**
* The bit offset of the mode in an H3 index.
*/
public static int H3_MODE_OFFSET = 59;
public static final int H3_MODE_OFFSET = 59;

/**
* 1's in the 4 mode bits, 0's everywhere else.
*/
public static long H3_MODE_MASK = 15L << H3_MODE_OFFSET;
public static final long H3_MODE_MASK = 15L << H3_MODE_OFFSET;

/**
* 0's in the 4 mode bits, 1's everywhere else.
*/
public static long H3_MODE_MASK_NEGATIVE = ~H3_MODE_MASK;
public static final long H3_MODE_MASK_NEGATIVE = ~H3_MODE_MASK;

public static long H3_set_mode(long h3, long mode) {
return (h3 & H3_MODE_MASK_NEGATIVE) | (mode << H3_MODE_OFFSET);
Expand All @@ -65,16 +65,16 @@ public static long H3_set_mode(long h3, long mode) {
/**
* The bit offset of the base cell in an H3 index.
*/
public static int H3_BC_OFFSET = 45;
public static final int H3_BC_OFFSET = 45;
/**
* 1's in the 7 base cell bits, 0's everywhere else.
*/
public static long H3_BC_MASK = 127L << H3_BC_OFFSET;
public static final long H3_BC_MASK = 127L << H3_BC_OFFSET;

/**
* 0's in the 7 base cell bits, 1's everywhere else.
*/
public static long H3_BC_MASK_NEGATIVE = ~H3_BC_MASK;
public static final long H3_BC_MASK_NEGATIVE = ~H3_BC_MASK;

/**
* Sets the integer base cell of h3 to bc.
Expand All @@ -83,26 +83,26 @@ public static long H3_set_base_cell(long h3, long bc) {
return (h3 & H3_BC_MASK_NEGATIVE) | (bc << H3_BC_OFFSET);
}

public static int H3_RES_OFFSET = 52;
public static final int H3_RES_OFFSET = 52;
/**
* 1's in the 4 resolution bits, 0's everywhere else.
*/
public static long H3_RES_MASK = 15L << H3_RES_OFFSET;
public static final long H3_RES_MASK = 15L << H3_RES_OFFSET;

/**
* 0's in the 4 resolution bits, 1's everywhere else.
*/
public static long H3_RES_MASK_NEGATIVE = ~H3_RES_MASK;
public static final long H3_RES_MASK_NEGATIVE = ~H3_RES_MASK;

/**
* The bit offset of the max resolution digit in an H3 index.
*/
public static int H3_MAX_OFFSET = 63;
public static final int H3_MAX_OFFSET = 63;

/**
* 1 in the highest bit, 0's everywhere else.
*/
public static long H3_HIGH_BIT_MASK = (1L << H3_MAX_OFFSET);
public static final long H3_HIGH_BIT_MASK = (1L << H3_MAX_OFFSET);

/**
* Gets the highest bit of the H3 index.
Expand All @@ -121,12 +121,12 @@ public static long H3_set_resolution(long h3, long res) {
/**
* The bit offset of the reserved bits in an H3 index.
*/
public static int H3_RESERVED_OFFSET = 56;
public static final int H3_RESERVED_OFFSET = 56;

/**
* 1's in the 3 reserved bits, 0's everywhere else.
*/
public static long H3_RESERVED_MASK = (7L << H3_RESERVED_OFFSET);
public static final long H3_RESERVED_MASK = (7L << H3_RESERVED_OFFSET);

/**
* Gets a value in the reserved space. Should always be zero for valid indexes.
Expand All @@ -149,12 +149,12 @@ public static int H3_get_resolution(long h3) {
/**
* The number of bits in a single H3 resolution digit.
*/
public static int H3_PER_DIGIT_OFFSET = 3;
public static final int H3_PER_DIGIT_OFFSET = 3;

/**
* 1's in the 3 bits of res 15 digit bits, 0's everywhere else.
*/
public static long H3_DIGIT_MASK = 7L;
public static final long H3_DIGIT_MASK = 7L;

/**
* Gets the resolution res integer digit (0-7) of h3.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

public class IngestDocumentBridge extends StableBridgeAPI.Proxy<IngestDocument> {

public static String INGEST_KEY = IngestDocument.INGEST_KEY;

public static IngestDocumentBridge wrap(final IngestDocument ingestDocument) {
if (ingestDocument == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public class MergingDigest extends AbstractTDigest {
// based on accumulated k-index. This can be much faster since we
// scale functions are more expensive than the corresponding
// weight limits.
public static boolean useWeightLimit = true;
public static final boolean useWeightLimit = true;

static MergingDigest create(TDigestArrays arrays, double compression) {
arrays.adjustBreaker(SHALLOW_SIZE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
*/
public class FingerprintAnalyzerProvider extends AbstractIndexAnalyzerProvider<Analyzer> {

public static ParseField SEPARATOR = new ParseField("separator");
public static ParseField MAX_OUTPUT_SIZE = new ParseField("max_output_size");
public static final ParseField SEPARATOR = new ParseField("separator");
public static final ParseField MAX_OUTPUT_SIZE = new ParseField("max_output_size");

public static int DEFAULT_MAX_OUTPUT_SIZE = 255;
public static CharArraySet DEFAULT_STOP_WORDS = CharArraySet.EMPTY_SET;
public static final int DEFAULT_MAX_OUTPUT_SIZE = 255;
public static final CharArraySet DEFAULT_STOP_WORDS = CharArraySet.EMPTY_SET;
public static final char DEFAULT_SEPARATOR = ' ';

private final FingerprintAnalyzer analyzer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public abstract class DotPrefixValidator<RequestType> implements MappedActionFil
".ml-state",
".ml-anomalies-unrelated"
);
public static Setting<List<String>> IGNORED_INDEX_PATTERNS_SETTING = Setting.stringListSetting(
public static final Setting<List<String>> IGNORED_INDEX_PATTERNS_SETTING = Setting.stringListSetting(
"cluster.indices.validate_ignored_dot_patterns",
List.of(
"\\.ml-state-\\d+",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.io.InputStream;

public class SearchTemplateResponse extends ActionResponse implements ToXContentObject {
public static ParseField TEMPLATE_OUTPUT_FIELD = new ParseField("template_output");
public static final ParseField TEMPLATE_OUTPUT_FIELD = new ParseField("template_output");

/** Contains the source of the rendered template **/
private BytesReference source;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public LegacyGeoShapeFieldMapper build(MapperBuilderContext context) {
}

@Deprecated
public static Mapper.TypeParser PARSER = (name, node, parserContext) -> {
public static final Mapper.TypeParser PARSER = (name, node, parserContext) -> {
boolean ignoreMalformedByDefault = IGNORE_MALFORMED_SETTING.get(parserContext.getSettings());
boolean coerceByDefault = COERCE_SETTING.get(parserContext.getSettings());
FieldMapper.Builder builder = new LegacyGeoShapeFieldMapper.Builder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public ValueFetcher valueFetcher(SearchExecutionContext context, String format)
}
}

public static TypeParser PARSER = new TypeParser((n, c) -> new Builder(n));
public static final TypeParser PARSER = new TypeParser((n, c) -> new Builder(n));

private final boolean index;
private final boolean hasDocValues;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class AzureStorageService {
* The maximum size of a BlockBlob block.
* See https://docs.microsoft.com/en-us/rest/api/storageservices/understanding-block-blobs--append-blobs--and-page-blobs
*/
public static ByteSizeValue MAX_BLOCK_SIZE = new ByteSizeValue(100, ByteSizeUnit.MB);
public static final ByteSizeValue MAX_BLOCK_SIZE = new ByteSizeValue(100, ByteSizeUnit.MB);

/**
* The maximum number of blocks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public record S3RepositoriesMetrics(
LongHistogram retryDeletesHistogram
) {

public static S3RepositoriesMetrics NOOP = new S3RepositoriesMetrics(RepositoriesMetrics.NOOP);
public static final S3RepositoriesMetrics NOOP = new S3RepositoriesMetrics(RepositoriesMetrics.NOOP);

public static final String METRIC_RETRY_EVENT_TOTAL = "es.repositories.s3.input_stream.retry.event.total";
public static final String METRIC_RETRY_SUCCESS_TOTAL = "es.repositories.s3.input_stream.retry.success.total";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class Netty4Plugin extends Plugin implements NetworkPlugin {
*/
private static final ByteSizeValue MTU = ByteSizeValue.ofBytes(Long.parseLong(System.getProperty("es.net.mtu", "1500")));
private static final String SETTING_KEY_HTTP_NETTY_MAX_COMPOSITE_BUFFER_COMPONENTS = "http.netty.max_composite_buffer_components";
public static Setting<Integer> SETTING_HTTP_NETTY_MAX_COMPOSITE_BUFFER_COMPONENTS = new Setting<>(
public static final Setting<Integer> SETTING_HTTP_NETTY_MAX_COMPOSITE_BUFFER_COMPONENTS = new Setting<>(
SETTING_KEY_HTTP_NETTY_MAX_COMPOSITE_BUFFER_COMPONENTS,
(s) -> {
ByteSizeValue maxContentLength = SETTING_HTTP_MAX_CONTENT_LENGTH.get(s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public AnnotatedTextFieldMapper build(MapperBuilderContext context) {
}
}

public static TypeParser PARSER = new TypeParser(
public static final TypeParser PARSER = new TypeParser(
(n, c) -> new Builder(n, c.indexVersionCreated(), c.getIndexAnalyzers(), SourceFieldMapper.isSynthetic(c.getIndexSettings()))
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Murmur3FieldMapper build(MapperBuilderContext context) {
}
}

public static TypeParser PARSER = new TypeParser((n, c) -> new Builder(n));
public static final TypeParser PARSER = new TypeParser((n, c) -> new Builder(n));

// this only exists so a check can be done to match the field type to using murmur3 hashing...
public static class Murmur3FieldType extends MappedFieldType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class CreateSnapshotRequest extends MasterNodeRequest<CreateSnapshotReque

public static final TransportVersion SETTINGS_IN_REQUEST_VERSION = TransportVersions.V_8_0_0;

public static int MAXIMUM_METADATA_BYTES = 1024; // chosen arbitrarily
public static final int MAXIMUM_METADATA_BYTES = 1024; // chosen arbitrarily

private String snapshot;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.Optional;

public class GetShardSnapshotResponse extends ActionResponse {
public static GetShardSnapshotResponse EMPTY = new GetShardSnapshotResponse(null, Collections.emptyMap());
public static final GetShardSnapshotResponse EMPTY = new GetShardSnapshotResponse(null, Collections.emptyMap());

private final ShardSnapshotInfo latestShardSnapshot;
private final Map<String, RepositoryException> repositoryFailures;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class RestoreSnapshotRequest extends MasterNodeRequest<RestoreSnapshotReq
private boolean includeGlobalState = false;
private boolean partial = false;
private boolean includeAliases = true;
public static TransportVersion VERSION_SUPPORTING_QUIET_PARAMETER = TransportVersions.V_8_4_0;
public static final TransportVersion VERSION_SUPPORTING_QUIET_PARAMETER = TransportVersions.V_8_4_0;
private boolean quiet = false;
private Settings indexSettings = Settings.EMPTY;
private String[] ignoreIndexSettings = Strings.EMPTY_ARRAY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ public void writeTo(StreamOutput out) throws IOException {
* which there is no shard-level return value.
*/
public static final class EmptyResult implements Writeable {
public static EmptyResult INSTANCE = new EmptyResult();
public static final EmptyResult INSTANCE = new EmptyResult();

private EmptyResult() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public record ClusterSnapshotStats(
List<PerRepositoryStats> statsByRepository
) implements ToXContentObject, Writeable {

public static ClusterSnapshotStats EMPTY = new ClusterSnapshotStats(0, 0, 0, 0, List.of());
public static final ClusterSnapshotStats EMPTY = new ClusterSnapshotStats(0, 0, 0, 0, List.of());

public static ClusterSnapshotStats of(ClusterState clusterState, long currentTimeMillis) {
return of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ public DataStreamTemplate(boolean hidden, boolean allowCustomRouting) {
/**
* A mapping snippet for a backing index with `_data_stream_timestamp` meta field mapper properly configured.
*/
public static CompressedXContent DATA_STREAM_MAPPING_SNIPPET;
public static final CompressedXContent DATA_STREAM_MAPPING_SNIPPET;

static {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static boolean isFailureStoreFeatureFlagEnabled() {
public static final DateFormatter DATE_FORMATTER = DateFormatter.forPattern("uuuu.MM.dd");
public static final String TIMESTAMP_FIELD_NAME = "@timestamp";
// Timeseries indices' leaf readers should be sorted by desc order of their timestamp field, as it allows search time optimizations
public static Comparator<LeafReader> TIMESERIES_LEAF_READERS_SORTER = Comparator.comparingLong((LeafReader r) -> {
public static final Comparator<LeafReader> TIMESERIES_LEAF_READERS_SORTER = Comparator.comparingLong((LeafReader r) -> {
try {
PointValues points = r.getPointValues(TIMESTAMP_FIELD_NAME);
if (points != null) {
Expand Down
Loading

0 comments on commit e94f145

Please sign in to comment.