Apache Lucene open-source search software
SOLR-12591: ParseDateField URP should default to "en_US" locale (not ROOT) which is implied by common formats. Should fix Java 9,10,11 test fails; Java 8 continues to work.
David Smiley4096decd8f6e
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 190ac123e84..afa7b119a46 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -57,7 +57,8 @@ New FeaturesSOLR-12591: Expand the set of recognized date format patterns of schemaless mode to subsume those handled by the"extract" contrib (Solr Cell / Tika). This is primarily a change in configuration of the default configSet for more- patterns, but also included enabling "lenient" parsing in ParseDateFieldUpdateProcessorFactory.+ patterns, but also included enabling "lenient" parsing in ParseDateFieldUpdateProcessorFactory. The default+ locale was changed from ROOT to en_US since well-known patterns assume this locale.(David Smiley, Bar Rotstein)Other Changesdiff --git a/solr/core/src/java/org/apache/solr/update/processor/ParseDateFieldUpdateProcessorFactory.java b/solr/core/src/java/org/apache/solr/update/processor/ParseDateFieldUpdateProcessorFactory.javaindex 2561fdb904f..c7aaaaf20a4 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@@ -81,8 +81,10 @@ import org.slf4j.LoggerFactory;* </p>* <p>* The locale to use when parsing field values using the specified formats may- * optionally be specified. If no locale is configured, then {@link Locale#ROOT}- * will be used. The following configuration specifies the French/France locale and+ * optionally be specified. If no locale is configured, then {@code en_US}+ * will be used since it's implied by some well-known formats. Recent versions of Java+ * have become sensitive to this.+ * The following configuration specifies the French/France locale and* two date formats that will parse the strings "le mardi 8 janvier 2013" and* "le 28 déc. 2010 à 15 h 30", respectively. Note that either individual <str>* elements or <arr>-s of <str> elements may be used to specify the@@ -103,6 +105,11 @@ import org.slf4j.LoggerFactory;* See {@link Locale} for a description of acceptable language, country (optional)* and variant (optional) values, joined with underscore(s).* </p>+ *+ * <p>+ * Tip: you can use multiple instances of this URP in your chain with different locales or+ * default time zones if you wish to vary those settings for different format patterns.+ * </p>* @since 4.4.0*/public class ParseDateFieldUpdateProcessorFactory extends FieldMutatingUpdateProcessorFactory {@@ -156,11 +163,12 @@ public class ParseDateFieldUpdateProcessorFactory extends FieldMutatingUpdatePro@Overridepublic void init(NamedList args) {- Locale locale = Locale.ROOT;-+ Locale locale;String localeParam = (String)args.remove(LOCALE_PARAM);if (null != localeParam) {locale = LocaleUtils.toLocale(localeParam);+ } else {+ locale = LocaleUtils.toLocale("en_US"); // because well-known patterns assume this}Object defaultTimeZoneParam = args.remove(DEFAULT_TIME_ZONE_PARAM);diff --git a/solr/core/src/test-files/solr/collection1/conf/solrconfig-parsing-update-processor-chains.xml b/solr/core/src/test-files/solr/collection1/conf/solrconfig-parsing-update-processor-chains.xmlindex b552c5c434b..43f2d285a9f 100644--- a/solr/core/src/test-files/solr/collection1/conf/solrconfig-parsing-update-processor-chains.xml+++ b/solr/core/src/test-files/solr/collection1/conf/solrconfig-parsing-update-processor-chains.xml@@ -64,7 +64,6 @@<updateRequestProcessorChain name="parse-date-non-UTC-defaultTimeZone"><processor class="solr.ParseDateFieldUpdateProcessorFactory"><str name="defaultTimeZone">America/New_York</str>- <str name="locale">en_US</str><str name="format">yyyy-MM-dd'T'HH:mm:ss.SSS[z]</str></processor><processor class="solr.RunUpdateProcessorFactory" />@@ -81,8 +80,6 @@<updateRequestProcessorChain name="parse-date-many-formats-no-run-processor"><processor class="solr.ParseDateFieldUpdateProcessorFactory">- <str name="defaultTimeZone">UTC</str>- <str name="locale">en_US</str><arr name="format"><str>yyyy-MM-dd'T'HH:mm[:ss[.SSS]][z</str><str>yyyy-MM-dd'T'HH:mm[:ss[,SSS]][z</str>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.javaindex 2448f925644..02f6ebdb295 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@@ -963,9 +963,14 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase {assertParsedDate(inputString, Date.from(Instant.ofEpochMilli(expectTs)), "parse-date-patterns-default-config");- // We might also test AKDT, but a bug in Java 9 (not in 8) causes this to fail- //assertParsedDate("Fri Oct 7 05:14:15 AKDT 2005", Date.from(inst20051007131415()), "parse-date-patterns-default-config"); // with timezone (not asctime) in DST+ // 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"));+ }}public void testEDTZone() throws IOException {