Fix critical sonar issues 25/73625/3
authorParshad Patel <pars.patel@samsung.com>
Tue, 27 Nov 2018 06:36:08 +0000 (15:36 +0900)
committerTal Gitelman <tal.gitelman@att.com>
Thu, 29 Nov 2018 11:12:38 +0000 (11:12 +0000)
Fix rethrow the "InterruptedException" and Use "isAssignableFrom" sonar issues

Issue-ID: SDC-1895
Change-Id: I2cadc08b9e7acdc84cf25a3ce9d22199711afa5d
Signed-off-by: Parshad Patel <pars.patel@samsung.com>
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/TitanGraphInitializer.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1710/UpgradeMigration1710.java
catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/CambriaHandler.java
catalog-dao/src/main/java/org/openecomp/sdc/be/dao/titan/TitanGraphClient.java
catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CacheMangerOperation.java
common-app-api/src/main/java/org/openecomp/sdc/common/datastructure/FunctionalInterfaces.java
common-be/src/main/java/org/openecomp/sdc/be/workers/Manager.java
openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-worker/src/main/java/org/openecomp/sdc/notification/workers/NotificationWorker.java
openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/AddContributorCommand.java
security-utils/src/main/java/org/openecomp/sdc/security/SecurityUtil.java

index 28a5bbd..8b89cc2 100644 (file)
@@ -133,7 +133,7 @@ public class TitanGraphInitializer {
                        PropertyKey propKey = null;
                        if (!graphMgt.containsPropertyKey(prop.getProperty())) {
                                Class<?> clazz = prop.getClazz();
-                               if (!ArrayList.class.getName().equals(clazz.getName()) && !HashMap.class.getName().equals(clazz.getName())) {
+                               if (!clazz.isAssignableFrom(ArrayList.class) && !clazz.isAssignableFrom(HashMap.class)) {
                                        propKey = graphMgt.makePropertyKey(prop.getProperty()).dataType(prop.getClazz()).make();
                                }
                        } else {
index 4b9af31..c63749e 100644 (file)
@@ -1110,6 +1110,7 @@ public class UpgradeMigration1710 implements PostMigration {
                 }
             } catch (InterruptedException e) {
                 log.error("Error occurred: {}", e.getMessage());
+                Thread.currentThread().interrupt();
             }
         }
         return false;
index 7d99563..359330b 100644 (file)
@@ -473,6 +473,7 @@ public class CambriaHandler {
             }
             catch (InterruptedException e) {
                 log.debug("Failed during sleep after sending the message.", e);
+                Thread.currentThread().interrupt();
             }
 
             log.debug("After sending notification data to topic {}. result is {}", topicName, result);
@@ -516,6 +517,7 @@ public class CambriaHandler {
             }
             catch (InterruptedException e) {
                 log.debug("Failed during sleep after sending the message.", e);
+                Thread.currentThread().interrupt();
             }
 
             log.debug("After sending notification data to topic {}. result is {}", topicName, result);
@@ -546,7 +548,13 @@ public class CambriaHandler {
                 response = new CambriaErrorResponse(CambriaOperationStatus.OK, 200);
             }
         }
-        catch (IOException | InterruptedException e) {
+        catch (InterruptedException e) {
+            log.debug("InterruptedException while closing cambria publisher", e);
+            Thread.currentThread().interrupt();
+            response = new CambriaErrorResponse(CambriaOperationStatus.INTERNAL_SERVER_ERROR, 500);
+            writeErrorToLog(response, methodName, SEND_NOTIFICATION);
+        }
+        catch (IOException e) {
             log.debug("Failed to close cambria publisher", e);
             response = new CambriaErrorResponse(CambriaOperationStatus.INTERNAL_SERVER_ERROR, 500);
             writeErrorToLog(response, methodName, SEND_NOTIFICATION);
index e50c5e6..9d5ff9d 100644 (file)
@@ -381,7 +381,7 @@ public class TitanGraphClient {
                        PropertyKey propKey = null;
                        if (!graphMgt.containsPropertyKey(prop.getProperty())) {
                                Class<?> clazz = prop.getClazz();
-                               if (!ArrayList.class.getName().equals(clazz.getName()) && !HashMap.class.getName().equals(clazz.getName())) {
+                               if (!clazz.isAssignableFrom(ArrayList.class) && !clazz.isAssignableFrom(HashMap.class)) {
                                        propKey = graphMgt.makePropertyKey(prop.getProperty()).dataType(prop.getClazz()).make();
                                }
                        } else {
index 758e465..3a0eef1 100644 (file)
@@ -91,7 +91,7 @@ public class CacheMangerOperation implements ICacheMangerOperation {
             Integer syncWorkerExacutionIntrval = applicationL2CacheConfig.getQueue().getSyncIntervalInSecondes();
             log.debug("starting Sync worker:{} with executions interval:{} ", workerName, syncWorkerExacutionIntrval);
             SyncWorker syncWorker = new SyncWorker(workerName, this);
-            this.syncExecutor.scheduleAtFixedRate(syncWorker, 5 * 60, syncWorkerExacutionIntrval, TimeUnit.SECONDS);
+            this.syncExecutor.scheduleAtFixedRate(syncWorker, 5 * 60L, syncWorkerExacutionIntrval, TimeUnit.SECONDS);
             this.workerExecutor = Executors.newFixedThreadPool(numberOfWorkers, threadFactory);
             CacheWorker cacheWorker;
             for (int i = 0; i < numberOfWorkers; i++) {
@@ -170,6 +170,7 @@ public class CacheMangerOperation implements ICacheMangerOperation {
             log.debug("all Cache workers finished");
         } catch (InterruptedException e) {
             log.error("failed while waiting for Cache worker", e);
+            Thread.currentThread().interrupt();
         }
         try {
             if (!workerExecutor.awaitTermination(1, TimeUnit.MINUTES)) {
@@ -178,6 +179,7 @@ public class CacheMangerOperation implements ICacheMangerOperation {
             log.debug("sync worker finished");
         } catch (InterruptedException e) {
             log.error("failed while waiting for sync worker", e);
+            Thread.currentThread().interrupt();
         }
     }
 
index 3f6fb4c..e66af77 100644 (file)
@@ -491,7 +491,11 @@ public class FunctionalInterfaces {
                        try {
                                T calcValue = future.get(timeoutInMs, TimeUnit.MILLISECONDS);
                                result = Either.left(calcValue);
-                       } catch (InterruptedException | ExecutionException | TimeoutException e) {
+                       } catch (InterruptedException e) {
+                               LOGGER.debug("InterruptedException in runMethodWithTimeOut", e);
+                               Thread.currentThread().interrupt();
+                               result = Either.right(false);
+                       } catch (ExecutionException | TimeoutException e) {
                                LOGGER.debug("method run was canceled because it has passed its time limit of {} MS", timeoutInMs, e);
                                result = Either.right(false);
                        } finally {
index 8f6445c..d0e5f42 100644 (file)
@@ -63,6 +63,7 @@ public class Manager<T extends Job, E> {
                        log.debug("all workers finished");
                } catch (InterruptedException e) {
                        log.error("failed while waiting for", e);
+            Thread.currentThread().interrupt();
                }
                return outputQueue;
        }
index e8c2006..cde6419 100644 (file)
@@ -68,6 +68,7 @@ public class NotificationWorker {
        }
 
        public class Poller extends Thread {
+               @Override
                public void run() {
                        try {
                                while (!stopRunning) {
@@ -77,6 +78,7 @@ public class NotificationWorker {
                        }
                        catch (InterruptedException e) {
                                LOGGER.error("Interrupted Exception during Notification poller launch.", e);
+                   Thread.currentThread().interrupt();
                        }
                }
 
index 2c13ab7..061ecbf 100644 (file)
@@ -71,6 +71,7 @@ public class AddContributorCommand extends Command {
             executor = Executors.newFixedThreadPool(DEFAULT_THREAD_NUMBER);
             executeAllTasks(executor, tasks);
         } catch (InterruptedException e) {
+            Thread.currentThread().interrupt();
             throw new CommandExecutionRuntimeException(COMMAND_ADD_CONTRIBUTOR_FAILED, e);
         } finally {
             if (executor != null) {
index b9a5f7a..76986c5 100644 (file)
@@ -47,7 +47,7 @@ public class SecurityUtil {
                         LOG.warn("Unfamiliar command please use: \n>aes <encrypt/decrypt> 'message to encrypt/decrypt' ");
                 }
             }catch(Exception e){
-                LOG.debug( "cannot perform {}:" );
+                LOG.warn("Exception while message encryption or decryption");
                 throw e;
             }
             LOG.debug( "output: {}", res!=null && res.isLeft() ? res.left().value() : "ERROR" );