This is an automated email from the ASF dual-hosted git repository. shaofengshi pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/kylin.git
The following commit(s) were added to refs/heads/master by this push: new 6bc2aae KYLIN-3836 fix Kylin StringUtil.join() may cause NPE if iterator is empty 6bc2aae is described below commit 6bc2aaeb7032aa89feed91316a2179263c4c4c35 Author: chao long <wayn...@qq.com> AuthorDate: Thu Feb 28 12:18:40 2019 +0800 KYLIN-3836 fix Kylin StringUtil.join() may cause NPE if iterator is empty --- .../org/apache/kylin/common/util/StringUtil.java | 38 +++++++++++++--------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/core-common/src/main/java/org/apache/kylin/common/util/StringUtil.java b/core-common/src/main/java/org/apache/kylin/common/util/StringUtil.java index 31f9a14..5dde9cf 100644 --- a/core-common/src/main/java/org/apache/kylin/common/util/StringUtil.java +++ b/core-common/src/main/java/org/apache/kylin/common/util/StringUtil.java @@ -75,26 +75,34 @@ public class StringUtil { } public static String join(Iterable<String> parts, String separator) { - StringBuilder buf = new StringBuilder(); - Iterator<String> iterator = parts.iterator(); - if (iterator == null || (!iterator.hasNext())) { + if (parts == null) { return null; } - final String first = iterator.next(); - if (first != null) { - buf.append(first); - } - while (iterator.hasNext()) { - if (separator != null) { - buf.append(separator); + + Iterator<String> iterator = parts.iterator(); + + if (iterator == null) { + return null; + } else if (!iterator.hasNext()) { + return ""; + } else { + StringBuilder buf = new StringBuilder(); + final String first = iterator.next(); + if (first != null) { + buf.append(first); } - final String part = iterator.next(); - if (part != null) { - buf.append(part); + while (iterator.hasNext()) { + if (separator != null) { + buf.append(separator); + } + final String part = iterator.next(); + if (part != null) { + buf.append(part); + } } - } - return buf.toString(); + return buf.toString(); + } } public static void toUpperCaseArray(String[] source, String[] target) {