Add null handling on cache 70/11670/1
authoraravind.est <aravindhan.a@est.tech>
Fri, 25 Aug 2023 14:15:26 +0000 (15:15 +0100)
committeraravind.est <aravindhan.a@est.tech>
Fri, 25 Aug 2023 14:29:13 +0000 (15:29 +0100)
Fixed a nullpointer which causes bug in sonar.

Issue-ID: NONRTRIC-910
Change-Id: I4f8a42c6874e72be27078678273be072f4c8faf2
Signed-off-by: aravind.est <aravindhan.a@est.tech>
rapp-manager-models/src/main/java/com/oransc/rappmanager/models/cache/RappCacheService.java

index 16c231c..cdc42c6 100755 (executable)
@@ -20,6 +20,7 @@ package com.oransc.rappmanager.models.cache;
 
 import com.oransc.rappmanager.models.rapp.Rapp;
 import java.util.Collection;
+import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import lombok.RequiredArgsConstructor;
@@ -36,8 +37,11 @@ public class RappCacheService {
 
     public Collection<Rapp> getAllRapp() {
         Cache cache = cacheManager.getCache(RAPP_CACHE);
-        Map<String, Rapp> nativeCache = (Map<String, Rapp>) cache.getNativeCache();
-        return nativeCache.values();
+        if(cache != null) {
+            Map<String, Rapp> nativeCache = (Map<String, Rapp>) cache.getNativeCache();
+            return nativeCache.values();
+        }
+        return List.of();
     }
 
     public Optional<Rapp> getRapp(String rappId) {