From fbc481ba674204cd9972c5c53563110fd0a1a1be Mon Sep 17 00:00:00 2001 From: "aravind.est" Date: Fri, 25 Aug 2023 15:15:26 +0100 Subject: [PATCH] Add null handling on cache Fixed a nullpointer which causes bug in sonar. Issue-ID: NONRTRIC-910 Change-Id: I4f8a42c6874e72be27078678273be072f4c8faf2 Signed-off-by: aravind.est --- .../com/oransc/rappmanager/models/cache/RappCacheService.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/cache/RappCacheService.java b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/cache/RappCacheService.java index 16c231c..cdc42c6 100755 --- a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/cache/RappCacheService.java +++ b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/cache/RappCacheService.java @@ -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 getAllRapp() { Cache cache = cacheManager.getCache(RAPP_CACHE); - Map nativeCache = (Map) cache.getNativeCache(); - return nativeCache.values(); + if(cache != null) { + Map nativeCache = (Map) cache.getNativeCache(); + return nativeCache.values(); + } + return List.of(); } public Optional getRapp(String rappId) { -- 2.16.6