More sonar issues cleanup 56/104556/2
authorPamela Dragosh <pdragosh@research.att.com>
Fri, 27 Mar 2020 12:03:24 +0000 (08:03 -0400)
committerPamela Dragosh <pdragosh@research.att.com>
Fri, 27 Mar 2020 14:56:46 +0000 (10:56 -0400)
Either log or rethrow
Use boolean expression
Add at least one test
Remove commented out code

Issue-ID: POLICY-2204
Change-Id: I4fdf31aea75303e4f49d25198eb3b12341995bfe
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
gson/src/test/java/org/onap/policy/common/gson/internal/FieldDeserializerTest.java
integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java
integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitor.java
integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagement.java
policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedBusTopicSource.java
policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java
utils-test/src/main/java/org/onap/policy/common/utils/time/TestTimeMulti.java
utils-test/src/main/java/org/onap/policy/common/utils/time/WorkItem.java
utils-test/src/test/java/org/onap/policy/common/utils/time/WorkItemTest.java

index 509ddb7..acb241e 100644 (file)
@@ -1,8 +1,8 @@
-/*
+/*-
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -61,18 +61,18 @@ public class FieldDeserializerTest {
         // no value in tree - text remains unchanged
         text = INITIAL_VALUE;
         deser.getFromTree(json, this);
-        assertEquals(text, INITIAL_VALUE);
+        assertEquals(INITIAL_VALUE, text);
 
         // null value in tree - text remains unchanged
         json.add(TEXT_FIELD_NAME, JsonNull.INSTANCE);
         deser.getFromTree(json, this);
-        assertEquals(text, INITIAL_VALUE);
+        assertEquals(INITIAL_VALUE, text);
 
         // now assign a value - text should be changed now
         json.addProperty(TEXT_FIELD_NAME, NEW_VALUE);
 
         deser.getFromTree(json, this);
-        assertEquals(text, NEW_VALUE);
+        assertEquals(NEW_VALUE, text);
 
         /*
          * check list field
index 4e718a6..a7b7fd8 100644 (file)
@@ -1,8 +1,8 @@
-/*
+/*--
  * ============LICENSE_START=======================================================
  * Integrity Audit
  * ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -60,16 +60,11 @@ public class DbAudit {
      */
     public DbAudit(DbDao dbDao) {
 
-        if (logger.isDebugEnabled()) {
-            logger.debug("Constructor: Entering");
-        }
+        logger.debug("Constructor: Entering");
 
         this.dbDao = dbDao;
 
-        if (logger.isDebugEnabled()) {
-            logger.debug("Constructor: Exiting");
-        }
-
+        logger.debug("Constructor: Exiting");
     }
 
     /**
@@ -153,8 +148,6 @@ public class DbAudit {
         if (logger.isDebugEnabled()) {
             logger.debug("dbAudit: Exiting");
         }
-
-        return; // all done
     }
 
     private void compareList(String persistenceUnit, List<IntegrityAuditEntity> iaeList, IntegrityAuditEntity myIae,
@@ -246,7 +239,7 @@ public class DbAudit {
              * again for all nodes later.
              */
             compareMineWithTheirs(myEntries, theirEntries, clazzName, misMatchedMap);
-        } // end for (IntegrityAuditEntity iae : iaeList)
+        }
     }
 
     private void compareMineWithTheirs(Map<Object, Object> myEntries, Map<Object, Object> theirEntries,
@@ -332,7 +325,7 @@ public class DbAudit {
                     logger.debug("dbAudit: Second comparison; waking from sleep");
                 }
             }
-        } // end: for(String clazzName: classNameList)
+        }
 
         if (errorCount != 0) {
             String msg = " DB Audit: " + errorCount
index 1372b4f..d96aa44 100644 (file)
@@ -925,7 +925,7 @@ public class IntegrityMonitor {
             }
             // check the next group
 
-        } // end for (String group : depGroups)
+        }
 
         return dependencyOk;
     }
@@ -963,7 +963,7 @@ public class IntegrityMonitor {
                 appendSeparator(errorMsg);
                 errorMsg.append(failMsg);
             }
-        } // end for (String dep : dependencies)
+        }
 
         // if all dependencies in a group are failed, set this
         // resource's state to disable dependency
@@ -1206,7 +1206,7 @@ public class IntegrityMonitor {
             } catch (Exception e1) {
                 logger.error(EXCEPTION_STRING, e1);
             }
-            logger.error("writeFpc DB table commit failed with exception", e);
+            logger.error("writeFpc DB table commit failed with exception");
             throw e;
         }
     }
@@ -1500,8 +1500,8 @@ public class IntegrityMonitor {
                 if (sme != null && !sme.getOpState().equals(StateManagement.DISABLED)) {
                     disableFailed(sme);
                 }
-            } // end if(diffMs > staleMs)
-        } // end for(ForwardProgressEntity fpe : fpList)
+            }
+        }
         logger.debug("IntegrityMonitor.executeStateAudit(): exit");
     }
 
@@ -1817,7 +1817,7 @@ public class IntegrityMonitor {
             allNotWellMap = new HashMap<>();
         }
 
-        if (asw) {
+        if (Boolean.TRUE.equals(asw)) {
             logger.info("allSeemsWell: ALL SEEMS WELL: key = {}, msg = {}", key, msg);
             allSeemsWellMap.put(key, msg);
             allNotWellMap.remove(key);
index 7a018ef..65ebf2d 100644 (file)
@@ -174,7 +174,6 @@ public class StateManagement {
                 logger.debug("StateManagement: {}() operation completed, resourceName = {}",
                                 methodName, resourceName);
             } catch (final Exception ex) {
-                logger.error("StateManagement.{}() caught unexpected exception: ", methodName, ex);
                 throw new StateManagementException("StateManagement." + methodName + "() Exception: " + ex);
             }
         }
@@ -476,7 +475,6 @@ public class StateManagement {
             }
         } catch (final Exception ex) {
             final String message = "findStateManagementEntity exception";
-            logger.error("{}: {}", message, ex.toString(), ex);
             throw new EntityRetrievalException(message, ex);
         }
     }
index 164f2b1..510ddaa 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * policy-endpoints
  * ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2018-2019 Samsung Electronics Co., Ltd.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -47,7 +47,7 @@ public abstract class SingleThreadedBusTopicSource extends BusTopicBase
      * Not to be converted to PolicyLogger. This will contain all instract /out traffic and only
      * that in a single file in a concise format.
      */
-    private static Logger logger = LoggerFactory.getLogger(InlineBusTopicSink.class);
+    private static Logger logger = LoggerFactory.getLogger(SingleThreadedBusTopicSource.class);
 
     /**
      * Bus consumer group.
@@ -134,8 +134,7 @@ public abstract class SingleThreadedBusTopicSource extends BusTopicBase
                 logger.info("{}: register: start not attempted", this);
             }
         } catch (Exception e) {
-            logger.warn("{}: cannot start after registration of because of: {}", this, topicListener, e.getMessage(),
-                    e);
+            logger.warn("{}: cannot start after registration of because of: {}", this, topicListener, e);
         }
     }
 
@@ -176,8 +175,7 @@ public abstract class SingleThreadedBusTopicSource extends BusTopicBase
                     busPollerThread.start();
                     return true;
                 } catch (Exception e) {
-                    logger.warn("{}: cannot start because of {}", this, e.getMessage(), e);
-                    throw new IllegalStateException(e);
+                    throw new IllegalStateException(this + ": cannot start", e);
                 }
             }
         }
index e5d08a2..6ed2e31 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2018-2019 Samsung Electronics Co., Ltd.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -75,9 +75,7 @@ public class SingleThreadedDmaapTopicSource extends SingleThreadedBusTopicSource
         try {
             this.init();
         } catch (Exception e) {
-            logger.error("ERROR during init in dmaap-source: cannot create topic {} because of {}",
-                            topic, e.getMessage(), e);
-            throw new IllegalArgumentException(e);
+            throw new IllegalArgumentException("ERROR during init in dmaap-source: cannot create topic " + topic, e);
         }
     }
 
index f52105e..5002edf 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -29,7 +29,6 @@ import java.util.PriorityQueue;
 import java.util.concurrent.Callable;
 import java.util.concurrent.TimeUnit;
 import lombok.Getter;
-import org.onap.policy.common.utils.time.TestTime;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -180,7 +179,7 @@ public class TestTimeMulti extends TestTime {
             long realEnd = System.currentTimeMillis() + maxWaitMs;
 
             while (System.currentTimeMillis() < realEnd) {
-                if (condition.call()) {
+                if (Boolean.TRUE.equals(condition.call())) {
                     return;
                 }
 
index af3d5d7..cd69060 100644 (file)
@@ -1,8 +1,8 @@
-/*
+/*--
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -22,7 +22,6 @@ package org.onap.policy.common.utils.time;
 
 import lombok.AccessLevel;
 import lombok.Getter;
-import org.onap.policy.common.utils.time.TestTime;
 
 /**
  * Work item to be executed at some time.
index 4e6f92b..d2fc8d5 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
 
 package org.onap.policy.common.utils.time;
 
+import static org.assertj.core.api.Assertions.assertThatCode;
 import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -88,7 +89,7 @@ public class WorkItemTest {
     @Test
     public void testFire() {
         // ensure no exception is thrown
-        item.fire();
+        assertThatCode(() -> item.fire()).doesNotThrowAnyException();
     }
 
     @Test