diff options
author | Conor Ward <conor.ward@ericsson.com> | 2018-09-19 15:07:46 +0000 |
---|---|---|
committer | Conor Ward <conor.ward@ericsson.com> | 2018-09-19 15:07:46 +0000 |
commit | 5ecbc83f99f72a197447857f8520449d4cba040e (patch) | |
tree | a4430e9ce3e69bb1af286852eee7d5feeec4253b | |
parent | c2c9a18dc3212fa69bcb173f5b0ed97c7996c044 (diff) |
Fix Sonar bugs
Change-Id: I76b212bf18e2988cba90869fe078aa922c23b44b
Signed-off-by: Conor Ward <conor.ward@ericsson.com>
Issue-ID: DMAAP-638
10 files changed, 35 insertions, 70 deletions
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 9ddbc25a..5f851398 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 @@ public class NodeServlet extends HttpServlet { .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 2c013ca5..d5b15bca 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 @@ public class NodeUtils { 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 @@ public class NodeUtils { * 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 c35978b6..685d5528 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 @@ import static org.onap.dmaap.datarouter.provisioning.utils.HttpServletUtils.send @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 @@ public class InternalServlet extends ProxyServlet { } 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 f2c511c1..563e6f7f 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 @@ public class Poker extends TimerTask { */ 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 @@ public class Poker extends TimerTask { * @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 @@ public class Poker extends TimerTask { 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 d500bb31..05502760 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 @@ public class PublishServlet extends BaseServlet { 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 @@ public class PublishServlet extends BaseServlet { // 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 3902dc63..b77062fa 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 @@ public class StatisticsServlet extends BaseServlet { 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 dec3cc13..1518859a 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 @@ public class LOGJSONObject { try { return this.toString(0); } catch (Exception e) { - return null; + return ""; } } @@ -1495,7 +1495,7 @@ public class LOGJSONObject { */ @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 @@ public class LOGJSONObject { @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 4576bd26..d0178fd6 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 class URLUtilities { 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 4346a0ec..fe9c4601 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 @@ public class FeedReport extends ReportBase { 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 @@ public class FeedReport extends ReportBase { 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 58bc4c40..38425748 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 @@ public class SampleSubscriberServlet extends HttpServlet { 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. |