From 7d7f8d044dde57c71881b99a51e503bf8f799f12 Mon Sep 17 00:00:00 2001 From: Markus Rathgeb Date: Thu, 20 Jun 2019 21:34:18 +0200 Subject: [PATCH] don't fail on nullable locale (currently not forbidden) (#886) Signed-off-by: Markus Rathgeb --- .../core/voice/text/AbstractRuleBasedInterpreter.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bundles/org.openhab.core.voice/src/main/java/org/eclipse/smarthome/core/voice/text/AbstractRuleBasedInterpreter.java b/bundles/org.openhab.core.voice/src/main/java/org/eclipse/smarthome/core/voice/text/AbstractRuleBasedInterpreter.java index 5001d07d1e..1acc27e325 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/eclipse/smarthome/core/voice/text/AbstractRuleBasedInterpreter.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/eclipse/smarthome/core/voice/text/AbstractRuleBasedInterpreter.java @@ -585,16 +585,17 @@ public abstract class AbstractRuleBasedInterpreter implements HumanLanguageInter * @return resulting tokens */ protected ArrayList tokenize(Locale locale, String text) { + final Locale localeSafe = locale != null ? locale : Locale.getDefault(); ArrayList parts = new ArrayList(); if (text == null) { return parts; } String[] split; - if ((locale != null) && locale.getLanguage().equalsIgnoreCase(Locale.FRENCH.getLanguage())) { - split = text.toLowerCase(locale).replaceAll("[\\']", " ").replaceAll("[^\\w\\sàâäçéèêëîïôùûü]", " ") + if (localeSafe.getLanguage().equalsIgnoreCase(Locale.FRENCH.getLanguage())) { + split = text.toLowerCase(localeSafe).replaceAll("[\\']", " ").replaceAll("[^\\w\\sàâäçéèêëîïôùûü]", " ") .split("\\s"); } else { - split = text.toLowerCase(locale).replaceAll("[\\']", "").replaceAll("[^\\w\\s]", " ").split("\\s"); + split = text.toLowerCase(localeSafe).replaceAll("[\\']", "").replaceAll("[^\\w\\s]", " ").split("\\s"); } for (int i = 0; i < split.length; i++) { String part = split[i].trim();