Skip to content

Commit 103f4ee

Browse files
authored
[8.15] Use CLDR locale provider on JDK 23 (#110222) (#112520)
Backports #110222 to 8.15. JDK 23 removes the COMPAT locale provider, leaving CLDR as the only option. This commit configures Elasticsearch to use the CLDR provider when on JDK 23, but still use the existing COMPAT provider when on JDK 22 and below. This causes some differences in locale behaviour; this also adapts various tests to still work whether run on COMPAT or CLDR.
1 parent 92d4f85 commit 103f4ee

File tree

30 files changed

+73
-92
lines changed

30 files changed

+73
-92
lines changed

build-tools-internal/src/main/groovy/elasticsearch.ide.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ if (providers.systemProperty('idea.active').getOrNull() == 'true') {
167167
vmParameters = [
168168
'-ea',
169169
'-Djava.security.manager=allow',
170-
'-Djava.locale.providers=SPI,COMPAT',
170+
'-Djava.locale.providers=SPI,CLDR',
171171
'-Djava.library.path=' + testLibraryPath,
172172
'-Djna.library.path=' + testLibraryPath,
173173
// TODO: only open these for mockito when it is modularized

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchTestBasePlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void execute(Task t) {
9292
mkdirs(test.getWorkingDir().toPath().resolve("temp").toFile());
9393

9494
// TODO remove once jvm.options are added to test system properties
95-
test.systemProperty("java.locale.providers", "SPI,COMPAT");
95+
test.systemProperty("java.locale.providers", "SPI,CLDR");
9696
}
9797
});
9898
test.getJvmArgumentProviders().add(nonInputProperties);

distribution/tools/server-cli/src/main/java/org/elasticsearch/server/cli/SystemJvmOptions.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.elasticsearch.common.settings.Settings;
1212
import org.elasticsearch.common.util.concurrent.EsExecutors;
1313
import org.elasticsearch.core.SuppressForbidden;
14+
import org.elasticsearch.core.UpdateForV9;
1415

1516
import java.io.File;
1617
import java.nio.file.Path;
@@ -64,11 +65,7 @@ static List<String> systemJvmOptions(Settings nodeSettings, final Map<String, St
6465
"-Dlog4j.shutdownHookEnabled=false",
6566
"-Dlog4j2.disable.jmx=true",
6667
"-Dlog4j2.formatMsgNoLookups=true",
67-
/*
68-
* Due to internationalization enhancements in JDK 9 Elasticsearch need to set the provider to COMPAT otherwise time/date
69-
* parsing will break in an incompatible way for some date patterns and locales.
70-
*/
71-
"-Djava.locale.providers=SPI,COMPAT",
68+
"-Djava.locale.providers=" + getLocaleProviders(),
7269
/*
7370
* Temporarily suppress illegal reflective access in searchable snapshots shared cache preallocation; this is temporary
7471
* while we explore alternatives. See org.elasticsearch.xpack.searchablesnapshots.preallocate.Preallocate.
@@ -87,6 +84,16 @@ static List<String> systemJvmOptions(Settings nodeSettings, final Map<String, St
8784
).filter(e -> e.isEmpty() == false).collect(Collectors.toList());
8885
}
8986

87+
@UpdateForV9 // only use CLDR in v9+
88+
private static String getLocaleProviders() {
89+
/*
90+
* Specify SPI to load IsoCalendarDataProvider (see #48209), specifying the first day of week as Monday.
91+
* When on pre-23, use COMPAT instead to maintain existing date formats as much as we can.
92+
* When on JDK 23+, use the default CLDR locale database, as COMPAT was removed in JDK 23.
93+
*/
94+
return Runtime.version().feature() >= 23 ? "SPI,CLDR" : "SPI,COMPAT";
95+
}
96+
9097
/*
9198
* The virtual file /proc/self/cgroup should list the current cgroup
9299
* membership. For each hierarchy, you can follow the cgroup path from

docs/painless/painless-contexts/painless-field-context.asciidoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ actors that appear in each play:
6464
----
6565
GET seats/_search
6666
{
67-
"size": 2,
67+
"size": 2,
6868
"query": {
6969
"match_all": {}
7070
},
7171
"script_fields": {
7272
"day-of-week": {
7373
"script": {
74-
"source": "doc['datetime'].value.getDayOfWeekEnum().getDisplayName(TextStyle.FULL, Locale.ROOT)"
74+
"source": "doc['datetime'].value.getDayOfWeekEnum().getDisplayName(TextStyle.FULL, Locale.ENGLISH)"
7575
}
7676
},
7777
"number-of-actors": {
@@ -132,4 +132,4 @@ GET seats/_search
132132
}
133133
}
134134
----
135-
// TESTRESPONSE[s/"took" : 68/"took" : "$body.took"/]
135+
// TESTRESPONSE[s/"took" : 68/"took" : "$body.took"/]

docs/painless/painless-guide/painless-execute-script.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ POST /_scripts/painless/_execute
749749
{
750750
"script": {
751751
"source": """
752-
emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT));
752+
emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ENGLISH));
753753
"""
754754
},
755755
"context": "keyword_field",

docs/reference/aggregations/bucket/composite-aggregation.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ GET /_search
156156
"type": "keyword",
157157
"script": """
158158
emit(doc['timestamp'].value.dayOfWeekEnum
159-
.getDisplayName(TextStyle.FULL, Locale.ROOT))
159+
.getDisplayName(TextStyle.FULL, Locale.ENGLISH))
160160
"""
161161
}
162162
},

docs/reference/aggregations/bucket/datehistogram-aggregation.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ For example, the offset of `+19d` will result in buckets with names like `2022-0
582582

583583
Increasing the offset to `+20d`, each document will appear in a bucket for the previous month,
584584
with all bucket keys ending with the same day of the month, as normal.
585-
However, further increasing to `+28d`,
585+
However, further increasing to `+28d`,
586586
what used to be a February bucket has now become `"2022-03-01"`.
587587

588588
[source,console,id=datehistogram-aggregation-offset-example-28d]
@@ -819,7 +819,7 @@ POST /sales/_search?size=0
819819
"runtime_mappings": {
820820
"date.day_of_week": {
821821
"type": "keyword",
822-
"script": "emit(doc['date'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))"
822+
"script": "emit(doc['date'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ENGLISH))"
823823
}
824824
},
825825
"aggs": {

docs/reference/indices/index-templates.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ PUT _component_template/runtime_component_template
102102
"day_of_week": {
103103
"type": "keyword",
104104
"script": {
105-
"source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))"
105+
"source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ENGLISH))"
106106
}
107107
}
108108
}

docs/reference/mapping/runtime.asciidoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ PUT my-index-000001/
135135
"day_of_week": {
136136
"type": "keyword",
137137
"script": {
138-
"source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))"
138+
"source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ENGLISH))"
139139
}
140140
}
141141
},
@@ -291,7 +291,7 @@ GET my-index-000001/_search
291291
"day_of_week": {
292292
"type": "keyword",
293293
"script": {
294-
"source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))"
294+
"source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ENGLISH))"
295295
}
296296
}
297297
},
@@ -667,7 +667,7 @@ PUT my-index-000001/
667667
"day_of_week": {
668668
"type": "keyword",
669669
"script": {
670-
"source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))"
670+
"source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ENGLISH))"
671671
}
672672
}
673673
},

docs/reference/ml/ml-shared.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ For example:
913913
"day_of_week": {
914914
"type": "keyword",
915915
"script": {
916-
"source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))"
916+
"source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ENGLISH))"
917917
}
918918
}
919919
}

0 commit comments

Comments
 (0)