null ptr check 33/55933/3
authorKrishnajinka <kris.jinka@samsung.com>
Fri, 6 Jul 2018 08:28:54 +0000 (17:28 +0900)
committerTakamune Cho <tc012c@att.com>
Tue, 10 Jul 2018 14:40:24 +0000 (14:40 +0000)
rework based on review comments

Issue-ID: APPC-1047

Change-Id: Ia87707535dc5825d18a6c35fdae416064dcb8c14
Signed-off-by: Krishnajinka <kris.jinka@samsung.com>
appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV2.java
appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV3.java
appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/WrapperEncryptionTool.java
appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/onap/appc/dg/dependencymanager/impl/DependencyManagerImpl.java
appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/impl/AbstractRequestHandlerImpl.java

index b22b684..7387204 100644 (file)
@@ -161,6 +161,12 @@ public class ServiceCatalogV2 extends ServiceCatalog {
 \r
         try {\r
             access = authenticate.execute();\r
+            //Ensure that access or the access token is not null before\r
+            //checking local expiration or accessing the tenant information\r
+            if (access == null || access.getToken() == null) {\r
+                throw new NullPointerException("The access key used to access the provider or access token is null." +\r
+                        "Failed to init ServiceCatalogV2");\r
+            }\r
             expiresLocal = getLocalExpiration(access);\r
             tenant = access.getToken().getTenant();\r
             tokenProvider = new OpenStackSimpleTokenProvider(access.getToken().getId());\r
@@ -370,13 +376,11 @@ public class ServiceCatalogV2 extends ServiceCatalog {
      */\r
     private static long getLocalExpiration(Access accessKey) {\r
         Date now = Time.getCurrentUTCDate();\r
-        if (accessKey != null && accessKey.getToken() != null) {\r
-            Calendar issued = accessKey.getToken().getIssued_at();\r
-            Calendar expires = accessKey.getToken().getExpires();\r
-            if (issued != null && expires != null) {\r
-                long tokenLife = expires.getTimeInMillis() - issued.getTimeInMillis();\r
-                return now.getTime() + tokenLife;\r
-            }\r
+        Calendar issued = accessKey.getToken().getIssued_at();\r
+        Calendar expires = accessKey.getToken().getExpires();\r
+        if (issued != null && expires != null) {\r
+            long tokenLife = expires.getTimeInMillis() - issued.getTimeInMillis();\r
+            return now.getTime() + tokenLife;\r
         }\r
         return now.getTime();\r
     }\r
index 4773603..02e73c1 100644 (file)
@@ -55,6 +55,8 @@ import com.woorea.openstack.keystone.v3.model.Token.Project;
 import com.woorea.openstack.keystone.v3.model.Token.Service;\r
 import com.woorea.openstack.keystone.v3.model.Token.Service.Endpoint;\r
 \r
+import javax.validation.constraints.Null;\r
+\r
 /**\r
  * This class is used to capture and cache the service catalog for a specific OpenStack provider.\r
  * <p>\r
@@ -171,6 +173,11 @@ public class ServiceCatalogV3 extends ServiceCatalog {
 \r
         try {\r
             token = authenticate.execute();\r
+            // Ensure that token is not null before accessing\r
+            // local expiration or the internal details of token\r
+            if (token == null) {\r
+                throw new NullPointerException("Access token is null. Failed to init ServiceCatalogV3");\r
+            }\r
             expiresLocal = getLocalExpiration(token);\r
             project = token.getProject();\r
             tokenProvider = new OpenStackSimpleTokenProvider(token.getId());\r
@@ -386,13 +393,11 @@ public class ServiceCatalogV3 extends ServiceCatalog {
      */\r
     private static long getLocalExpiration(Token accessToken) {\r
         Date now = Time.getCurrentUTCDate();\r
-        if (accessToken != null) {\r
-            Calendar issued = accessToken.getIssuedAt();\r
-            Calendar expires = accessToken.getExpiresAt();\r
-            if (issued != null && expires != null) {\r
-                long tokenLife = expires.getTimeInMillis() - issued.getTimeInMillis();\r
-                return now.getTime() + tokenLife;\r
-            }\r
+        Calendar issued = accessToken.getIssuedAt();\r
+        Calendar expires = accessToken.getExpiresAt();\r
+        if (issued != null && expires != null) {\r
+            long tokenLife = expires.getTimeInMillis() - issued.getTimeInMillis();\r
+            return now.getTime() + tokenLife;\r
         }\r
         return now.getTime();\r
     }\r
index f71bee1..86b0861 100644 (file)
@@ -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();
+            }
         }
     }
 
index 82891b0..ecd3c03 100644 (file)
@@ -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()) {
index aa6d203..cd9011f 100644 (file)
@@ -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().