Skip to content

Commit d268b49

Browse files
authored
[ML] Mute test failing due to Java 11 date time format parsing bug (#31899)
1 parent dadf96a commit d268b49

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/DataDescription.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ public void setTimeFormat(String format) {
353353
try {
354354
DateTimeFormatterTimestampConverter.ofPattern(format, ZoneOffset.UTC);
355355
} catch (IllegalArgumentException e) {
356-
throw ExceptionsHelper.badRequestException(Messages.getMessage(Messages.JOB_CONFIG_INVALID_TIMEFORMAT, format));
356+
throw ExceptionsHelper.badRequestException(
357+
Messages.getMessage(Messages.JOB_CONFIG_INVALID_TIMEFORMAT, format), e.getCause());
357358
}
358359
}
359360
timeFormat = format;

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/time/DateTimeFormatterTimestampConverter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ public static TimestampConverter ofPattern(String pattern, ZoneId defaultTimezon
5454
.parseDefaulting(ChronoField.YEAR_OF_ERA, LocalDate.now(defaultTimezone).getYear())
5555
.toFormatter();
5656

57-
String now = formatter.format(ZonedDateTime.ofInstant(Instant.ofEpochSecond(0), ZoneOffset.UTC));
57+
String formattedTime = formatter.format(ZonedDateTime.ofInstant(Instant.ofEpochSecond(0), ZoneOffset.UTC));
5858
try {
59-
TemporalAccessor parsed = formatter.parse(now);
59+
TemporalAccessor parsed = formatter.parse(formattedTime);
6060
boolean hasTimeZone = parsed.isSupported(ChronoField.INSTANT_SECONDS);
6161
if (hasTimeZone) {
6262
Instant.from(parsed);
@@ -67,7 +67,7 @@ public static TimestampConverter ofPattern(String pattern, ZoneId defaultTimezon
6767
return new DateTimeFormatterTimestampConverter(formatter, hasTimeZone, defaultTimezone);
6868
}
6969
catch (DateTimeException e) {
70-
throw new IllegalArgumentException("Timestamp cannot be derived from pattern: " + pattern);
70+
throw new IllegalArgumentException("Timestamp cannot be derived from pattern: " + pattern, e);
7171
}
7272
}
7373

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/config/DataDescriptionTests.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import org.elasticsearch.xpack.core.ml.job.config.DataDescription.DataFormat;
1818
import org.elasticsearch.xpack.core.ml.job.messages.Messages;
1919

20+
import java.time.DateTimeException;
21+
2022
import static org.hamcrest.Matchers.containsString;
2123
import static org.hamcrest.Matchers.equalTo;
2224
import static org.hamcrest.Matchers.instanceOf;
@@ -51,8 +53,12 @@ public void testVerify_GivenValidFormat() {
5153
description.setTimeFormat("epoch");
5254
description.setTimeFormat("epoch_ms");
5355
description.setTimeFormat("yyyy-MM-dd HH");
54-
String goodFormat = "yyyy.MM.dd G 'at' HH:mm:ss z";
55-
description.setTimeFormat(goodFormat);
56+
}
57+
58+
@AwaitsFix(bugUrl = "https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8206980")
59+
public void testVerify_GivenValidFormat_Java11Bug() {
60+
DataDescription.Builder description = new DataDescription.Builder();
61+
description.setTimeFormat("yyyy.MM.dd G 'at' HH:mm:ss z");
5662
}
5763

5864
public void testVerify_GivenInValidFormat() {
@@ -68,6 +74,10 @@ public void testVerify_GivenInValidFormat() {
6874
e = expectThrows(ElasticsearchException.class, () -> description.setTimeFormat("y-M-dd"));
6975
assertEquals(Messages.getMessage(Messages.JOB_CONFIG_INVALID_TIMEFORMAT, "y-M-dd"), e.getMessage());
7076
expectThrows(ElasticsearchException.class, () -> description.setTimeFormat("YYY-mm-UU hh:mm:ssY"));
77+
78+
Throwable cause = e.getCause();
79+
assertNotNull(cause);
80+
assertThat(cause, instanceOf(DateTimeException.class));
7181
}
7282

7383
public void testTransform_GivenDelimitedAndEpoch() {

0 commit comments

Comments
 (0)