From 32f122871b81f0944f1142802fdcf828d9ac1563 Mon Sep 17 00:00:00 2001 From: Houston Putman Date: Fri, 31 Jan 2025 16:48:08 -0600 Subject: [PATCH] SOLR-17379: Fix date parsing in Java 23, remove Lucene TestSecurityManager Co-authored-by: Chris Hostetter --- gradle/testing/randomization.gradle | 2 +- .../ParseDateFieldUpdateProcessorFactory.java | 8 ++- .../ParsingFieldUpdateProcessorsTest.java | 57 +++++++++---------- 3 files changed, 35 insertions(+), 32 deletions(-) diff --git a/gradle/testing/randomization.gradle b/gradle/testing/randomization.gradle index d3ae962c144..6d2cb2791ac 100644 --- a/gradle/testing/randomization.gradle +++ b/gradle/testing/randomization.gradle @@ -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('\\', '/') diff --git a/solr/core/src/java/org/apache/solr/update/processor/ParseDateFieldUpdateProcessorFactory.java b/solr/core/src/java/org/apache/solr/update/processor/ParseDateFieldUpdateProcessorFactory.java index f06f4a4af68..69b9af7e990 100644 --- a/solr/core/src/java/org/apache/solr/update/processor/ParseDateFieldUpdateProcessorFactory.java +++ b/solr/core/src/java/org/apache/solr/update/processor/ParseDateFieldUpdateProcessorFactory.java @@ -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); } } } diff --git a/solr/core/src/test/org/apache/solr/update/processor/ParsingFieldUpdateProcessorsTest.java b/solr/core/src/test/org/apache/solr/update/processor/ParsingFieldUpdateProcessorsTest.java index 7e78a49da9c..8dfee5606a5 100644 --- a/solr/core/src/test/org/apache/solr/update/processor/ParsingFieldUpdateProcessorsTest.java +++ b/solr/core/src/test/org/apache/solr/update/processor/ParsingFieldUpdateProcessorsTest.java @@ -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; @@ -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 = @@ -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 {