Fix Sonar bugs

Change-Id: I76b212bf18e2988cba90869fe078aa922c23b44b
Signed-off-by: Conor Ward <conor.ward@ericsson.com>
Issue-ID: DMAAP-638
diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeServlet.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeServlet.java
index 9ddbc25..5f85139 100644
--- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeServlet.java
+++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeServlet.java
@@ -69,18 +69,15 @@
         .getLogger("org.onap.dmaap.datarouter.node.NodeServlet");
 
     static {
-        try {
-            final String ws = "\\s*";
-            // assume that \\ and \" have been replaced by X
-            final String string = "\"[^\"]*\"";
-            //String string = "\"(?:[^\"\\\\]|\\\\.)*\"";
-            final String number = "[+-]?(?:\\.\\d+|(?:0|[1-9]\\d*)(?:\\.\\d*)?)(?:[eE][+-]?\\d+)?";
-            final String value = "(?:" + string + "|" + number + "|null|true|false)";
-            final String item = string + ws + ":" + ws + value + ws;
-            final String object = ws + "\\{" + ws + "(?:" + item + "(?:" + "," + ws + item + ")*)?\\}" + ws;
-            MetaDataPattern = Pattern.compile(object, Pattern.DOTALL);
-        } catch (Exception e) {
-        }
+        final String ws = "\\s*";
+        // assume that \\ and \" have been replaced by X
+        final String string = "\"[^\"]*\"";
+        //String string = "\"(?:[^\"\\\\]|\\\\.)*\"";
+        final String number = "[+-]?(?:\\.\\d+|(?:0|[1-9]\\d*)(?:\\.\\d*)?)(?:[eE][+-]?\\d+)?";
+        final String value = "(?:" + string + "|" + number + "|null|true|false)";
+        final String item = string + ws + ":" + ws + value + ws;
+        final String object = ws + "\\{" + ws + "(?:" + item + "(?:" + "," + ws + item + ")*)?\\}" + ws;
+        MetaDataPattern = Pattern.compile(object, Pattern.DOTALL);
     }
 
     /**
diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeUtils.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeUtils.java
index 2c013ca..d5b15bc 100644
--- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeUtils.java
+++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeUtils.java
@@ -53,12 +53,6 @@
     private static EELFLogger eelfLogger = EELFManager.getInstance()
         .getLogger("org.onap.dmaap.datarouter.node.NodeUtils");
     private static Logger nodeUtilsLogger = Logger.getLogger("org.onap.dmaap.datarouter.node.NodeUtils");
-    private static SimpleDateFormat logDate;
-
-    static {
-        logDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
-        logDate.setTimeZone(TimeZone.getTimeZone("GMT"));
-    }
 
     private NodeUtils() {
     }
@@ -241,6 +235,8 @@
      * Format a logging timestamp as yyyy-mm-ddThh:mm:ss.mmmZ
      */
     public static synchronized String logts(Date when) {
+        SimpleDateFormat logDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
+        logDate.setTimeZone(TimeZone.getTimeZone("GMT"));
         return (logDate.format(when));
     }
 
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/InternalServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/InternalServlet.java
index c35978b..685d552 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/InternalServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/InternalServlet.java
@@ -156,6 +156,7 @@
 @SuppressWarnings("serial")
 public class InternalServlet extends ProxyServlet {
 
+    private static final Object lock = new Object();
     private static Integer logseq = 0; // another piece of info to make log spool file names unique
     //Adding EELF Logger Rally:US664892
     private static EELFLogger eelflogger = EELFManager.getInstance()
@@ -454,7 +455,7 @@
             }
             String spooldir = (new DB()).getProperties().getProperty("org.onap.dmaap.datarouter.provserver.spooldir");
             String spoolname = String.format("%d-%d-", System.currentTimeMillis(), Thread.currentThread().getId());
-            synchronized (logseq) {
+            synchronized (lock) {
                 // perhaps unnecessary, but it helps make the name unique
                 spoolname += logseq.toString();
                 logseq++;
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Poker.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Poker.java
index f2c511c..563e6f7 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Poker.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Poker.java
@@ -64,6 +64,8 @@
      */
     private static final String POKE_URL_TEMPLATE = "http://%s/internal/fetchProv";
 
+    private static final Object lock = new Object();
+
     /**
      * This is a singleton -- there is only one Poker object in the server
      */
@@ -109,7 +111,7 @@
      * @param t2 the second timer set the outer bound on how long to wait.  It cannot be reset.
      */
     public void setTimers(long t1, long t2) {
-        synchronized (thisPod) {
+        synchronized (lock) {
             if (timer1 == 0 || t1 > timer1) {
                 timer1 = t1;
             }
@@ -144,7 +146,7 @@
             if (timer1 > 0) {
                 long now = System.currentTimeMillis();
                 boolean fire = false;
-                synchronized (thisPod) {
+                synchronized (lock) {
                     if (now > timer1 || now > timer2) {
                         timer1 = timer2 = 0;
                         fire = true;
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/PublishServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/PublishServlet.java
index d500bb3..0550276 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/PublishServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/PublishServlet.java
@@ -64,6 +64,7 @@
     private List<IngressRoute> irt;
     //Adding EELF Logger Rally:US664892
     private static EELFLogger eelflogger = EELFManager.getInstance().getLogger("org.onap.dmaap.datarouter.provisioning.PublishServlet");
+    private static final Object lock = new Object();
 
 
     @Override
@@ -138,7 +139,7 @@
         // Check to see if the IRT needs to be updated
         Poker p = Poker.getPoker();
         String s = p.getProvisioningString();
-        synchronized (provstring) {
+        synchronized (lock) {
             if (irt == null || (s.length() != provstring.length()) || !s.equals(provstring)) {
                 // Provisioning string has changed -- update the IRT
                 provstring = s;
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java
index 3902dc6..b77062f 100755
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java
@@ -546,10 +546,8 @@
       intlogger.debug(filterQuery);

       long start = System.currentTimeMillis();

       DB db = new DB();

-      ResultSet rs = null;

       try (Connection conn = db.getConnection()) {

-        try (PreparedStatement pst = conn.prepareStatement(filterQuery)) {

-          rs = pst.executeQuery();

+        try (ResultSet rs = conn.prepareStatement(filterQuery).executeQuery()) {

           if (outputType.equals("csv")) {

             resp.setContentType("application/octet-stream");

             Date date = new Date();

diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObject.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObject.java
index dec3cc1..1518859 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObject.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObject.java
@@ -1446,7 +1446,7 @@
         try {
             return this.toString(0);
         } catch (Exception e) {
-            return null;
+            return "";
         }
     }
 
@@ -1495,7 +1495,7 @@
      */
     @SuppressWarnings("unchecked")
     public static String valueToString(Object value) throws JSONException {
-        if (value == null || value.equals(null)) {
+        if (value == null) {
             return "null";
         }
         if (value instanceof JSONString) {
@@ -1601,7 +1601,7 @@
     @SuppressWarnings("unchecked")
     static final Writer writeValue(Writer writer, Object value,
                                    int indentFactor, int indent) throws JSONException, IOException {
-        if (value == null || value.equals(null)) {
+        if (value == null) {
             writer.write("null");
         } else if (value instanceof LOGJSONObject) {
             ((LOGJSONObject) value).write(writer, indentFactor, indent);
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/URLUtilities.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/URLUtilities.java
index 4576bd2..d0178fd 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/URLUtilities.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/URLUtilities.java
@@ -115,7 +115,7 @@
     public static String generatePeerLogsURL() {

         //Fixes for Itrack ticket - DATARTR-4#Fixing if only one Prov is configured, not to give exception to fill logs.

         String peerPodUrl = getPeerPodName();

-        if (peerPodUrl.equals("") || peerPodUrl==null) {

+        if (peerPodUrl == null || peerPodUrl.equals("")) {

             return "";

         }

 

diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/FeedReport.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/FeedReport.java
index 4346a0e..fe9c460 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/FeedReport.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/FeedReport.java
@@ -72,36 +72,12 @@
            try( PreparedStatement ps = conn.prepareStatement(SELECT_SQL)) {

                try (ResultSet rs = ps.executeQuery()) {

                    while (rs.next()) {

-                       if (alg1) {

-                           String date = rs.getString("date");

-                           String type = rs.getString("type");

-                           int feedid = rs.getInt("feedid");

-                           int subid = type.equals("del") ? rs.getInt("delivery_subid") : 0;

-                           int count = rs.getInt("count");

-                           sb.append(date + "," + type + "," + feedid + "," + subid + "," + count + "\n");

-                       } else {

-                           String date = rs.getString("date");

-                           JSONObject datemap = jo.optJSONObject(date);

-                           if (datemap == null) {

-                               datemap = new JSONObject();

-                               jo.put(date, datemap);

-                           }

-                           int feed = rs.getInt("FEEDID");

-                           JSONObject feedmap = datemap.optJSONObject("" + feed);

-                           if (feedmap == null) {

-                               feedmap = new JSONObject();

-                               feedmap.put("pubcount", 0);

-                               datemap.put("" + feed, feedmap);

-                           }

-                           String type = rs.getString("TYPE");

-                           int count = rs.getInt("count");

-                           if (type.equals("pub")) {

-                               feedmap.put("pubcount", count);

-                           } else if (type.equals("del")) {

-                               String subid = "" + rs.getInt("DELIVERY_SUBID");

-                               feedmap.put(subid, count);

-                           }

-                       }

+                       String date = rs.getString("date");

+                       String type = rs.getString("type");

+                       int feedid = rs.getInt("feedid");

+                       int subid = type.equals("del") ? rs.getInt("delivery_subid") : 0;

+                       int count = rs.getInt("count");

+                       sb.append(date + "," + type + "," + feedid + "," + subid + "," + count + "\n");

                    }

                }

            }

@@ -110,15 +86,9 @@
             e.printStackTrace();

         }

         logger.debug("Query time: " + (System.currentTimeMillis() - start) + " ms");

-        try {

-            PrintWriter os = new PrintWriter(outfile);

-            if (alg1) {

-                os.print("date,type,feedid,subid,count\n");

-                os.print(sb.toString());

-            } else {

-                os.println(toHTML(jo));

-            }

-            os.close();

+        try (PrintWriter os = new PrintWriter(outfile)) {

+            os.print("date,type,feedid,subid,count\n");

+            os.print(sb.toString());

         } catch (FileNotFoundException e) {

             System.err.println("File cannot be written: " + outfile);

         }

diff --git a/datarouter-subscriber/src/main/java/org/onap/dmaap/datarouter/subscriber/SampleSubscriberServlet.java b/datarouter-subscriber/src/main/java/org/onap/dmaap/datarouter/subscriber/SampleSubscriberServlet.java
index 58bc4c4..3842574 100644
--- a/datarouter-subscriber/src/main/java/org/onap/dmaap/datarouter/subscriber/SampleSubscriberServlet.java
+++ b/datarouter-subscriber/src/main/java/org/onap/dmaap/datarouter/subscriber/SampleSubscriberServlet.java
@@ -38,8 +38,8 @@
 
   private static Logger logger =
       Logger.getLogger("org.onap.dmaap.datarouter.subscriber.SampleSubscriberServlet");
-  private String outputDirectory;
-  private String basicAuth;
+  private static String outputDirectory;
+  private static String basicAuth;
 
   /**
    * Configure the SampleSubscriberServlet.