Fix sonarqube code Bug 81/119981/1
authormkidd <michael.kidd@est.tech>
Mon, 29 Mar 2021 08:16:18 +0000 (10:16 +0200)
committermkidd <michael.kidd@est.tech>
Mon, 29 Mar 2021 08:47:40 +0000 (10:47 +0200)
ApexEditorParameters has a URI that sonar does not like, hard coding the leading forward slash removes the complaint
ApexEditorMain was receiving args and a print stream in the form of System.err and then System.out, both of these were null values, while Sonar sees System.out or err as a bug as it should be a logger, simply passing null in its place is not an issue to sonar
BeanBase.java Removed an if statement that always asserted to be true, as it is inside an if statement that confirmed that condition.
removed an accessibility change as sonar sees this as a violation

Issue-ID: POLICY-3095
Signed-off-by: mkidd <michael.kidd@est.tech>
Change-Id: I1bbdfe9cc6db085195e95da3dbfbc8b29d9a5ff5
Signed-off-by: mkidd <michael.kidd@est.tech>
gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorMain.java
gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorParameters.java
gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanBase.java

index 53d94c8..1d8f1d3 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
- *  Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ *  Modifications Copyright (C) 2019-2021 Nordix Foundation.
  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -212,7 +212,7 @@ public class ApexEditorMain {
      */
     public static void main(final String[] args) {
         try {
-            final ApexEditorMain editorMain = new ApexEditorMain(args, System.out);
+            final ApexEditorMain editorMain = new ApexEditorMain(args, null);
             editorMain.init();
         } catch (final Exception e) {
             LOGGER.error("start failed", e);
index e89e69f..7eb0195 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
- *  Modifications Copyright (C) 2020 Nordix Foundation.
+ *  Modifications Copyright (C) 2020-2021 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -50,7 +50,7 @@ public class ApexEditorParameters {
     private static final String DEFAULT_SERVER_URI_PREFIX = "http://";
     /** The server listens on localhost by default. */
     public static final String DEFAULT_SERVER_URI_ROOT = "localhost";
-    private static final String DEFAULT_REST_PATH = "/apexservices/";
+    private static final String DEFAULT_REST_PATH = "apexservices/";
     private static final String DEFAULT_STATIC_PATH = "/";
 
     // Constants for port checks
@@ -90,7 +90,7 @@ public class ApexEditorParameters {
      * @return the base URI
      */
     public URI getBaseUri() {
-        return URI.create(DEFAULT_SERVER_URI_PREFIX + listenAddress + ':' + restPort + DEFAULT_REST_PATH);
+        return URI.create(DEFAULT_SERVER_URI_PREFIX + listenAddress + ':' + restPort + "/" + DEFAULT_REST_PATH);
     }
 
     /**
index 261cbae..dbc5ae2 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
- *  Modifications Copyright (C) 2020 Nordix Foundation.
+ *  Modifications Copyright (C) 2020-2021 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -54,10 +54,8 @@ public abstract class BeanBase {
         if (field != null) {
             try {
                 final Field f = this.getClass().getDeclaredField(field);
-                if (f != null) {
-                    f.setAccessible(true);
-                    return (String) (f.get(this));
-                }
+                f.trySetAccessible();
+                return (String) (f.get(this));
             } catch (final Exception e) {
                 throw new IllegalArgumentException(PROBLEM_RETRIEVING_FIELD_PREFIX + field + JSON_BEAN_SUFFIX + this,
                     e);