Fix Blocker/Critical sonar issues 75/11675/1
authorshashikanth <shashikanth.vh@huawei.com>
Mon, 11 Sep 2017 13:22:19 +0000 (18:52 +0530)
committershashikanth <shashikanth.vh@huawei.com>
Mon, 11 Sep 2017 13:22:24 +0000 (18:52 +0530)
Fix Blocker/Critical sonar issues in ccsdk/core module
https://sonar.onap.org/component_issues?id=org.openecomp.sdnc.core%3Asdnc-core#resolved=false|severities=BLOCKER

Issue-Id: CCSDK-67
Change-Id: Iec86b90f7085f4b96d4f92adf4064b70640fcf22
Signed-off-by: shashikanth.vh <shashikanth.vh@huawei.com>
dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java

index 46c003a..7ed5430 100644 (file)
 
 package org.onap.ccsdk.sli.core.dblib;
 
+import com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException;
+import org.apache.tomcat.jdbc.pool.PoolExhaustedException;
+import org.onap.ccsdk.sli.core.dblib.config.DbConfigPool;
+import org.onap.ccsdk.sli.core.dblib.factory.AbstractDBResourceManagerFactory;
+import org.onap.ccsdk.sli.core.dblib.factory.AbstractResourceManagerFactory;
+import org.onap.ccsdk.sli.core.dblib.factory.DBConfigFactory;
+import org.onap.ccsdk.sli.core.dblib.pm.PollingWorker;
+import org.onap.ccsdk.sli.core.dblib.pm.SQLExecutionMonitor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.sql.DataSource;
+import javax.sql.rowset.CachedRowSet;
 import java.io.PrintWriter;
 import java.sql.Connection;
 import java.sql.SQLDataException;
@@ -38,26 +51,9 @@ import java.util.PriorityQueue;
 import java.util.Properties;
 import java.util.Queue;
 import java.util.Set;
-import java.util.Timer;
 import java.util.TimerTask;
-import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.atomic.AtomicBoolean;
 
-import javax.sql.DataSource;
-import javax.sql.rowset.CachedRowSet;
-
-import org.apache.tomcat.jdbc.pool.PoolExhaustedException;
-import org.onap.ccsdk.sli.core.dblib.config.DbConfigPool;
-import org.onap.ccsdk.sli.core.dblib.factory.AbstractDBResourceManagerFactory;
-import org.onap.ccsdk.sli.core.dblib.factory.AbstractResourceManagerFactory;
-import org.onap.ccsdk.sli.core.dblib.factory.DBConfigFactory;
-import org.onap.ccsdk.sli.core.dblib.pm.PollingWorker;
-import org.onap.ccsdk.sli.core.dblib.pm.SQLExecutionMonitor;
-
-import com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 
 /**
  * @version $Revision: 1.15 $
@@ -336,11 +332,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
                                }
                                sources.remove(active);
                                return active.getData(statement, arguments);
-                       } catch(SQLDataException exc){
-                               throw exc;
-                       } catch(SQLSyntaxErrorException exc){
-                               throw exc;
-                       } catch(SQLIntegrityConstraintViolationException exc){
+                       } catch(SQLDataException | SQLSyntaxErrorException | SQLIntegrityConstraintViolationException exc){
                                throw exc;
                        } catch(Throwable exc){
                                lastException = exc;
@@ -432,7 +424,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
        }
 
        CachedDataSource findMaster() throws PoolExhaustedException, MySQLNonTransientConnectionException {
-               CachedDataSource master = null;
+               CachedDataSource master;
                CachedDataSource[] dss = this.dsQueue.toArray(new CachedDataSource[0]);
                for(int i=0; i<dss.length; i++) {
                        if(!dss[i].isSlave()) {
@@ -444,10 +436,8 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
                                return master;
                        }
                }
-               if(master == null) {
-                       LOGGER.warn("MASTER not found.");
-               }
-               return master;
+               LOGGER.warn("MASTER not found.");
+               return null;
        }