diff options
author | Jim Hahn <jrh3@att.com> | 2020-04-06 15:33:23 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-04-06 19:30:02 -0400 |
commit | 15014b8ca386a8bfd5c26435f45de94ca06e95e8 (patch) | |
tree | 3cca518b950dfa35da0ea64dab2f9ff2b80f4595 /feature-state-management/src/main | |
parent | ece155048af47ea83ff898c999aa5137dc99a988 (diff) |
Address sonar issues in drools-pdp
Addressed the following sonar issues:
- add "final" to public static fields
- commented code; some were bogus - just updated the comments
so sonar is happy
- use "{}" instead of string concatenation
- junit should assert something
- when using logger, invoke compute-intensive tasks conditionally
- use superclass name instead of subclass name to access static fields
- don't always return the same value
- remove "transient" from fields of classes that aren't Serializable
- don't nest try/catch blocks
- use appropriate class name in Logger.getLogger()
- use Predicate<T> instead of Function<T,Boolean>
- remove unused parameters from private methods
- either log or throw
- remove duplicate methods
- use remove() TLS instead of set(null)
- null check is implicit in instanceof check
- do something with return value
- don't use volatile
- don't return "null" list; used Optional instead
- add no-arg constructor to non-Serializable superclass
- add callSuper=true for EqualsAndHashCode
- don't declare "throws XXX" where XXX is a subclass of RuntimeException
- remove serialVersionUID field if the class isn't Serializable
Also addressed some eclipse warnings:
- unused fields
- suppress generic typic cast warnings
Issue-ID: POLICY-2305
Change-Id: I906d5bf71c1f86531423e23b3667a585cdba45e1
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'feature-state-management/src/main')
3 files changed, 19 insertions, 16 deletions
diff --git a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DroolsPdpIntegrityMonitor.java b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DroolsPdpIntegrityMonitor.java index 2fa54e6b..2252a0f4 100644 --- a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DroolsPdpIntegrityMonitor.java +++ b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DroolsPdpIntegrityMonitor.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * feature-state-management * ================================================================================ - * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -172,11 +172,10 @@ public class DroolsPdpIntegrityMonitor extends IntegrityMonitor { try { logger.info("init: Starting HTTP server, addr= {}:{}", testHost, testPort); - IntegrityMonitorRestServer server = new IntegrityMonitorRestServer(); - server.init(properties); + new IntegrityMonitorRestServer(properties); } catch (Exception e) { - logger.error("init: Caught Exception attempting to start server on testPort= {} message:", testPort, e); + logger.error("init: Caught Exception attempting to start server on testPort={}", testPort); throw new IntegrityMonitorException(e); } } @@ -360,10 +359,10 @@ public class DroolsPdpIntegrityMonitor extends IntegrityMonitor { } public static class IntegrityMonitorRestServer implements Startable { - protected volatile HttpServletServer server = null; - protected volatile Properties integrityMonitorRestServerProperties = null; + protected HttpServletServer server = null; + protected final Properties integrityMonitorRestServerProperties; - public void init(Properties props) { + public IntegrityMonitorRestServer(Properties props) { this.integrityMonitorRestServerProperties = props; this.start(); } diff --git a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/RepositoryAudit.java b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/RepositoryAudit.java index 66982ef9..bf6b2e7b 100644 --- a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/RepositoryAudit.java +++ b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/RepositoryAudit.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * feature-state-management * ================================================================================ - * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -268,8 +268,8 @@ public class RepositoryAudit extends DroolsPdpIntegrityMonitor.AuditBase { repositoryPassword = getProperty("audit.password", true); logger.debug("Nexus Repository Information retrieved from 'IntegrityMonitorProperties':"); - logger.debug("repositoryId: " + repositoryId); - logger.debug("repositoryUrl: " + repositoryUrl); + logger.debug("repositoryId: {}", repositoryId); + logger.debug("repositoryUrl: {}", repositoryUrl); // Setting upload to be false so that files can no longer be created/deleted upload = false; @@ -419,10 +419,10 @@ public class RepositoryAudit extends DroolsPdpIntegrityMonitor.AuditBase { .resolve(artifact.artifactId + "-" + artifact.version + "." + artifact.type).toFile() .exists()) { // artifact exists, as expected - logger.info("RepositoryAudit: {} : exists", artifact.toString()); + logger.info("RepositoryAudit: {} : exists", artifact); } else { // Audit ERROR: artifact download failed for some reason - logger.error("RepositoryAudit: {}: does not exist", artifact.toString()); + logger.error("RepositoryAudit: {}: does not exist", artifact); if (!ignoreErrors) { response.append("Failed to download artifact: ").append(artifact).append('\n'); setResponse(response.toString()); @@ -470,12 +470,16 @@ public class RepositoryAudit extends DroolsPdpIntegrityMonitor.AuditBase { if (fileContents.regionMatches(index, "loading: ", 0, 9)) { index += 9; int endIndex = fileContents.indexOf('\n', index); - logger.info("RepositoryAudit: Attempted download: '{}'", fileContents.substring(index, endIndex)); + if (logger.isInfoEnabled()) { + logger.info("RepositoryAudit: Attempted download: '{}'", fileContents.substring(index, endIndex)); + } index = endIndex; } else if (fileContents.regionMatches(index, "loaded: ", 0, 8)) { index += 8; int endIndex = fileContents.indexOf(' ', index); - logger.info("RepositoryAudit: Successful download: '{}'", fileContents.substring(index, endIndex)); + if (logger.isInfoEnabled()) { + logger.info("RepositoryAudit: Successful download: '{}'", fileContents.substring(index, endIndex)); + } index = endIndex; } } diff --git a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeature.java b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeature.java index f88eaead..520d8503 100644 --- a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeature.java +++ b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeature.java @@ -194,7 +194,7 @@ public class StateManagementFeature implements StateManagementFeatureApi, try { stateManagement.lock(); } catch (Exception e) { - logger.error("StateManagementFeature.lock() failed with exception: {}", e); + logger.error("StateManagementFeature.lock() failed with exception", e); return false; } return true; @@ -210,7 +210,7 @@ public class StateManagementFeature implements StateManagementFeatureApi, try { stateManagement.unlock(); } catch (Exception e) { - logger.error("StateManagementFeature.unlock() failed with exception: {}", e); + logger.error("StateManagementFeature.unlock() failed with exception", e); return false; } return true; |