Fix sonar related to persistence-feature 99/12499/2
authorPamela Dragosh <pdragosh@research.att.com>
Thu, 14 Sep 2017 17:49:52 +0000 (13:49 -0400)
committerPamela Dragosh <pdragosh@research.att.com>
Fri, 15 Sep 2017 13:51:44 +0000 (09:51 -0400)
Sonar blocker for catchable:
I am not sure why this is wrapped with an exception.
Changing try-catch to use Exception | LinkageError per Jorge/Ralph.

Sonar critical for logging exceptions.

Sonar critical for casting to Long and reinterrupting thread.

Change-Id: I44d46f005d9aa30c434c22e479034107055277ce
Issue-ID: POLICY-195
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/PersistenceFeature.java
policy-management/src/main/java/org/onap/policy/drools/persistence/FileSystemPersistence.java
policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java

index e6603b6..b48690b 100644 (file)
@@ -732,7 +732,7 @@ public class PersistenceFeature implements PolicySessionFeatureAPI, PolicyEngine
                 * before firing rules again.  This is a "half" time, so that
                 * we can multiply it by two without overflowing the word size.
                 */
-               long halfMaxSleepTime = 5000 / 2;
+               long halfMaxSleepTime = 5000L / 2L;
 
                /**
                 * Constructor - initialize variables and create thread
@@ -819,6 +819,7 @@ public class PersistenceFeature implements PolicySessionFeatureAPI, PolicyEngine
                                
                        } catch (InterruptedException e) {
                                logger.error("stopThread exception: ", e);
+                               Thread.currentThread().interrupt();
                        }
                        
                        // verify that it's done
@@ -866,11 +867,9 @@ public class PersistenceFeature implements PolicySessionFeatureAPI, PolicyEngine
                                                // no rules fired -- increase poll delay
                                                sleepTime = 2 * Math.min(halfMaxSleepTime, sleepTime);
                                        }
-                                       
-                               } catch (Throwable e) {
-                                       logger.error("startThread exception: ", e);
-                               }
-                               
+                               } catch (Exception | LinkageError e) {
+                                       logger.error("Exception during kieSession.fireAllRules", e);
+                               }                               
                        
                                try {
                                        if(stopped.await(sleepTime, TimeUnit.MILLISECONDS)) {
@@ -879,6 +878,7 @@ public class PersistenceFeature implements PolicySessionFeatureAPI, PolicyEngine
                                        
                                } catch (InterruptedException e) {
                                        logger.error("startThread exception: ", e);
+                                       Thread.currentThread().interrupt();
                                        break;
                                }
                        }
index 5ac1725..e217ee7 100644 (file)
@@ -164,7 +164,7 @@ public class FileSystemPersistence implements SystemPersistence {
           this.backupController(controllerName);
         }
       } catch (final Exception e) {
-        logger.info("{}: no existing {} properties", this, controllerName);
+        logger.info("{}: no existing {} properties {}", this, controllerName, e);
         // continue
       }
     }
index a6f7937..b2b2df6 100644 (file)
@@ -998,6 +998,7 @@ class PolicyEngineManager implements PolicyEngine {
           Thread.sleep(5000L);
         } catch (final InterruptedException e) {
           logger.warn("{}: interrupted-exception while shutting down management server: ", this);
+          Thread.currentThread().interrupt();
         }
 
         System.exit(0);