Skip to content

Commit 160d1bd

Browse files
authored
Work around JDK8 timezone bug in tests (#37968)
The timezone GMT0 cannot be properly parsed on java8. The randomZone() method now excludes GMT0, if java8 is used. Closes #37814
1 parent 1a93976 commit 160d1bd

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

server/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,14 +426,11 @@ public void testDateRangeInQueryString() {
426426
assertThat(e.toString(), containsString("unit [D] not supported for date math"));
427427
}
428428

429-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/37814")
430429
// Issue #7880
431430
public void testDateRangeInQueryStringWithTimeZone_7880() {
432431
//the mapping needs to be provided upfront otherwise we are not sure how many failures we get back
433432
//as with dynamic mappings some shards might be lacking behind and parse a different query
434-
assertAcked(prepareCreate("test").addMapping(
435-
"type", "past", "type=date"
436-
));
433+
assertAcked(prepareCreate("test").addMapping("type", "past", "type=date"));
437434

438435
ZoneId timeZone = randomZone();
439436
String now = DateFormatter.forPattern("strict_date_optional_time").format(Instant.now().atZone(timeZone));

test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.apache.lucene.util.TimeUnits;
4949
import org.elasticsearch.Version;
5050
import org.elasticsearch.bootstrap.BootstrapForTesting;
51+
import org.elasticsearch.bootstrap.JavaVersion;
5152
import org.elasticsearch.client.Requests;
5253
import org.elasticsearch.cluster.ClusterModule;
5354
import org.elasticsearch.cluster.metadata.IndexMetaData;
@@ -784,7 +785,17 @@ public static TimeZone randomTimeZone() {
784785
* generate a random TimeZone from the ones available in java.time
785786
*/
786787
public static ZoneId randomZone() {
787-
return ZoneId.of(randomFrom(JAVA_ZONE_IDS));
788+
// work around a JDK bug, where java 8 cannot parse the timezone GMT0 back into a temporal accessor
789+
// see https://bugs.openjdk.java.net/browse/JDK-8138664
790+
if (JavaVersion.current().getVersion().get(0) == 8) {
791+
ZoneId timeZone;
792+
do {
793+
timeZone = ZoneId.of(randomFrom(JAVA_ZONE_IDS));
794+
} while (timeZone.equals(ZoneId.of("GMT0")));
795+
return timeZone;
796+
} else {
797+
return ZoneId.of(randomFrom(JAVA_ZONE_IDS));
798+
}
788799
}
789800

790801
/**

0 commit comments

Comments
 (0)