You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ds...@apache.org on 2018/08/30 13:54:09 UTC

lucene-solr:master: 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.

Repository: lucene-solr
Updated Branches:
  refs/heads/master 86ba65c10 -> 4096decd8


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.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/4096decd
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/4096decd
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/4096decd

Branch: refs/heads/master
Commit: 4096decd8f6e496d2307d4c1c4eccefbfcd8f74a
Parents: 86ba65c
Author: David Smiley <ds...@apache.org>
Authored: Thu Aug 30 09:53:43 2018 -0400
Committer: David Smiley <ds...@apache.org>
Committed: Thu Aug 30 09:53:43 2018 -0400

----------------------------------------------------------------------
 solr/CHANGES.txt                                    |  3 ++-
 .../ParseDateFieldUpdateProcessorFactory.java       | 16 ++++++++++++----
 .../solrconfig-parsing-update-processor-chains.xml  |  3 ---
 .../processor/ParsingFieldUpdateProcessorsTest.java |  9 +++++++--
 4 files changed, 21 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/4096decd/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 190ac12..afa7b11 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -57,7 +57,8 @@ New Features
 
 SOLR-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 Changes

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/4096decd/solr/core/src/java/org/apache/solr/update/processor/ParseDateFieldUpdateProcessorFactory.java
----------------------------------------------------------------------
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 2561fdb..c7aaaaf 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 &lt;str&gt;
  * elements or &lt;arr&gt;-s of &lt;str&gt; 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
   @Override
   public 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);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/4096decd/solr/core/src/test-files/solr/collection1/conf/solrconfig-parsing-update-processor-chains.xml
----------------------------------------------------------------------
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.xml
index b552c5c..43f2d28 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>

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/4096decd/solr/core/src/test/org/apache/solr/update/processor/ParsingFieldUpdateProcessorsTest.java
----------------------------------------------------------------------
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 2448f92..02f6ebd 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 {