Skip to content

Commit a36d90c

Browse files
authored
Use CLDR locale provider on JDK 23+ (#110222)
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 0074c14 commit a36d90c

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
'-Des.nativelibs.path="' + testLibraryPath + '"',
172172
// TODO: only open these for mockito when it is modularized
173173
'--add-opens=java.base/java.security.cert=ALL-UNNAMED',

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
@@ -10,6 +10,7 @@
1010

1111
import org.elasticsearch.common.settings.Settings;
1212
import org.elasticsearch.common.util.concurrent.EsExecutors;
13+
import org.elasticsearch.core.UpdateForV9;
1314

1415
import java.util.List;
1516
import java.util.Map;
@@ -59,11 +60,7 @@ static List<String> systemJvmOptions(Settings nodeSettings, final Map<String, St
5960
"-Dlog4j.shutdownHookEnabled=false",
6061
"-Dlog4j2.disable.jmx=true",
6162
"-Dlog4j2.formatMsgNoLookups=true",
62-
/*
63-
* Due to internationalization enhancements in JDK 9 Elasticsearch need to set the provider to COMPAT otherwise time/date
64-
* parsing will break in an incompatible way for some date patterns and locales.
65-
*/
66-
"-Djava.locale.providers=SPI,COMPAT",
63+
"-Djava.locale.providers=" + getLocaleProviders(),
6764
maybeEnableNativeAccess(),
6865
maybeOverrideDockerCgroup(distroType),
6966
maybeSetActiveProcessorCount(nodeSettings),
@@ -75,6 +72,16 @@ static List<String> systemJvmOptions(Settings nodeSettings, final Map<String, St
7572
).filter(e -> e.isEmpty() == false).collect(Collectors.toList());
7673
}
7774

75+
@UpdateForV9 // only use CLDR in v9+
76+
private static String getLocaleProviders() {
77+
/*
78+
* Specify SPI to load IsoCalendarDataProvider (see #48209), specifying the first day of week as Monday.
79+
* When on pre-23, use COMPAT instead to maintain existing date formats as much as we can.
80+
* When on JDK 23+, use the default CLDR locale database, as COMPAT was removed in JDK 23.
81+
*/
82+
return Runtime.version().feature() >= 23 ? "SPI,CLDR" : "SPI,COMPAT";
83+
}
84+
7885
/*
7986
* The virtual file /proc/self/cgroup should list the current cgroup
8087
* 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
@@ -951,7 +951,7 @@ For example:
951951
"day_of_week": {
952952
"type": "keyword",
953953
"script": {
954-
"source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))"
954+
"source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ENGLISH))"
955955
}
956956
}
957957
}

0 commit comments

Comments
 (0)