Author: jleroux
Date: Sun Sep 15 06:32:42 2019 New Revision: 1866957 URL: http://svn.apache.org/viewvc?rev=1866957&view=rev Log: Fixed: Fix Default or Empty Catch block in Java and Groovy files (OFBIZ-) In many Java and Groovy files we have auto generated catch blocks or empty catch blocks. To avoid such exception swallowing this should be improved to at least log the error and also return error in case of service. Here we use 3 try-with-ressource blocks and log some errors Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/template/XslTransform.java ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/jdbc/JdbcValueHandler.java ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/jms/AbstractJmsListener.java ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/jms/JmsListenerFactory.java ofbiz/ofbiz-framework/trunk/framework/webtools/groovyScripts/log/FetchLogs.groovy ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/UtilCacheEvents.java ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/WebToolsServices.java Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/template/XslTransform.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/template/XslTransform.java?rev=1866957&r1=1866956&r2=1866957&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/template/XslTransform.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/template/XslTransform.java Sun Sep 15 06:32:42 2019 @@ -86,7 +86,9 @@ public final class XslTransform { StreamResult sr = new StreamResult(sw); transformer.transform(source, sr); result = sw.toString(); - } catch (IOException e) {} + } catch (IOException e) { + Debug.logError(e, module); + } } else { Debug.logError("tfactory does not support SAX features!", module); } Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/jdbc/JdbcValueHandler.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/jdbc/JdbcValueHandler.java?rev=1866957&r1=1866956&r2=1866957&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/jdbc/JdbcValueHandler.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/jdbc/JdbcValueHandler.java Sun Sep 15 06:32:42 2019 @@ -192,19 +192,11 @@ public abstract class JdbcValueHandler<T protected static byte[] serializeObject(Object obj) throws SQLException { ByteArrayOutputStream os = new ByteArrayOutputStream(); - ObjectOutputStream oos = null; try { - oos = new ObjectOutputStream(os); + ObjectOutputStream oos = new ObjectOutputStream(os); oos.writeObject(obj); - os.close(); } catch (IOException e) { throw new SQLException(e); - } finally { - if (oos != null) { - try { - oos.close(); - } catch (IOException e) {} - } } return os.toByteArray(); } @@ -448,9 +440,8 @@ public abstract class JdbcValueHandler<T if (clob == null || clob.length() == 0) { return null; } - Reader clobReader = null; - try { - clobReader = clob.getCharacterStream(); + try (Reader clobReader = clob.getCharacterStream()) { + int clobLength = (int) clob.length(); char[] charBuffer = new char[clobLength]; int offset = 0; @@ -466,13 +457,6 @@ public abstract class JdbcValueHandler<T } catch (IOException e) { throw new SQLException(e); } - finally { - if (clobReader != null) { - try { - clobReader.close(); - } catch (IOException e) {} - } - } } @Override protected JdbcValueHandler<Object> newInstance(int sqlType) { @@ -627,9 +611,8 @@ public abstract class JdbcValueHandler<T @Override public Object getValue(ResultSet rs, int columnIndex) throws SQLException { ObjectInputStream in = null; - InputStream bis = null; - try { - bis = rs.getBinaryStream(columnIndex); + try (InputStream bis = rs.getBinaryStream(columnIndex)) { + if (bis == null) { return null; } @@ -641,12 +624,9 @@ public abstract class JdbcValueHandler<T if (in != null) { try { in.close(); - } catch (IOException e) {} - } - if (bis != null) { - try { - bis.close(); - } catch (IOException e) {} + } catch (IOException e) { + Debug.logError(e, module); + } } } } Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/jms/AbstractJmsListener.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/jms/AbstractJmsListener.java?rev=1866957&r1=1866956&r2=1866957&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/jms/AbstractJmsListener.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/jms/AbstractJmsListener.java Sun Sep 15 06:32:42 2019 @@ -138,7 +138,9 @@ public abstract class AbstractJmsListene } catch (GenericServiceException e) { try { Thread.sleep(10000); - } catch (InterruptedException ie) {} + } catch (InterruptedException ie) { + Debug.logError(ie, module); + } continue; } } Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/jms/JmsListenerFactory.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/jms/JmsListenerFactory.java?rev=1866957&r1=1866956&r2=1866957&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/jms/JmsListenerFactory.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/jms/JmsListenerFactory.java Sun Sep 15 06:32:42 2019 @@ -89,7 +89,9 @@ public class JmsListenerFactory implemen firstPass = false; try { Thread.sleep(20000); - } catch (InterruptedException ie) {} + } catch (InterruptedException ie) { + Debug.logError(ie, module); + } continue; } Debug.logInfo("JMS Listener Factory Thread Finished; All listeners connected.", module); Modified: ofbiz/ofbiz-framework/trunk/framework/webtools/groovyScripts/log/FetchLogs.groovy URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/groovyScripts/log/FetchLogs.groovy?rev=1866957&r1=1866956&r2=1866957&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/webtools/groovyScripts/log/FetchLogs.groovy (original) +++ ofbiz/ofbiz-framework/trunk/framework/webtools/groovyScripts/log/FetchLogs.groovy Sun Sep 15 06:32:42 2019 @@ -64,6 +64,8 @@ if (parameters.logFileName && logFileNam } logLines.add([type: type, line:line]) } - } catch (Exception exc) {} + } catch (Exception e) { + Debug.logError(e, "FetchLogs.groovy"); + } context.logLines = logLines } Modified: ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/UtilCacheEvents.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/UtilCacheEvents.java?rev=1866957&r1=1866956&r2=1866957&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/UtilCacheEvents.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/UtilCacheEvents.java Sun Sep 15 06:32:42 2019 @@ -19,11 +19,10 @@ package org.apache.ofbiz.webtools; import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; import java.util.Locale; +import java.util.List; import java.util.Map; - +import java.util.LinkedList; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; Modified: ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/WebToolsServices.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/WebToolsServices.java?rev=1866957&r1=1866956&r2=1866957&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/WebToolsServices.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/WebToolsServices.java Sun Sep 15 06:32:42 2019 @@ -1027,7 +1027,9 @@ public class WebToolsServices { if (bundle != null) { try { entityDescription = bundle.getString("EntityDescription." + entity.getEntityName()); - } catch (Exception exception) {} + } catch (Exception exception) { + Debug.logError(exception, module); + } } if (UtilValidate.isEmpty(entityDescription)) { entityDescription = entity.getDescription(); @@ -1046,7 +1048,9 @@ public class WebToolsServices { if (bundle != null) { try { fieldDescription = bundle.getString("FieldDescription." + entity.getEntityName() + "." + field.getName()); - } catch (Exception exception) {} + } catch (Exception exception) { + Debug.logError(exception, module); + } } if (UtilValidate.isEmpty(fieldDescription)) { fieldDescription = field.getDescription(); @@ -1054,7 +1058,9 @@ public class WebToolsServices { if (UtilValidate.isEmpty(fieldDescription) && bundle != null) { try { fieldDescription = bundle.getString("FieldDescription." + field.getName()); - } catch (Exception exception) {} + } catch (Exception exception) { + Debug.logError(exception, module); + } } if (UtilValidate.isEmpty(fieldDescription)) { fieldDescription = ModelUtil.javaNameToDbName(field.getName()).toLowerCase(); |
Free forum by Nabble | Edit this page |