diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/SerDeStorageSchemaReader.java b/metastore/src/java/org/apache/hadoop/hive/metastore/SerDeStorageSchemaReader.java index 59bcd5c..da7f070 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/SerDeStorageSchemaReader.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/SerDeStorageSchemaReader.java @@ -23,7 +23,6 @@ import org.apache.hadoop.hive.metastore.api.FieldSchema; import org.apache.hadoop.hive.metastore.api.MetaException; import org.apache.hadoop.hive.metastore.api.Table; -import org.apache.hadoop.hive.metastore.utils.StringUtils; import java.util.List; @@ -47,7 +46,6 @@ Deserializer s = HiveMetaStoreUtils.getDeserializer(conf, tbl, false); return HiveMetaStoreUtils.getFieldsFromDeserializer(tbl.getTableName(), s); } catch (Exception e) { - StringUtils.stringifyException(e); throw new MetaException(e.getMessage()); } finally { if (orgHiveLoader != null) { diff --git a/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/utils/StringUtils.java b/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/utils/StringUtils.java index e49a423..44f2d67 100644 --- a/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/utils/StringUtils.java +++ b/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/utils/StringUtils.java @@ -17,9 +17,8 @@ */ package org.apache.hadoop.hive.metastore.utils; -import java.io.PrintWriter; -import java.io.StringWriter; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -27,12 +26,17 @@ import java.util.Map; import java.util.Set; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.ArrayUtils; + public class StringUtils { /** * Return the internalized string, or null if the given string is null. + * * @param str The string to intern - * @return The identical string cached in the string pool. + * @return The identical string cached in the string pool */ public static String intern(String str) { if (str == null) { @@ -43,33 +47,28 @@ public static String intern(String str) { /** * Return an interned list with identical contents as the given list. + * * @param list The list whose strings will be interned - * @return An identical list with its strings interned. + * @return An identical list with its strings interned */ - public static List intern(List list) { - if(list == null) { - return null; + public static List intern(final List list) { + if (CollectionUtils.isEmpty(list)) { + return Collections.emptyList(); } List newList = new ArrayList<>(list.size()); - for(String str : list) { - newList.add(intern(str)); - } + list.forEach(item -> newList.add(intern(item))); return newList; } /** * Return an interned map with identical contents as the given map. + * * @param map The map whose strings will be interned - * @return An identical map with its strings interned. + * @return An identical map with its strings interned */ - public static Map intern(Map map) { - if (map == null) { - return null; - } - - if (map.isEmpty()) { - // nothing to intern - return map; + public static Map intern(final Map map) { + if (MapUtils.isEmpty(map)) { + return Collections.emptyMap(); } Map newMap = new HashMap<>(map.size()); for (Map.Entry entry : map.entrySet()) { @@ -78,52 +77,53 @@ public static String intern(String str) { return newMap; } + /** + * Returns a set given a list of strings. Returned strings are interned. + * + * @param elements The strings whose strings will be interned + * @return A set of interned strings + */ public static Set asSet(String... elements) { - if (elements == null) return new HashSet<>(); - Set set = new HashSet<>(elements.length); - Collections.addAll(set, elements); - return set; + if (ArrayUtils.isEmpty(elements)) { + return Collections.emptySet(); + } + return new HashSet<>(intern(Arrays.asList(elements))); } /** * Normalize all identifiers to make equality comparisons easier. + * * @param identifier identifier * @return normalized version, with white space removed and all lower case. */ public static String normalizeIdentifier(String identifier) { - return identifier.trim().toLowerCase(); - } - - /** - * Make a string representation of the exception. - * @param e The exception to stringify - * @return A string with exception name and call stack. - */ - public static String stringifyException(Throwable e) { - StringWriter stm = new StringWriter(); - PrintWriter wrt = new PrintWriter(stm); - e.printStackTrace(wrt); - wrt.close(); - return stm.toString(); + return (identifier == null) ? null : identifier.trim().toLowerCase(); } /** * Given an array of bytes it will convert the bytes to a hex string * representation of the bytes. + * + * @deprecated Use {@link org.apache.hadoop.util.StringUtils} * @param bytes Input bytes * @param start start index, inclusively * @param end end index, exclusively * @return hex string representation of the byte array */ + @Deprecated public static String byteToHexString(byte[] bytes, int start, int end) { - return org.apache.hadoop.util.StringUtils.byteToHexString(bytes, start, end); + return org.apache.hadoop.util.StringUtils.byteToHexString(bytes, start, + end); } /** - * Checks if the input string/char sequence is empty + * Checks if the input string/char sequence is empty. + * + * @deprecated Use {@link org.apache.commons.lang.StringUtils#isEmpty(String)} * @param cs Input char sequence * @return true if empty and false if not */ + @Deprecated public static boolean isEmpty(CharSequence cs) { return cs == null || cs.length() == 0; } diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ReplChangeManager.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ReplChangeManager.java index ac1d3c8..985186b 100644 --- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ReplChangeManager.java +++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ReplChangeManager.java @@ -152,7 +152,7 @@ private ReplChangeManager(Configuration conf) throws MetaException { inited = true; } } catch (IOException e) { - throw new MetaException(StringUtils.stringifyException(e)); + throw new MetaException(e.getMessage()); } } @@ -341,7 +341,7 @@ public static FileInfo getFileInfo(Path src, String checksumString, String srcCM return new FileInfo(srcFs, src, cmPath, checksumString, false, subDir); } } catch (IOException e) { - throw new MetaException(StringUtils.stringifyException(e)); + throw new MetaException(e.getMessage()); } } @@ -440,20 +440,18 @@ public void run() { } else { boolean succ = fs.delete(file.getPath(), false); if (succ) { - if (LOG.isDebugEnabled()) { - LOG.debug("Remove " + file.toString()); - } + LOG.debug("Remove {}", file); } else { - LOG.warn("Fail to remove " + file.toString()); + LOG.warn("Fail to remove {}", file); } } } catch (UnsupportedOperationException e) { - LOG.warn("Error getting xattr for " + file.getPath().toString()); + LOG.warn("Error getting xattr for {}", file.getPath()); } } } } catch (IOException e) { - LOG.error("Exception when clearing cmroot:" + StringUtils.stringifyException(e)); + LOG.error("Exception when clearing cmroot", e); } } }