Skip to content

Commit

Permalink
SOLR-17379: Fix date parsing in Java 23, remove Lucene TestSecurityMa…
Browse files Browse the repository at this point in the history
…nager

Co-authored-by: Chris Hostetter <[email protected]>
  • Loading branch information
HoustonPutman and hossman committed Jan 31, 2025
1 parent dac5fe1 commit 32f1228
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 32 deletions.
2 changes: 1 addition & 1 deletion gradle/testing/randomization.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ allprojects {
javaSecurityPolicy: javaSecurityPolicy
)
)
systemProperty 'java.security.manager', "org.apache.lucene.tests.util.TestSecurityManager"
systemProperty 'java.security.manager', "default"

def gradleUserHome = project.gradle.getGradleUserHomeDir()
systemProperty 'gradle.lib.dir', Paths.get(project.class.location.toURI()).parent.toAbsolutePath().toString().replace('\\', '/')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,13 @@ public static Object parsePossibleDate(
return Date.from(parseInstant(parser, srcStringVal, parsePosition));
} catch (DateTimeParseException e) {
if (log.isDebugEnabled()) {
log.debug("value '{}' is not parseable with format '{}'", srcStringVal, parser);
log.debug(
"value '{}' is not parseable with format '{}' (using {} + {})",
srcStringVal,
parser,
parser.getLocale(),
parser.getZone(),
e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.temporal.TemporalAccessor;
import java.util.Date;
import java.util.HashMap;
Expand All @@ -41,6 +42,8 @@
/**
* Tests for the field mutating update processors that parse Dates, Longs, Doubles, and Booleans.
*/
@org.apache.solr.util.LogLevel(
"org.apache.solr.update.processor.ParseDateFieldUpdateProcessorFactory=DEBUG") // nocommit
public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase {
private static final double EPSILON = 1E-15;
private static final DateTimeFormatter isoDateOptionalTimeFormatter =
Expand Down Expand Up @@ -1064,43 +1067,37 @@ public void testAKSTZone() throws IOException {
final String inputString = "Thu Nov 13 04:35:51 AKST 2008"; // asctime + timezone1

final long expectTs = 1226583351000L;
assertEquals(
expectTs,
DateTimeFormatter.ofPattern(dateFormat, Locale.ENGLISH)
.withZone(ZoneId.of("UTC"))
.parse(inputString, Instant::from)
.toEpochMilli());

// ensure english locale and root locale return the same date
assertEquals(
expectTs + "",
DateTimeFormatter.ofPattern(dateFormat, Locale.ENGLISH)
.withZone(ZoneId.of("UTC"))
.parse(inputString, Instant::from)
.toEpochMilli(),
DateTimeFormatter.ofPattern(dateFormat, Locale.ROOT)
.withZone(ZoneId.of("UTC"))
.parse(inputString, Instant::from)
.toEpochMilli());
try {
// ensure english locale and root locale return the same date
assertEquals(
expectTs,
DateTimeFormatter.ofPattern(dateFormat, Locale.ENGLISH)
.withZone(ZoneId.of("UTC"))
.parse(inputString, Instant::from)
.toEpochMilli());

assertEquals(
expectTs,
DateTimeFormatter.ofPattern(dateFormat, Locale.ROOT)
.withZone(ZoneId.of("UTC"))
.parse(inputString, Instant::from)
.toEpochMilli());
} catch (DateTimeParseException e) {
// If the JVM's java.locale.providers can't parse these, there is no hope of this test passing
assumeNoException("JVM's Locale provider is incompatible with this test", e);
}

assertParsedDate(
inputString,
Date.from(Instant.ofEpochMilli(expectTs)),
"parse-date-patterns-default-config");

// A bug in Java 9 (not in 8) causes this to fail! (not fixed yet?!)
// see https://bugs.openjdk.java.net/browse/JDK-8189784
if (System.getProperty("java.version").startsWith("1.8.")) {
// with daylight savings time timezone
assertParsedDate(
"Fri Oct 7 05:14:15 AKDT 2005",
Date.from(inst20051007131415()),
"parse-date-patterns-default-config");
} else {
System.err.println(
"Didn't test AKDT because only Java 1.8 does this right! This Java version is: "
+ System.getProperty("java.version"));
}
// with daylight savings time timezone
assertParsedDate(
"Fri Oct 7 05:14:15 AKDT 2005",
Date.from(inst20051007131415()),
"parse-date-patterns-default-config");
}

public void testEDTZone() throws IOException {
Expand Down

0 comments on commit 32f1228

Please sign in to comment.