From 82c84075c71e285d1009bbe7e183ad2f0358d335 Mon Sep 17 00:00:00 2001 From: Parshad Patel Date: Tue, 27 Nov 2018 15:36:08 +0900 Subject: Fix critical sonar issues Fix rethrow the "InterruptedException" and Use "isAssignableFrom" sonar issues Issue-ID: SDC-1895 Change-Id: I2cadc08b9e7acdc84cf25a3ce9d22199711afa5d Signed-off-by: Parshad Patel --- .../org/openecomp/sdc/asdctool/impl/TitanGraphInitializer.java | 2 +- .../asdctool/migration/tasks/mig1710/UpgradeMigration1710.java | 1 + .../sdc/be/components/distribution/engine/CambriaHandler.java | 10 +++++++++- .../java/org/openecomp/sdc/be/dao/titan/TitanGraphClient.java | 2 +- .../sdc/be/model/operations/impl/CacheMangerOperation.java | 4 +++- .../sdc/common/datastructure/FunctionalInterfaces.java | 6 +++++- .../src/main/java/org/openecomp/sdc/be/workers/Manager.java | 1 + .../openecomp/sdc/notification/workers/NotificationWorker.java | 2 ++ .../openecomp/core/tools/commands/AddContributorCommand.java | 1 + .../src/main/java/org/openecomp/sdc/security/SecurityUtil.java | 2 +- 10 files changed, 25 insertions(+), 6 deletions(-) diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/TitanGraphInitializer.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/TitanGraphInitializer.java index 28a5bbdb24..8b89cc2706 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/TitanGraphInitializer.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/TitanGraphInitializer.java @@ -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 { diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1710/UpgradeMigration1710.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1710/UpgradeMigration1710.java index 4b9af31092..c63749e0d6 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1710/UpgradeMigration1710.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1710/UpgradeMigration1710.java @@ -1110,6 +1110,7 @@ public class UpgradeMigration1710 implements PostMigration { } } catch (InterruptedException e) { log.error("Error occurred: {}", e.getMessage()); + Thread.currentThread().interrupt(); } } return false; diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/CambriaHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/CambriaHandler.java index 7d99563a76..359330b81d 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/CambriaHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/CambriaHandler.java @@ -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); diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/titan/TitanGraphClient.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/titan/TitanGraphClient.java index e50c5e6278..9d5ff9d226 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/titan/TitanGraphClient.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/titan/TitanGraphClient.java @@ -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 { diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CacheMangerOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CacheMangerOperation.java index 758e46544d..3a0eef1a46 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CacheMangerOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CacheMangerOperation.java @@ -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(); } } diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/datastructure/FunctionalInterfaces.java b/common-app-api/src/main/java/org/openecomp/sdc/common/datastructure/FunctionalInterfaces.java index 3f6fb4c298..e66af77648 100644 --- a/common-app-api/src/main/java/org/openecomp/sdc/common/datastructure/FunctionalInterfaces.java +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/datastructure/FunctionalInterfaces.java @@ -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 { diff --git a/common-be/src/main/java/org/openecomp/sdc/be/workers/Manager.java b/common-be/src/main/java/org/openecomp/sdc/be/workers/Manager.java index 8f6445c21a..d0e5f4297d 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/workers/Manager.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/workers/Manager.java @@ -63,6 +63,7 @@ public class Manager { log.debug("all workers finished"); } catch (InterruptedException e) { log.error("failed while waiting for", e); + Thread.currentThread().interrupt(); } return outputQueue; } diff --git a/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-worker/src/main/java/org/openecomp/sdc/notification/workers/NotificationWorker.java b/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-worker/src/main/java/org/openecomp/sdc/notification/workers/NotificationWorker.java index e8c2006d5c..cde6419aa8 100644 --- a/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-worker/src/main/java/org/openecomp/sdc/notification/workers/NotificationWorker.java +++ b/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-worker/src/main/java/org/openecomp/sdc/notification/workers/NotificationWorker.java @@ -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(); } } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/AddContributorCommand.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/AddContributorCommand.java index 2c13ab7749..061ecbfaf1 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/AddContributorCommand.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/AddContributorCommand.java @@ -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) { diff --git a/security-utils/src/main/java/org/openecomp/sdc/security/SecurityUtil.java b/security-utils/src/main/java/org/openecomp/sdc/security/SecurityUtil.java index b9a5f7ab4b..76986c58aa 100644 --- a/security-utils/src/main/java/org/openecomp/sdc/security/SecurityUtil.java +++ b/security-utils/src/main/java/org/openecomp/sdc/security/SecurityUtil.java @@ -47,7 +47,7 @@ public class SecurityUtil { LOG.warn("Unfamiliar command please use: \n>aes '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" ); -- cgit 1.2.3-korg