summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKrishnajinka <kris.jinka@samsung.com>2018-07-06 17:28:54 +0900
committerTakamune Cho <tc012c@att.com>2018-07-10 14:40:24 +0000
commitec248ffb74f1c038fdd6c7a77411f628ef51366f (patch)
treea790240451325798417300472b31a86993987160
parent72dbb19dd424ef559422bd0243d6a3179e01c382 (diff)
null ptr check
rework based on review comments Issue-ID: APPC-1047 Change-Id: Ia87707535dc5825d18a6c35fdae416064dcb8c14 Signed-off-by: Krishnajinka <kris.jinka@samsung.com>
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV2.java18
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV3.java19
-rw-r--r--appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/WrapperEncryptionTool.java7
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/onap/appc/dg/dependencymanager/impl/DependencyManagerImpl.java5
-rw-r--r--appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/impl/AbstractRequestHandlerImpl.java7
5 files changed, 39 insertions, 17 deletions
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV2.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV2.java
index b22b6843a..73872040b 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV2.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV2.java
@@ -161,6 +161,12 @@ public class ServiceCatalogV2 extends ServiceCatalog {
try {
access = authenticate.execute();
+ //Ensure that access or the access token is not null before
+ //checking local expiration or accessing the tenant information
+ if (access == null || access.getToken() == null) {
+ throw new NullPointerException("The access key used to access the provider or access token is null." +
+ "Failed to init ServiceCatalogV2");
+ }
expiresLocal = getLocalExpiration(access);
tenant = access.getToken().getTenant();
tokenProvider = new OpenStackSimpleTokenProvider(access.getToken().getId());
@@ -370,13 +376,11 @@ public class ServiceCatalogV2 extends ServiceCatalog {
*/
private static long getLocalExpiration(Access accessKey) {
Date now = Time.getCurrentUTCDate();
- if (accessKey != null && accessKey.getToken() != null) {
- Calendar issued = accessKey.getToken().getIssued_at();
- Calendar expires = accessKey.getToken().getExpires();
- if (issued != null && expires != null) {
- long tokenLife = expires.getTimeInMillis() - issued.getTimeInMillis();
- return now.getTime() + tokenLife;
- }
+ Calendar issued = accessKey.getToken().getIssued_at();
+ Calendar expires = accessKey.getToken().getExpires();
+ if (issued != null && expires != null) {
+ long tokenLife = expires.getTimeInMillis() - issued.getTimeInMillis();
+ return now.getTime() + tokenLife;
}
return now.getTime();
}
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV3.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV3.java
index 4773603c3..02e73c10c 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV3.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV3.java
@@ -55,6 +55,8 @@ import com.woorea.openstack.keystone.v3.model.Token.Project;
import com.woorea.openstack.keystone.v3.model.Token.Service;
import com.woorea.openstack.keystone.v3.model.Token.Service.Endpoint;
+import javax.validation.constraints.Null;
+
/**
* This class is used to capture and cache the service catalog for a specific OpenStack provider.
* <p>
@@ -171,6 +173,11 @@ public class ServiceCatalogV3 extends ServiceCatalog {
try {
token = authenticate.execute();
+ // Ensure that token is not null before accessing
+ // local expiration or the internal details of token
+ if (token == null) {
+ throw new NullPointerException("Access token is null. Failed to init ServiceCatalogV3");
+ }
expiresLocal = getLocalExpiration(token);
project = token.getProject();
tokenProvider = new OpenStackSimpleTokenProvider(token.getId());
@@ -386,13 +393,11 @@ public class ServiceCatalogV3 extends ServiceCatalog {
*/
private static long getLocalExpiration(Token accessToken) {
Date now = Time.getCurrentUTCDate();
- if (accessToken != null) {
- Calendar issued = accessToken.getIssuedAt();
- Calendar expires = accessToken.getExpiresAt();
- if (issued != null && expires != null) {
- long tokenLife = expires.getTimeInMillis() - issued.getTimeInMillis();
- return now.getTime() + tokenLife;
- }
+ Calendar issued = accessToken.getIssuedAt();
+ Calendar expires = accessToken.getExpiresAt();
+ if (issued != null && expires != null) {
+ long tokenLife = expires.getTimeInMillis() - issued.getTimeInMillis();
+ return now.getTime() + tokenLife;
}
return now.getTime();
}
diff --git a/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/WrapperEncryptionTool.java b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/WrapperEncryptionTool.java
index f71bee1ec..86b0861cb 100644
--- a/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/WrapperEncryptionTool.java
+++ b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/WrapperEncryptionTool.java
@@ -105,10 +105,11 @@ public class WrapperEncryptionTool {
log.debug("Caught Exception", e);
log.info("Caught exception", e);
log.info("APPC-MESSAGE:" + e.getMessage());
- dbResourceManager.cleanUp();
-
} finally {
- dbResourceManager.cleanUp();
+ //When dbResourceManager is not created then no need to cleanup
+ if (dbResourceManager != null) {
+ dbResourceManager.cleanUp();
+ }
}
}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/onap/appc/dg/dependencymanager/impl/DependencyManagerImpl.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/onap/appc/dg/dependencymanager/impl/DependencyManagerImpl.java
index 82891b02d..ecd3c0305 100644
--- a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/onap/appc/dg/dependencymanager/impl/DependencyManagerImpl.java
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/onap/appc/dg/dependencymanager/impl/DependencyManagerImpl.java
@@ -55,6 +55,11 @@ public class DependencyManagerImpl implements DependencyManager {
if(dependencyModel == null){
logger.debug("Dependency model not found in cache, creating strategy for reading it");
DependencyType strategy = getStrategy(dependencyType);
+ // Throw exception if strategy could not be created because it is required
+ // to retrieve the vnfc dependency model later
+ if (strategy == null) {
+ throw new NullPointerException("Strategy is null. Failed to retrieve Vnfc Dependency Model");
+ }
dependencyModel = strategy.getVnfcDependencyModel(modelIdentifier);
}
if (logger.isTraceEnabled()) {
diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/impl/AbstractRequestHandlerImpl.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/impl/AbstractRequestHandlerImpl.java
index aa6d203a5..cd9011f4b 100644
--- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/impl/AbstractRequestHandlerImpl.java
+++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/impl/AbstractRequestHandlerImpl.java
@@ -408,6 +408,13 @@ public abstract class AbstractRequestHandlerImpl implements RequestHandler {
if (logger.isDebugEnabled())
logger.debug("Metric getting initialized");
MetricService metricService = getMetricservice();
+ // Check for the metric service created before trying to create registry using
+ // the metricService object
+ if (metricService == null) {
+ // Cannot find service reference for org.onap.appc.metricservice.MetricService
+ throw new NullPointerException("org.onap.appc.metricservice.MetricService is null. " +
+ "Failed to init Metric");
+ }
metricRegistry = metricService.createRegistry("APPC");
DispatchingFuntionMetric dispatchingFuntionMetric = metricRegistry.metricBuilderFactory().
dispatchingFunctionCounterBuilder().