Author: pgil
Date: Fri Sep 27 13:52:43 2019 New Revision: 1867635 URL: http://svn.apache.org/viewvc?rev=1867635&view=rev Log: Improved: Refactor UelFunctions.java to remove error management via Exception (OFBIZ-11213) This refacto was done to avoid logging stackTrace exception, when it is possible to manage it without exception. Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java?rev=1867635&r1=1867634&r2=1867635&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java Fri Sep 27 13:52:43 2019 @@ -312,199 +312,108 @@ public class UelFunctions { return dateFormat.format(stamp); } - @SuppressWarnings("rawtypes") public static int getSize(Object obj) { - try { - Map map = (Map) obj; - return map.size(); - } catch (Exception e) { - Debug.logError(e, module); + if (null == obj) return 0; + if (obj instanceof Map) { + return ((Map) obj).size(); } - - try { - Collection coll = (Collection) obj; - return coll.size(); - } catch (Exception e) { - Debug.logError(e, module); + if (obj instanceof Collection) { + return ((Collection) obj).size(); } - - try { - String str = (String) obj; - return str.length(); - } catch (Exception e) { - Debug.logError(e, module); + if (obj instanceof String) { + return ((String) obj).length(); } - return -1; } public static boolean endsWith(String str1, String str2) { - try { - return str1.endsWith(str2); - } catch (Exception e) { - Debug.logError(e, module); - } - - return false; + if (null == str1) return false; + return str1.endsWith(str2); } public static int indexOf(String str1, String str2) { - try { - return str1.indexOf(str2); - } catch (Exception e) { - Debug.logError(e, module); - } - - return -1; + if (null == str1) return -1; + return str1.indexOf(str2); } public static int lastIndexOf(String str1, String str2) { - try { - return str1.lastIndexOf(str2); - } catch (Exception e) { - Debug.logError(e, module); - } - - return -1; + if (null == str1) return -1; + return str1.lastIndexOf(str2); } public static int length(String str1) { - try { - return str1.length(); - } catch (Exception e) { - Debug.logError(e, module); - } - - return -1; + if (null == str1) return 0; + return str1.length(); } public static String replace(String str1, String str2, String str3) { - try { - return str1.replace(str2, str3); - } catch (Exception e) { - Debug.logError(e, module); - } - - return null; + if (null == str1) return null; + return str1.replace(str2, str3); } public static String replaceAll(String str1, String str2, String str3) { - try { - return str1.replaceAll(str2, str3); - } catch (Exception e) { - Debug.logError(e, module); - } - - return null; + if (null == str1) return null; + return str1.replaceAll(str2, str3); } public static String replaceFirst(String str1, String str2, String str3) { - try { - return str1.replaceFirst(str2, str3); - } catch (Exception e) { - Debug.logError(e, module); - } - - return null; + if (null == str1) return null; + return str1.replaceFirst(str2, str3); } public static boolean startsWith(String str1, String str2) { - try { - return str1.startsWith(str2); - } catch (Exception e) { - Debug.logError(e, module); - } - - return false; + if (null == str1) return false; + return str1.startsWith(str2); } public static String endString(String str, int index) { - try { - return str.substring(index); - } catch (Exception e) { - Debug.logError(e, module); - } - - return null; + if (null == str) return null; + return str.substring(index); } public static String subString(String str, int beginIndex, int endIndex) { - try { - return str.substring(beginIndex, endIndex); - } catch (Exception e) { - Debug.logError(e, module); - } - - return null; + if (null == str) return null; + return str.substring(beginIndex, endIndex); } public static String trim(String str) { - try { - return str.trim(); - } catch (Exception e) { - Debug.logError(e, module); - } - - return null; + if (null == str) return null; + return str.trim(); } public static String toLowerCase(String str) { - try { - return str.toLowerCase(Locale.getDefault()); - } catch (Exception e) { - Debug.logError(e, module); - } - - return null; + if (null == str) return null; + return str.toLowerCase(Locale.getDefault()); } public static String toUpperCase(String str) { - try { - return str.toUpperCase(Locale.getDefault()); - } catch (Exception e) { - Debug.logError(e, module); - } - - return null; + if (null == str) return null; + return str.toUpperCase(Locale.getDefault()); } public static String toString(Object obj) { + if (null == obj) return null; return obj.toString(); } public static String sysGetEnv(String str) { - try { - return System.getenv(str); - } catch (Exception e) { - Debug.logError(e, module); - } - - return null; + if (null == str) return null; + return System.getenv(str); } public static String sysGetProp(String str) { - try { - return System.getProperty(str); - } catch (Exception e) { - Debug.logError(e, module); - } - - return null; + if (null == str) return null; + return System.getProperty(str); } public static String label(String ressource, String label, Locale locale) { if (locale == null) { locale = Locale.getDefault(); } - try { - String resolveLabel = UtilProperties.getMessage(ressource, label, locale); - if (resolveLabel != null) { - return resolveLabel; - } - } catch (Exception e) { - Debug.logError(e, module); + String resolveLabel = UtilProperties.getMessage(ressource, label, locale); + if (resolveLabel != null) { + return resolveLabel; } - return label; } |
Free forum by Nabble | Edit this page |