Fix NPE & other issues 38/106238/1
authorParshad Patel <pars.patel@samsung.com>
Mon, 20 Apr 2020 02:36:34 +0000 (11:36 +0900)
committerParshad Patel <pars.patel@samsung.com>
Mon, 20 Apr 2020 03:04:12 +0000 (12:04 +0900)
Fix A "NullPointerException" could be thrown
Use "isAssignableFrom" instead
Either log or rethrow this exception

Issue-ID: PORTAL-562
Change-Id: Iabee6308bdca9c679323f8f496532d9431227772
Signed-off-by: Parshad Patel <pars.patel@samsung.com>
ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduler/SchedulerRestInterface.java
ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduler/SchedulerUtil.java
ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduleraux/SchedulerAuxRestInt.java
ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPRoleServiceImpl.java

index 93310a9..afcb7ab 100644 (file)
@@ -152,9 +152,6 @@ public class SchedulerRestInterface implements SchedulerRestInterfaceIfc {
                                
                logger.debug(EELFLoggerDelegate.debugLogger, "Client Initialized");
                
-               
-               
-
        }
 
        @SuppressWarnings("unchecked")
@@ -179,7 +176,7 @@ public class SchedulerRestInterface implements SchedulerRestInterfaceIfc {
                        if (cres.getEntity() != null) {
                                try {
                                        String str = (cres).readEntity(String.class);
-                                       if (t.getClass().getName().equals(String.class.getName())) {
+                                       if (t.getClass().isAssignableFrom(String.class)) {
                                                t = (T) str;
 
                                        } else {
@@ -234,7 +231,7 @@ public class SchedulerRestInterface implements SchedulerRestInterfaceIfc {
 
                                try {
                                        String str = (cres).readEntity(String.class);
-                                       if (t.getClass().getName().equals(String.class.getName())) {
+                                       if (t.getClass().isAssignableFrom(String.class)) {
                                                t = (T) str;
 
                                        } else {
index c1ca873..675cfe1 100644 (file)
@@ -57,17 +57,17 @@ public class SchedulerUtil {
 
        public static GetTimeSlotsWrapper getTimeSlotsWrapResponse (GetTimeSlotsRestObject<String> rs) {        
                
-               String resp_str = "";
+               String respStr = "";
                int status = 0;
                
                if ( rs != null ) {
-                       resp_str = rs.get();
+                       respStr = rs.get();
                        status = rs.getStatusCode();
                }
                                
                GetTimeSlotsWrapper w = new GetTimeSlotsWrapper();
                
-               w.setEntity(resp_str);
+               w.setEntity(respStr);
                w.setStatus (status);
                
                return (w);
@@ -75,19 +75,19 @@ public class SchedulerUtil {
        
        public static PostSubmitVnfChangeTimeSlotsWrapper postSubmitNewVnfWrapResponse (PostSubmitVnfChangeRestObject<String> rs) {     
                
-               String resp_str = "";
+               String respStr = "";
                int status = 0;
                String uuid = "";
                
                if ( rs != null ) {
-                       resp_str = rs.get();
+                       respStr = rs.get();
                        status = rs.getStatusCode();
                        uuid = rs.getUUID();
                }
                                
                PostSubmitVnfChangeTimeSlotsWrapper w = new PostSubmitVnfChangeTimeSlotsWrapper();
                
-               w.setEntity(resp_str);
+               w.setEntity(respStr);
                w.setStatus (status);
                w.setUuid(uuid);
                
@@ -96,19 +96,19 @@ public class SchedulerUtil {
        
        public static PostCreateNewVnfWrapper postCreateNewVnfWrapResponse (PostCreateNewVnfRestObject<String> rs) {    
                
-               String resp_str = "";
+               String respStr = "";
                int status = 0;
                String uuid = "";
                
                if ( rs != null ) {
-                       resp_str = rs.get();
+                       respStr = rs.get();
                        status = rs.getStatusCode();
                        uuid = rs.getUUID();
                }
                                
                PostCreateNewVnfWrapper w = new PostCreateNewVnfWrapper();
                
-               w.setEntity(resp_str);
+               w.setEntity(respStr);
                w.setStatus (status);
                w.setUuid(uuid);
                
@@ -121,14 +121,14 @@ public class SchedulerUtil {
                ObjectMapper mapper = new ObjectMapper();
                String r_json_str = "";
            if ( t != null ) {
-                   try {
-                       r_json_str = mapper.writeValueAsString(t);
-                   }
-                   catch ( com.fasterxml.jackson.core.JsonProcessingException j ) {
-                                       logger.debug(EELFLoggerDelegate.debugLogger,
-                                               DateUtil.getDateFormat().format(new Date()) + "<== " + methodName + " Unable " + "to "
-                                                       + "parse object as json");
-                               }
+            try {
+                r_json_str = mapper.writeValueAsString(t);
+            } catch (com.fasterxml.jackson.core.JsonProcessingException j) {
+                logger.debug(
+                        EELFLoggerDelegate.debugLogger, DateUtil.getDateFormat().format(new Date())
+                                + "<== " + methodName + " Unable " + "to " + "parse object as json",
+                        j);
+            }
            }
            return (r_json_str);
        }
index 75919ee..f120c4f 100644 (file)
@@ -63,24 +63,21 @@ public class SchedulerAuxRestInt {
         *
         * @param r the r
         */
-       public void logRequest ( RequestDetails r ) {
-                 SimpleDateFormat dateFormat = DateUtil.getDateFormat();
-       String methodName = "logRequest";
-           ObjectMapper mapper = new ObjectMapper();
-           String r_json_str = "";
-           if ( r != null ) {
-               r_json_str = r.toString();
-                   try {
-                       r_json_str = mapper.writeValueAsString(r);
-                   }
-                   catch ( com.fasterxml.jackson.core.JsonProcessingException j ) {
-                       logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " +  methodName + " "
-                                               + "Unable to "
-                                               + "parse request as json");
-                   }
-           }
-           logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " +  methodName + " Request="
-                               + "(" +
-                               r_json_str + ")");
+    public void logRequest(RequestDetails r) {
+        SimpleDateFormat dateFormat = DateUtil.getDateFormat();
+        String methodName = "logRequest";
+        ObjectMapper mapper = new ObjectMapper();
+        String rJsonStr = "";
+        if (r != null) {
+            rJsonStr = r.toString();
+            try {
+                rJsonStr = mapper.writeValueAsString(r);
+            } catch (com.fasterxml.jackson.core.JsonProcessingException j) {
+                logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== "
+                        + methodName + " " + "Unable to " + "parse request as json", j);
+            }
+        }
+        logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== "
+                + methodName + " Request=" + "(" + rJsonStr + ")");
     }
 }
index 5d38317..4adf1fd 100644 (file)
@@ -62,6 +62,9 @@ import org.onap.portalsdk.core.service.DataAccessService;
 public class EPRoleServiceImpl implements EPRoleService {
     EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPRoleServiceImpl.class);
 
+    private static final String GET_APP_ROLE_SQL_FORMAT =
+            "SELECT * FROM fn_role where APP_ID = %s AND APP_ROLE_ID = %s";
+
     @Autowired
     private DataAccessService dataAccessService;
 
@@ -123,10 +126,6 @@ public class EPRoleServiceImpl implements EPRoleService {
         return (EPRole) getDataAccessService().getDomainObject(EPRole.class, id, null);
     }
 
-    // TODO: refactor
-    private static final String GET_APP_ROLE_SQL_FORMAT =
-            "SELECT * FROM fn_role where APP_ID = %s AND APP_ROLE_ID = %s";
-
     @SuppressWarnings("unchecked")
     public EPRole getRole(Long appId, Long appRoleid) {
         if (appId == null || appRoleid == null) {
@@ -185,7 +184,7 @@ public class EPRoleServiceImpl implements EPRoleService {
             if (roles != null) {
                 return roles.get(0);
             }
-        } else if (resultsCount == 1) {
+        } else if (roles!=null && resultsCount == 1) {
             return roles.get(0);
         }
         return null;