CachedElement.java - Sonar Fixes 93/79293/2
authorDriptaroop Das <driptaroop.das@in.ibm.com>
Wed, 27 Feb 2019 19:31:38 +0000 (01:01 +0530)
committerTakamune Cho <takamune.cho@att.com>
Thu, 28 Feb 2019 14:45:45 +0000 (14:45 +0000)
CachedElement.java - Sonar Fixes

Issue-ID: APPC-1508
Change-Id: I24bdb1ab1e3c00975eba4ea92dcf34b8e26849dc
Signed-off-by: Driptaroop Das <driptaroop.das@in.ibm.com>
appc-core/appc-common-bundle/src/main/java/org/onap/appc/pool/CachedElement.java

index 093ce10..c070a17 100644 (file)
 
 package org.onap.appc.pool;
 
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
 import java.io.Closeable;
 import java.io.IOException;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.util.concurrent.atomic.AtomicBoolean;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
 
 /**
  * This class is used as a "wrapper" for any closeable elements that are cached in a pool. It is
@@ -90,7 +91,7 @@ public class CachedElement<T extends Closeable>
         CachedElement<T> ce = new CachedElement<>(pool, element);
         boolean found = false;
         for (Class<?> intf : interfaces) {
-            if (intf.getName().equals(CacheManagement.class.getName())) {
+            if (intf.isAssignableFrom(CacheManagement.class)) {
                 found = true;
                 break;
             }
@@ -180,10 +181,8 @@ public class CachedElement<T extends Closeable>
 
         switch (method.getName()) {
             case "close":
-                if (released.compareAndSet(false, true)) {
-                    if (!pool.isDrained()) {
-                        pool.release((T) proxy);
-                    }
+                if (released.compareAndSet(false, true) && !pool.isDrained()) {
+                    pool.release((T) proxy);
                 }
                 break;
             case "equals":