From 80f072f60509ef3a35369a60857fe05f6c2a993a Mon Sep 17 00:00:00 2001 From: "Tej, Tarun" Date: Mon, 21 Aug 2017 20:00:50 -0400 Subject: Fixes for sonar critical issues Fixes for critical and blocker issues reported in sonar. Issue-Id: POLICY-113 Change-Id: I50969fe93a94b0497f3fb30864a6c45e63208fe6 Signed-off-by: Tej, Tarun --- .../java/org/onap/policy/xacml/std/pap/StdEngine.java | 14 +++++++------- .../org/onap/policy/xacml/std/pap/StdPAPPolicy.java | 2 +- .../java/org/onap/policy/xacml/std/pap/StdPDP.java | 7 +++---- .../org/onap/policy/xacml/std/pap/StdPDPGroup.java | 18 +++++++++--------- .../xacml/std/pap/StdPDPItemSetChangeNotifier.java | 2 +- .../org/onap/policy/xacml/std/pap/StdPDPStatus.java | 10 +++++----- 6 files changed, 26 insertions(+), 27 deletions(-) (limited to 'ONAP-XACML/src/main') diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdEngine.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdEngine.java index 3132b8cac..14d7c7f62 100644 --- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdEngine.java +++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdEngine.java @@ -69,10 +69,10 @@ public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE private static Log logger = LogFactory.getLog(StdEngine.class); - public static String PROP_PAP_REPO = "xacml.pap.pdps"; - public static String PROP_PAP_GROUPS = "xacml.pap.groups"; - public static String PROP_PAP_GROUPS_DEFAULT = "xacml.pap.groups.default"; - public static String PROP_PAP_GROUPS_DEFAULT_NAME = "default"; + public static final String PROP_PAP_REPO = "xacml.pap.pdps"; + public static final String PROP_PAP_GROUPS = "xacml.pap.groups"; + public static final String PROP_PAP_GROUPS_DEFAULT = "xacml.pap.groups.default"; + public static final String PROP_PAP_GROUPS_DEFAULT_NAME = "default"; //this value will be accessed from XacmlPapServlet so that we know if a default group did not exist //and was just added. This way, we can add the new group to the database. public boolean wasDefaultGroupJustAdded = false; @@ -892,7 +892,7 @@ public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE try { ((StdPDPGroup)group).saveGroupConfiguration(); } catch (IOException e) { - throw new PAPException("Unable to save new configuration for '" + group.getName() + "': " + e.getMessage()); + throw new PAPException("Unable to save new configuration for '" + group.getName() + "': " + e.getMessage(), e); } // update the group in the set by simply replacing the old instance with the new one this.groups.remove(existingGroup); @@ -923,13 +923,13 @@ public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE } } catch (Exception e) { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "StdEngine", "Unable to rename directory"); - throw new PAPException("Unable to move directory from '" + oldPath + "' to '" + newPath + "': " + e.getMessage()); + throw new PAPException("Unable to move directory from '" + oldPath + "' to '" + newPath + "': " + e.getMessage(),e); } // update the disk try { ((StdPDPGroup)group).saveGroupConfiguration(); } catch (IOException e) { - throw new PAPException("Unable to save new configuration for '" + group.getName() + "': " + e.getMessage()); + throw new PAPException("Unable to save new configuration for '" + group.getName() + "': " + e.getMessage(), e); } // save the new group into the Set diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPAPPolicy.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPAPPolicy.java index d69f38d95..56676f38b 100644 --- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPAPPolicy.java +++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPAPPolicy.java @@ -42,7 +42,7 @@ public class StdPAPPolicy implements OnapPAPPolicy, Serializable{ private List dynamicRuleAlgorithmCombo; private List dynamicRuleAlgorithmField1; private List dynamicRuleAlgorithmField2; - private List dynamicVariableList; + private transient List dynamicVariableList; private List dataTypeList; private String configBodyData = null; private String policyID = null; diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDP.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDP.java index 20dbfae07..4c1f4aadc 100644 --- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDP.java +++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDP.java @@ -45,11 +45,11 @@ public class StdPDP extends StdPDPItemSetChangeNotifier implements OnapPDP, Comp private Integer jmxport = 0; - private PDPStatus status = new StdPDPStatus(); + private transient PDPStatus status = new StdPDPStatus(); - private Set policies = new HashSet<>(); + private transient Set policies = new HashSet<>(); - private Set pipConfigs = new HashSet<>(); + private transient Set pipConfigs = new HashSet<>(); public StdPDP() { @@ -89,7 +89,6 @@ public class StdPDP extends StdPDPItemSetChangeNotifier implements OnapPDP, Comp } else if (key.toString().endsWith(".description")) { this.description = properties.getProperty(key.toString()); }else if (key.toString().endsWith(".jmxport")) { - //todo fix this hackjob if (properties.getProperty(key.toString()) != null && properties.getProperty(key.toString()).trim().length() > 0){ logger.debug("initialize before: " + this.jmxport); this.jmxport = Integer.valueOf( properties.getProperty(key.toString())); diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPGroup.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPGroup.java index 63cc4b4fc..28f6a4d03 100644 --- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPGroup.java +++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPGroup.java @@ -70,20 +70,20 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG private String description; - private StdPDPGroupStatus status = new StdPDPGroupStatus(Status.UNKNOWN); + private transient StdPDPGroupStatus status = new StdPDPGroupStatus(Status.UNKNOWN); - private Set pdps = new HashSet<>(); + private transient Set pdps = new HashSet<>(); - private Set policies = new HashSet<>(); + private transient Set policies = new HashSet<>(); - private Set selectedPolicies = new HashSet<>(); + private transient Set selectedPolicies = new HashSet<>(); - private Set pipConfigs = new HashSet<>(); + private transient Set pipConfigs = new HashSet<>(); private String operation; @JsonIgnore - private Path directory; + private transient Path directory; @JsonIgnore private Integer jmxport; @@ -187,7 +187,7 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG try (OutputStream os = Files.newOutputStream(file)) { policyProperties.store(os, ""); } catch (Exception e) { - throw new PAPException("Failed to create new default policy properties file '" + file +"'"); + throw new PAPException("Failed to create new default policy properties file '" + file +"'", e); } } else { // load previously existing file @@ -225,13 +225,13 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG pipProperties.store(os, ""); } } catch (Exception e) { - throw new PAPException("Failed to create new default pip properties file '" + file +"'"); + throw new PAPException("Failed to create new default pip properties file '" + file +"'", e); } //Even if we create a new pip file, we still need to parse and load the properties try{ this.readPIPProperties(directory, pipProperties); }catch(Exception e){ - throw new PAPException("Failed to load the new pip properties file"); + throw new PAPException("Failed to load the new pip properties file", e); } } else { try { diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPItemSetChangeNotifier.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPItemSetChangeNotifier.java index d23501f26..cc80b62c2 100644 --- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPItemSetChangeNotifier.java +++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPItemSetChangeNotifier.java @@ -41,7 +41,7 @@ public class StdPDPItemSetChangeNotifier { public void addItemSetChangeListener(StdItemSetChangeListener listener) { if (this.listeners == null) { - this.listeners = new LinkedList(); + this.listeners = new LinkedList<>(); } this.listeners.add(listener); } diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPStatus.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPStatus.java index f8759956c..5349f8340 100644 --- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPStatus.java +++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPStatus.java @@ -38,15 +38,15 @@ public class StdPDPStatus implements Serializable, PDPStatus { private Set loadWarnings = new HashSet<>(); - private Set loadedPolicies = new HashSet<>(); + private transient Set loadedPolicies = new HashSet<>(); - private Set loadedRootPolicies = new HashSet<>(); + private transient Set loadedRootPolicies = new HashSet<>(); - private Set failedPolicies = new HashSet<>(); + private transient Set failedPolicies = new HashSet<>(); - private Set loadedPIPConfigs = new HashSet<>(); + private transient Set loadedPIPConfigs = new HashSet<>(); - private Set failedPIPConfigs = new HashSet<>(); + private transient Set failedPIPConfigs = new HashSet<>(); public StdPDPStatus() { } -- cgit 1.2.3-korg