svn commit: r1866958 - in /ofbiz/ofbiz-framework/trunk: applications/product/groovyScripts/facility/facility/ framework/base/src/test/java/org/apache/ofbiz/base/util/ framework/entity/src/main/java/org/apache/ofbiz/entity/test/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1866958 - in /ofbiz/ofbiz-framework/trunk: applications/product/groovyScripts/facility/facility/ framework/base/src/test/java/org/apache/ofbiz/base/util/ framework/entity/src/main/java/org/apache/ofbiz/entity/test/

jleroux@apache.org
Author: jleroux
Date: Sun Sep 15 07:48:09 2019
New Revision: 1866958

URL: http://svn.apache.org/viewvc?rev=1866958&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.

Last ones :)

Modified:
    ofbiz/ofbiz-framework/trunk/applications/product/groovyScripts/facility/facility/CountFacilityInventoryByProduct.groovy
    ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/AssertTests.java
    ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/test/EntityTestSuite.java

Modified: ofbiz/ofbiz-framework/trunk/applications/product/groovyScripts/facility/facility/CountFacilityInventoryByProduct.groovy
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/groovyScripts/facility/facility/CountFacilityInventoryByProduct.groovy?rev=1866958&r1=1866957&r2=1866958&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/product/groovyScripts/facility/facility/CountFacilityInventoryByProduct.groovy (original)
+++ ofbiz/ofbiz-framework/trunk/applications/product/groovyScripts/facility/facility/CountFacilityInventoryByProduct.groovy Sun Sep 15 07:48:09 2019
@@ -360,7 +360,9 @@ if (action) {
         if (prodsEli != null) {
             try {
                 prodsEli.close()
-            } catch (Exception exc) {}
+            } catch (Exception exc) {
+                Debug.logError(exception, module);
+            }
         }
         // only commit the transaction if we started one... this will throw an exception if it fails
         TransactionUtil.commit(beganTransaction)

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/AssertTests.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/AssertTests.java?rev=1866958&r1=1866957&r2=1866958&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/AssertTests.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/AssertTests.java Sun Sep 15 07:48:09 2019
@@ -23,13 +23,13 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.ofbiz.base.util.Assert;
 import org.junit.Test;
 
 /**
  * Assert tests {@link org.apache.ofbiz.base.util.Assert}.
  */
 public class AssertTests {
+    public static final String module = AssertTests.class.getName();
 
     @Test
     public void testAssert(){
@@ -44,7 +44,10 @@ public class AssertTests {
         try {
             Assert.notNull("foo", null);
             fail("notNull - IllegalArgumentException not thrown");
-        } catch (IllegalArgumentException e) {}
+        } catch (IllegalArgumentException e) {
+            Debug.logError(e, module);
+        }
+
 
         //-----------------------------------------------------------------------
         try {
@@ -55,7 +58,10 @@ public class AssertTests {
         try {
             Assert.notNull("foo", testObject, "bar", null);
             fail("notNull (argument list) - IllegalArgumentException not thrown");
-        } catch (IllegalArgumentException e) {}
+        } catch (IllegalArgumentException e) {
+            Debug.logError(e, module);
+        }
+
 
         //-----------------------------------------------------------------------
         try {
@@ -66,7 +72,10 @@ public class AssertTests {
         try {
             Assert.notEmpty("foo", "");
             fail("notEmpty(String) - IllegalArgumentException not thrown");
-        } catch (IllegalArgumentException e) {}
+        } catch (IllegalArgumentException e) {
+            Debug.logError(e, module);
+        }
+
 
         //-----------------------------------------------------------------------
         String[] strArray = {"foo", "bar"};
@@ -78,14 +87,20 @@ public class AssertTests {
         try {
             Assert.notEmpty("foo", new String[0]);
             fail("notEmpty(Array) - IllegalArgumentException not thrown");
-        } catch (IllegalArgumentException e) {}
+        } catch (IllegalArgumentException e) {
+            Debug.logError(e, module);
+        }
+
 
         //-----------------------------------------------------------------------
         List<String> strList = new ArrayList<>();
         try {
             Assert.notEmpty("foo", strList);
             fail("notEmpty(Collection) - IllegalArgumentException not thrown");
-        } catch (IllegalArgumentException e) {}
+        } catch (IllegalArgumentException e) {
+            Debug.logError(e, module);
+        }
+
         strList.add("foo");
         try {
             Assert.notEmpty("foo", strList);
@@ -98,7 +113,10 @@ public class AssertTests {
         try {
             Assert.notEmpty("foo", strMap);
             fail("notEmpty(Map) - IllegalArgumentException not thrown");
-        } catch (IllegalArgumentException e) {}
+        } catch (IllegalArgumentException e) {
+            Debug.logError(e, module);
+        }
+
         strMap.put("foo", "foo");
         try {
             Assert.notEmpty("foo", strMap);
@@ -115,7 +133,10 @@ public class AssertTests {
         try {
             Assert.isInstanceOf("foo", strMap, AssertTests.class);
             fail("isInstanceOf - IllegalArgumentException not thrown");
-        } catch (IllegalArgumentException e) {}
+        } catch (IllegalArgumentException e) {
+            Debug.logError(e, module);
+        }
+
 
         //-----------------------------------------------------------------------
         try {
@@ -126,7 +147,10 @@ public class AssertTests {
         try {
             Assert.isInstanceOf("foo", strMap, String.class, AssertTests.class);
             fail("isInstanceOf (argument list) - IllegalArgumentException not thrown");
-        } catch (IllegalArgumentException e) {}
+        } catch (IllegalArgumentException e) {
+            Debug.logError(e, module);
+        }
+
 
         //-----------------------------------------------------------------------
         try {
@@ -137,7 +161,10 @@ public class AssertTests {
         try {
             Assert.isNotInstanceOf("foo", strMap, Map.class);
             fail("isNotInstanceOf - IllegalArgumentException not thrown");
-        } catch (IllegalArgumentException e) {}
+        } catch (IllegalArgumentException e) {
+            Debug.logError(e, module);
+        }
+
 
         //-----------------------------------------------------------------------
         try {
@@ -148,7 +175,10 @@ public class AssertTests {
         try {
             Assert.isNotInstanceOf("foo", strMap, String.class, Map.class);
             fail("isNotInstanceOf (argument list) - IllegalArgumentException not thrown");
-        } catch (IllegalArgumentException e) {}
+        } catch (IllegalArgumentException e) {
+            Debug.logError(e, module);
+        }
+
 
         //-----------------------------------------------------------------------
         try {
@@ -159,6 +189,9 @@ public class AssertTests {
         try {
             Assert.isAssignableTo("foo", strArray, Map[].class);
             fail("isNotInstanceOf (argument list) - IllegalArgumentException not thrown");
-        } catch (IllegalArgumentException e) {}
+        } catch (IllegalArgumentException e) {
+            Debug.logError(e, module);
+        }
+
     }
 }

Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/test/EntityTestSuite.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/test/EntityTestSuite.java?rev=1866958&r1=1866957&r2=1866958&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/test/EntityTestSuite.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/test/EntityTestSuite.java Sun Sep 15 07:48:09 2019
@@ -1275,7 +1275,9 @@ public class EntityTestSuite extends Ent
         } catch (GenericEntityException e) {
             try {
                 TransactionUtil.rollback(transactionStarted, "", e);
-            } catch (Exception e2) {}
+            } catch (Exception e2) {
+                Debug.logError(e2, module);
+            }
             noErrors = false;
         }
         endTime = System.currentTimeMillis();