Apache Lucene open-source search software
SOLR-9430: Fix locale lookup in DIH <propertyWriter/> to use BCP47 language tags to be consistent with other places in Solr. Language names still work for backwards compatibility
Uwe Schindlere99d9706741e
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 62c6d5f34d2..824cdaecd8b 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -83,6 +83,10 @@ Bug Fixes* SOLR-9439: Shard split clean up logic for older failed splits is faulty. (shalin)+* SOLR-9430: Fix locale lookup in DIH <propertyWriter/> to use BCP47 language tags+ to be consistent with other places in Solr. Language names still work for backwards+ compatibility. (Uwe Schindler, Boris Steiner)+Optimizations----------------------diff --git a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SimplePropertiesWriter.java b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SimplePropertiesWriter.javaindex 92527bb46e0..1ee18eff696 100644--- a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SimplePropertiesWriter.java+++ b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SimplePropertiesWriter.java@@ -30,11 +30,13 @@ import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;import java.util.HashMap;+import java.util.IllformedLocaleException;import java.util.Locale;import java.util.Map;import java.util.Properties;import org.apache.lucene.util.IOUtils;+import org.apache.solr.common.util.SuppressForbidden;import org.apache.solr.core.SolrCore;import org.apache.solr.core.SolrResourceLoader;import org.slf4j.Logger;@@ -90,16 +92,7 @@ public class SimplePropertiesWriter extends DIHProperties {}findDirectory(dataImporter, params);if(params.get(LOCALE) != null) {- String localeStr = params.get(LOCALE);- for (Locale l : Locale.getAvailableLocales()) {- if(localeStr.equals(l.getDisplayName(Locale.ROOT))) {- locale = l;- break;- }- }- if(locale==null) {- throw new DataImportHandlerException(SEVERE, "Unsupported locale for PropertWriter: " + localeStr);- }+ locale = getLocale(params.get(LOCALE));} else {locale = Locale.ROOT;}@@ -108,7 +101,25 @@ public class SimplePropertiesWriter extends DIHProperties {} else {dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", locale);}- }+ }++ @SuppressForbidden(reason = "Usage of outdated locale parsing with Locale#toString() because of backwards compatibility")+ private Locale getLocale(String name) {+ if (name == null) {+ return Locale.ROOT;+ }+ for (final Locale l : Locale.getAvailableLocales()) {+ if(name.equals(l.toString()) || name.equals(l.getDisplayName(Locale.ROOT))) {+ return locale;+ }+ }+ try {+ return new Locale.Builder().setLanguageTag(name).build();+ } catch (IllformedLocaleException ex) {+ throw new DataImportHandlerException(SEVERE, "Unsupported locale for PropertyWriter: " + name);+ }+ }+protected void findDirectory(DataImporter dataImporter, Map<String, String> params) {if(params.get(DIRECTORY) != null) {configDir = params.get(DIRECTORY);