Skip to content

Commit 9a80a37

Browse files
authored
[7.17] Use CLDR locale provider on JDK 23 (#110222) (#112544)
Backports #110222 to 7.17. 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 63098be commit 9a80a37

File tree

15 files changed

+45
-38
lines changed

15 files changed

+45
-38
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
@@ -120,7 +120,7 @@ if (providers.systemProperty('idea.active').getOrNull() == 'true') {
120120
defaults(JUnit) {
121121
vmParameters = [
122122
'-ea',
123-
'-Djava.locale.providers=SPI,COMPAT',
123+
'-Djava.locale.providers=SPI,CLDR',
124124
"--illegal-access=deny",
125125
// TODO: only open these for mockito when it is modularized
126126
'--add-opens=java.base/java.security.cert=ALL-UNNAMED',

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ public void execute(Task t) {
8787
if (BuildParams.getRuntimeJavaVersion() == JavaVersion.VERSION_1_8) {
8888
test.systemProperty("java.locale.providers", "SPI,JRE");
8989
} else {
90-
test.systemProperty("java.locale.providers", "SPI,COMPAT");
90+
if (BuildParams.getRuntimeJavaVersion().compareTo(JavaVersion.VERSION_22) <= 0) {
91+
test.systemProperty("java.locale.providers", "SPI,COMPAT");
92+
} else {
93+
test.systemProperty("java.locale.providers", "SPI,CLDR");
94+
}
9195
test.jvmArgs(
9296
"--illegal-access=deny",
9397
// TODO: only open these for mockito when it is modularized

distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/SystemJvmOptions.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,15 @@ private static String javaLocaleProviders() {
9191
* parsing will break in an incompatible way for some date patterns and locales.
9292
* //TODO COMPAT will be deprecated in jdk14 https://bugs.openjdk.java.net/browse/JDK-8232906
9393
* See also: documentation in <code>server/org.elasticsearch.common.time.IsoCalendarDataProvider</code>
94+
*
95+
* COMPAT is removed in JDK 23, so we have to use CLDR for 23
9496
*/
9597
if (JavaVersion.majorVersion(JavaVersion.CURRENT) == 8) {
9698
return "-Djava.locale.providers=SPI,JRE";
97-
} else {
99+
} else if (JavaVersion.majorVersion(JavaVersion.CURRENT) <= 22) {
98100
return "-Djava.locale.providers=SPI,COMPAT";
101+
} else {
102+
return "-Djava.locale.providers=SPI,CLDR";
99103
}
100104
}
101105

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ POST /_scripts/painless/_execute
730730
{
731731
"script": {
732732
"source": """
733-
emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT));
733+
emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ENGLISH));
734734
"""
735735
},
736736
"context": "keyword_field",
@@ -823,4 +823,4 @@ The response includes the calculated value from the script valuation:
823823
8624909
824824
]
825825
}
826-
----
826+
----

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ POST /sales/_search?size=0
749749
"runtime_mappings": {
750750
"date.day_of_week": {
751751
"type": "keyword",
752-
"script": "emit(doc['date'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))"
752+
"script": "emit(doc['date'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ENGLISH))"
753753
}
754754
},
755755
"aggs": {

docs/reference/indices/index-templates.asciidoc

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

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
},
@@ -277,7 +277,7 @@ GET my-index-000001/_search
277277
"day_of_week": {
278278
"type": "keyword",
279279
"script": {
280-
"source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))"
280+
"source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ENGLISH))"
281281
}
282282
}
283283
},
@@ -661,7 +661,7 @@ PUT my-index-000001/
661661
"day_of_week": {
662662
"type": "keyword",
663663
"script": {
664-
"source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))"
664+
"source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ENGLISH))"
665665
}
666666
}
667667
},

docs/reference/ml/ml-shared.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ For example:
877877
"day_of_week": {
878878
"type": "keyword",
879879
"script": {
880-
"source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))"
880+
"source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ENGLISH))"
881881
}
882882
}
883883
}

modules/runtime-fields-common/src/yamlRestTest/resources/rest-api-spec/test/runtime_fields/10_keyword.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ setup:
1212
day_of_week:
1313
type: keyword
1414
script: |
15-
emit(doc['timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT));
15+
emit(doc['timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ENGLISH));
1616
# Test fetching from _source
1717
day_of_week_from_source:
1818
type: keyword
1919
script: |
2020
Instant instant = Instant.ofEpochMilli(params._source.timestamp);
2121
ZonedDateTime dt = ZonedDateTime.ofInstant(instant, ZoneId.of("UTC"));
22-
emit(dt.dayOfWeek.getDisplayName(TextStyle.FULL, Locale.ROOT));
22+
emit(dt.dayOfWeek.getDisplayName(TextStyle.FULL, Locale.ENGLISH));
2323
# Test fetching many values
2424
day_of_week_letters:
2525
type: keyword
@@ -75,7 +75,7 @@ setup:
7575
- match: {sensor.mappings.runtime.day_of_week.type: keyword }
7676
- match:
7777
sensor.mappings.runtime.day_of_week.script.source: |
78-
emit(doc['timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT));
78+
emit(doc['timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ENGLISH));
7979
- match: {sensor.mappings.runtime.day_of_week.script.lang: painless }
8080

8181
# --- TODO get field mappings needs to be adapted
@@ -90,7 +90,7 @@ setup:
9090
# type: keyword
9191
# script:
9292
# source: |
93-
# emit(doc['timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT));
93+
# emit(doc['timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ENGLISH));
9494
# lang: painless
9595
# meta: {}
9696
#
@@ -148,7 +148,7 @@ setup:
148148
day_of_week:
149149
type: keyword
150150
script: |
151-
emit(doc['timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.SHORT, Locale.ROOT));
151+
emit(doc['timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.SHORT, Locale.ENGLISH));
152152
- do:
153153
search:
154154
index: sensor

0 commit comments

Comments
 (0)