aboutsummaryrefslogtreecommitdiffstats
path: root/policy-utils
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-04-06 15:33:23 -0400
committerJim Hahn <jrh3@att.com>2020-04-06 19:30:02 -0400
commit15014b8ca386a8bfd5c26435f45de94ca06e95e8 (patch)
tree3cca518b950dfa35da0ea64dab2f9ff2b80f4595 /policy-utils
parentece155048af47ea83ff898c999aa5137dc99a988 (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 'policy-utils')
-rw-r--r--policy-utils/src/main/java/org/onap/policy/drools/policies/DomainMaker.java7
-rw-r--r--policy-utils/src/main/java/org/onap/policy/drools/utils/PropertyUtil.java9
-rw-r--r--policy-utils/src/test/java/org/onap/policy/drools/models/domains/a/DomainAPolicy.java2
-rw-r--r--policy-utils/src/test/java/org/onap/policy/drools/policies/DomainMakerTest.java2
4 files changed, 8 insertions, 12 deletions
diff --git a/policy-utils/src/main/java/org/onap/policy/drools/policies/DomainMaker.java b/policy-utils/src/main/java/org/onap/policy/drools/policies/DomainMaker.java
index 0097dff6..58d5052a 100644
--- a/policy-utils/src/main/java/org/onap/policy/drools/policies/DomainMaker.java
+++ b/policy-utils/src/main/java/org/onap/policy/drools/policies/DomainMaker.java
@@ -106,7 +106,7 @@ public class DomainMaker {
* Check policy conformance to its specification providing a list of errors
* in a ValidationFailedException.
*/
- public boolean conformance(@NonNull ToscaPolicy policy) throws ValidationFailedException {
+ public boolean conformance(@NonNull ToscaPolicy policy) {
if (!isRegistered(policy.getTypeIdentifier())) {
return false;
}
@@ -134,8 +134,7 @@ public class DomainMaker {
* Checks a domain policy conformance to its specification providing a list of errors
* in a ValidationFailedException.
*/
- public <T> boolean conformance(@NonNull ToscaPolicyTypeIdentifier policyType, T domainPolicy)
- throws ValidationFailedException {
+ public <T> boolean conformance(@NonNull ToscaPolicyTypeIdentifier policyType, T domainPolicy) {
if (!isRegistered(policyType)) {
return false;
@@ -144,7 +143,7 @@ public class DomainMaker {
try {
validators.get(policyType).encode(domainPolicy);
} catch (CoderException e) {
- logger.info("policy {}:{}:{} is not conformant", policyType, domainPolicy.getClass().getName(), e);
+ logger.info("policy {}:{} is not conformant", policyType, domainPolicy.getClass().getName(), e);
if (e.getCause() instanceof ValidationFailedException) {
throw (ValidationFailedException) e.getCause();
}
diff --git a/policy-utils/src/main/java/org/onap/policy/drools/utils/PropertyUtil.java b/policy-utils/src/main/java/org/onap/policy/drools/utils/PropertyUtil.java
index 959e6a2c..e6195fa4 100644
--- a/policy-utils/src/main/java/org/onap/policy/drools/utils/PropertyUtil.java
+++ b/policy-utils/src/main/java/org/onap/policy/drools/utils/PropertyUtil.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * 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.
@@ -30,6 +30,7 @@ import java.util.Properties;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
+import java.util.concurrent.atomic.AtomicReference;
import org.apache.commons.configuration2.Configuration;
import org.apache.commons.configuration2.ConfigurationConverter;
import org.apache.commons.configuration2.SystemConfiguration;
@@ -54,13 +55,13 @@ public class PropertyUtil {
private static final Logger logger = LoggerFactory.getLogger(PropertyUtil.class.getName());
- private static volatile CryptoCoder cryptoCoder;
+ private static final AtomicReference<CryptoCoder> cryptoCoder = new AtomicReference<>();
/**
* Sets a default Crypto Coder.
*/
public static void setDefaultCryptoCoder(CryptoCoder cryptoCoder) {
- PropertyUtil.cryptoCoder = cryptoCoder;
+ PropertyUtil.cryptoCoder.set(cryptoCoder);
}
/**
@@ -186,7 +187,7 @@ public class PropertyUtil {
* @return Properties - interpolated properties object
*/
public static Properties getInterpolatedProperties(Properties properties) {
- return getInterpolatedProperties(properties, cryptoCoder);
+ return getInterpolatedProperties(properties, cryptoCoder.get());
}
/**
diff --git a/policy-utils/src/test/java/org/onap/policy/drools/models/domains/a/DomainAPolicy.java b/policy-utils/src/test/java/org/onap/policy/drools/models/domains/a/DomainAPolicy.java
index 04f20b2a..47972397 100644
--- a/policy-utils/src/test/java/org/onap/policy/drools/models/domains/a/DomainAPolicy.java
+++ b/policy-utils/src/test/java/org/onap/policy/drools/models/domains/a/DomainAPolicy.java
@@ -27,8 +27,6 @@ import lombok.Data;
@Data
@Builder
public class DomainAPolicy {
- private static final long serialVersionUID = -8942432000554391455L;
-
@SerializedName("type")
public String type;
diff --git a/policy-utils/src/test/java/org/onap/policy/drools/policies/DomainMakerTest.java b/policy-utils/src/test/java/org/onap/policy/drools/policies/DomainMakerTest.java
index cfacc7ab..47d6c2d8 100644
--- a/policy-utils/src/test/java/org/onap/policy/drools/policies/DomainMakerTest.java
+++ b/policy-utils/src/test/java/org/onap/policy/drools/policies/DomainMakerTest.java
@@ -45,12 +45,10 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifi
public class DomainMakerTest {
private DomainMaker domainMaker;
- private StandardCoder nonValCoder;
@Before
public void setUp() throws Exception {
domainMaker = new DomainMaker();
- nonValCoder = new StandardCoder();
}
@Test