You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/09/14 17:41:52 UTC

[commons-pool] branch master updated (e34ee19 -> 0205645)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-pool.git.


    from e34ee19  Nex release will be 2.9.0.
     new 2edd1fc  Add @SuppressWarnings. Better local var name.
     new 0205645  Use try-with-resources.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../commons/pool2/impl/GenericObjectPool.java      | 16 ++--
 .../org/apache/commons/pool2/TestPoolUtils.java    | 86 ++++++++++------------
 2 files changed, 49 insertions(+), 53 deletions(-)


[commons-pool] 01/02: Add @SuppressWarnings. Better local var name.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-pool.git

commit 2edd1fc546da70ec7508b3b83e4d516a185d5bf4
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Sep 14 13:23:17 2020 -0400

    Add @SuppressWarnings. Better local var name.
---
 .../org/apache/commons/pool2/impl/GenericObjectPool.java | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java b/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java
index 1a3a02b..7d182ab 100644
--- a/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java
+++ b/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java
@@ -318,6 +318,7 @@ public class GenericObjectPool<T> extends BaseGenericObjectPool<T>
      *
      * @see AbandonedConfig
      */
+    @SuppressWarnings("resource") // PrintWriter is managed elsewhere
     public void setAbandonedConfig(final AbandonedConfig abandonedConfig) {
         if (abandonedConfig == null) {
             this.abandonedConfig = null;
@@ -1062,13 +1063,14 @@ public class GenericObjectPool<T> extends BaseGenericObjectPool<T>
      * Recovers abandoned objects which have been checked out but
      * not used since longer than the removeAbandonedTimeout.
      *
-     * @param ac The configuration to use to identify abandoned objects
+     * @param abandonedConfig The configuration to use to identify abandoned objects
      */
-    private void removeAbandoned(final AbandonedConfig ac) {
+    @SuppressWarnings("resource") // PrintWriter is managed elsewhere
+    private void removeAbandoned(final AbandonedConfig abandonedConfig) {
         // Generate a list of abandoned objects to remove
         final long now = System.currentTimeMillis();
         final long timeout =
-                now - (ac.getRemoveAbandonedTimeout() * 1000L);
+                now - (abandonedConfig.getRemoveAbandonedTimeout() * 1000L);
         final ArrayList<PooledObject<T>> remove = new ArrayList<>();
         final Iterator<PooledObject<T>> it = allObjects.values().iterator();
         while (it.hasNext()) {
@@ -1086,8 +1088,8 @@ public class GenericObjectPool<T> extends BaseGenericObjectPool<T>
         final Iterator<PooledObject<T>> itr = remove.iterator();
         while (itr.hasNext()) {
             final PooledObject<T> pooledObject = itr.next();
-            if (ac.getLogAbandoned()) {
-                pooledObject.printStackTrace(ac.getLogWriter());
+            if (abandonedConfig.getLogAbandoned()) {
+                pooledObject.printStackTrace(abandonedConfig.getLogWriter());
             }
             try {
                 invalidateObject(pooledObject.getObject(), DestroyMode.ABANDONED);
@@ -1102,8 +1104,8 @@ public class GenericObjectPool<T> extends BaseGenericObjectPool<T>
 
     @Override
     public void use(final T pooledObject) {
-        final AbandonedConfig ac = this.abandonedConfig;
-        if (ac != null && ac.getUseUsageTracking()) {
+        final AbandonedConfig abandonedCfg = this.abandonedConfig;
+        if (abandonedCfg != null && abandonedCfg.getUseUsageTracking()) {
             final PooledObject<T> wrapper = allObjects.get(new IdentityWrapper<>(pooledObject));
             wrapper.use();
         }


[commons-pool] 02/02: Use try-with-resources.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-pool.git

commit 02056450c8c00c08c66d03b2ed1d7beaab7c97ae
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Sep 14 13:41:42 2020 -0400

    Use try-with-resources.
---
 .../org/apache/commons/pool2/TestPoolUtils.java    | 86 ++++++++++------------
 1 file changed, 40 insertions(+), 46 deletions(-)

diff --git a/src/test/java/org/apache/commons/pool2/TestPoolUtils.java b/src/test/java/org/apache/commons/pool2/TestPoolUtils.java
index f2ba7d2..b95d446 100644
--- a/src/test/java/org/apache/commons/pool2/TestPoolUtils.java
+++ b/src/test/java/org/apache/commons/pool2/TestPoolUtils.java
@@ -382,8 +382,7 @@ public class TestPoolUtils {
 
     @Test
     public void testSynchronizedPoolObjectPool() throws Exception {
-        try {
-            PoolUtils.synchronizedPool((ObjectPool<Object>) null);
+        try (final ObjectPool<Object> synchronizedPool = PoolUtils.synchronizedPool((ObjectPool<Object>) null)) {
             fail("PoolUtils.synchronizedPool(ObjectPool) must not allow a null pool.");
         } catch (final IllegalArgumentException iae) {
             // expected
@@ -391,9 +390,8 @@ public class TestPoolUtils {
 
         final List<String> calledMethods = new ArrayList<>();
         try (@SuppressWarnings("unchecked")
-            final ObjectPool<Object> op = createProxy(ObjectPool.class, calledMethods)) {
-
-            final ObjectPool<Object> sop = PoolUtils.synchronizedPool(op);
+        final ObjectPool<Object> op = createProxy(ObjectPool.class, calledMethods);
+                final ObjectPool<Object> sop = PoolUtils.synchronizedPool(op);) {
             final List<String> expectedMethods = invokeEveryMethod(sop);
             assertEquals(expectedMethods, calledMethods);
 
@@ -403,8 +401,8 @@ public class TestPoolUtils {
 
     @Test
     public void testSynchronizedPoolKeyedObjectPool() throws Exception {
-        try {
-            PoolUtils.synchronizedPool((KeyedObjectPool<Object, Object>) null);
+        try (final KeyedObjectPool<Object, Object> synchronizedPool = PoolUtils
+                .synchronizedPool((KeyedObjectPool<Object, Object>) null)) {
             fail("PoolUtils.synchronizedPool(KeyedObjectPool) must not allow a null pool.");
         } catch (final IllegalArgumentException iae) {
             // expected
@@ -412,9 +410,8 @@ public class TestPoolUtils {
 
         final List<String> calledMethods = new ArrayList<>();
         try (@SuppressWarnings("unchecked")
-            final KeyedObjectPool<Object, Object> kop = createProxy(KeyedObjectPool.class, calledMethods)) {
-
-            final KeyedObjectPool<Object, Object> skop = PoolUtils.synchronizedPool(kop);
+        final KeyedObjectPool<Object, Object> kop = createProxy(KeyedObjectPool.class, calledMethods);
+                final KeyedObjectPool<Object, Object> skop = PoolUtils.synchronizedPool(kop)) {
             final List<String> expectedMethods = invokeEveryMethod(skop);
             assertEquals(expectedMethods, calledMethods);
         }
@@ -425,16 +422,15 @@ public class TestPoolUtils {
     @Test
     public void testSynchronizedPoolableFactoryPoolableObjectFactory() throws Exception {
         try {
-            PoolUtils.synchronizedPooledFactory((PooledObjectFactory<Object>)null);
+            PoolUtils.synchronizedPooledFactory((PooledObjectFactory<Object>) null);
             fail("PoolUtils.synchronizedPoolableFactory(PoolableObjectFactory) must not allow a null factory.");
-        } catch(final IllegalArgumentException iae) {
+        } catch (final IllegalArgumentException iae) {
             // expected
         }
 
         final List<String> calledMethods = new ArrayList<>();
         @SuppressWarnings("unchecked")
-        final PooledObjectFactory<Object> pof =
-                createProxy(PooledObjectFactory.class, calledMethods);
+        final PooledObjectFactory<Object> pof = createProxy(PooledObjectFactory.class, calledMethods);
 
         final PooledObjectFactory<Object> spof = PoolUtils.synchronizedPooledFactory(pof);
         final List<String> expectedMethods = invokeEveryMethod(spof);
@@ -446,18 +442,18 @@ public class TestPoolUtils {
     @Test
     public void testSynchronizedPoolableFactoryKeyedPoolableObjectFactory() throws Exception {
         try {
-            PoolUtils.synchronizedKeyedPooledFactory((KeyedPooledObjectFactory<Object,Object>)null);
+            PoolUtils.synchronizedKeyedPooledFactory((KeyedPooledObjectFactory<Object, Object>) null);
             fail("PoolUtils.synchronizedPoolableFactory(KeyedPoolableObjectFactory) must not allow a null factory.");
-        } catch(final IllegalArgumentException iae) {
+        } catch (final IllegalArgumentException iae) {
             // expected
         }
 
         final List<String> calledMethods = new ArrayList<>();
         @SuppressWarnings("unchecked")
-        final KeyedPooledObjectFactory<Object,Object> kpof =
-                createProxy(KeyedPooledObjectFactory.class, calledMethods);
+        final KeyedPooledObjectFactory<Object, Object> kpof = createProxy(KeyedPooledObjectFactory.class,
+                calledMethods);
 
-        final KeyedPooledObjectFactory<Object,Object> skpof = PoolUtils.synchronizedKeyedPooledFactory(kpof);
+        final KeyedPooledObjectFactory<Object, Object> skpof = PoolUtils.synchronizedKeyedPooledFactory(kpof);
         final List<String> expectedMethods = invokeEveryMethod(skpof);
         assertEquals(expectedMethods, calledMethods);
 
@@ -466,15 +462,13 @@ public class TestPoolUtils {
 
     @Test
     public void testErodingPoolObjectPool() throws Exception {
-        try {
-            PoolUtils.erodingPool((ObjectPool<Object>) null);
+        try (final ObjectPool<Object> erodingPool = PoolUtils.erodingPool((ObjectPool<Object>) null)) {
             fail("PoolUtils.erodingPool(ObjectPool) must not allow a null pool.");
         } catch (final IllegalArgumentException iae) {
             // expected
         }
 
-        try {
-            PoolUtils.erodingPool((ObjectPool<Object>) null, 1f);
+        try (final ObjectPool<Object> erodingPool = PoolUtils.erodingPool((ObjectPool<Object>) null, 1f)) {
             fail("PoolUtils.erodingPool(ObjectPool, float) must not allow a null pool.");
         } catch (final IllegalArgumentException iae) {
             // expected
@@ -494,7 +488,7 @@ public class TestPoolUtils {
         };
 
         try (@SuppressWarnings({ "unchecked" })
-            final ObjectPool<?> o = PoolUtils.erodingPool(createProxy(ObjectPool.class, handler), -1f)) {
+        final ObjectPool<?> o = PoolUtils.erodingPool(createProxy(ObjectPool.class, handler), -1f)) {
             fail("PoolUtils.erodingPool(ObjectPool, float) must not allow a non-positive factor.");
         } catch (final IllegalArgumentException iae) {
             // expected
@@ -558,10 +552,10 @@ public class TestPoolUtils {
     @Test
     public void testErodingObjectPoolDefaultFactor() {
         try (@SuppressWarnings("unchecked")
-            final ObjectPool<Object> internalPool = createProxy(ObjectPool.class, (arg0, arg1, arg2) -> null)) {
-            final ObjectPool<Object> pool = PoolUtils.erodingPool(internalPool);
-            final String expectedToString = "ErodingObjectPool{factor=ErodingFactor{factor=1.0, idleHighWaterMark=1}, pool="
-                    + internalPool + "}";
+        final ObjectPool<Object> internalPool = createProxy(ObjectPool.class, (arg0, arg1, arg2) -> null);
+                final ObjectPool<Object> pool = PoolUtils.erodingPool(internalPool);) {
+            final String expectedToString = "ErodingObjectPool{factor=ErodingFactor{factor=1.0, idleHighWaterMark=1}, pool=" +
+                    internalPool + "}";
             // The factor is not exposed, but will be printed in the toString() method
             // In this case since we didn't pass one, the default 1.0f will be printed
             assertEquals(expectedToString, pool.toString());
@@ -570,22 +564,22 @@ public class TestPoolUtils {
 
     @Test
     public void testErodingPoolKeyedObjectPool() throws Exception {
-        try {
-            PoolUtils.erodingPool((KeyedObjectPool<Object, Object>) null);
+        try (final KeyedObjectPool<Object, Object> erodingPool = PoolUtils
+                .erodingPool((KeyedObjectPool<Object, Object>) null)) {
             fail("PoolUtils.erodingPool(KeyedObjectPool) must not allow a null pool.");
         } catch (final IllegalArgumentException iae) {
             // expected
         }
 
-        try {
-            PoolUtils.erodingPool((KeyedObjectPool<Object, Object>) null, 1f);
+        try (final KeyedObjectPool<Object, Object> erodingPool = PoolUtils
+                .erodingPool((KeyedObjectPool<Object, Object>) null, 1f)) {
             fail("PoolUtils.erodingPool(KeyedObjectPool, float) must not allow a null pool.");
         } catch (final IllegalArgumentException iae) {
             // expected
         }
 
-        try {
-            PoolUtils.erodingPool((KeyedObjectPool<Object, Object>) null, 1f, true);
+        try (final KeyedObjectPool<Object, Object> erodingPool = PoolUtils
+                .erodingPool((KeyedObjectPool<Object, Object>) null, 1f, true)) {
             fail("PoolUtils.erodingPool(KeyedObjectPool, float, boolean) must not allow a null pool.");
         } catch (final IllegalArgumentException iae) {
             // expected
@@ -605,14 +599,14 @@ public class TestPoolUtils {
         };
 
         try (@SuppressWarnings({ "unchecked" })
-            final KeyedObjectPool<?, ?> o = PoolUtils.erodingPool(createProxy(KeyedObjectPool.class, handler), 0f)) {
+        final KeyedObjectPool<?, ?> o = PoolUtils.erodingPool(createProxy(KeyedObjectPool.class, handler), 0f)) {
             fail("PoolUtils.erodingPool(ObjectPool, float) must not allow a non-positive factor.");
         } catch (final IllegalArgumentException iae) {
             // expected
         }
 
         try (@SuppressWarnings({ "unchecked" })
-            final KeyedObjectPool<?, ?> o = PoolUtils.erodingPool(createProxy(KeyedObjectPool.class, handler), 0f, false)) {
+        final KeyedObjectPool<?, ?> o = PoolUtils.erodingPool(createProxy(KeyedObjectPool.class, handler), 0f, false)) {
             fail("PoolUtils.erodingPool(ObjectPool, float, boolean) must not allow a non-positive factor.");
         } catch (final IllegalArgumentException iae) {
             // expected
@@ -680,10 +674,10 @@ public class TestPoolUtils {
     public void testErodingPoolKeyedObjectPoolDefaultFactor() {
         try (@SuppressWarnings("unchecked")
         final KeyedObjectPool<Object, Object> internalPool = createProxy(KeyedObjectPool.class,
-                (arg0, arg1, arg2) -> null)) {
-            final KeyedObjectPool<Object, Object> pool = PoolUtils.erodingPool(internalPool);
-            final String expectedToString = "ErodingKeyedObjectPool{factor=ErodingFactor{factor=1.0, idleHighWaterMark=1}, keyedPool="
-                    + internalPool + "}";
+                (arg0, arg1, arg2) -> null);
+                final KeyedObjectPool<Object, Object> pool = PoolUtils.erodingPool(internalPool)) {
+            final String expectedToString = "ErodingKeyedObjectPool{factor=ErodingFactor{factor=1.0, idleHighWaterMark=1}, keyedPool=" +
+                    internalPool + "}";
             // The factor is not exposed, but will be printed in the toString() method
             // In this case since we didn't pass one, the default 1.0f will be printed
             assertEquals(expectedToString, pool.toString());
@@ -692,22 +686,22 @@ public class TestPoolUtils {
 
     @Test
     public void testErodingPerKeyKeyedObjectPool() throws Exception {
-        try {
-            PoolUtils.erodingPool((KeyedObjectPool<Object, Object>) null, 1f, true);
+        try (final KeyedObjectPool<Object, Object> erodingPool = PoolUtils
+                .erodingPool((KeyedObjectPool<Object, Object>) null, 1f, true)) {
             fail("PoolUtils.erodingPool(KeyedObjectPool) must not allow a null pool.");
         } catch (final IllegalArgumentException iae) {
             // expected
         }
 
-        try {
-            PoolUtils.erodingPool((KeyedObjectPool<Object, Object>) null, 0f, true);
+        try (final KeyedObjectPool<Object, Object> erodingPool = PoolUtils
+                .erodingPool((KeyedObjectPool<Object, Object>) null, 0f, true)) {
             fail("PoolUtils.erodingPool(ObjectPool, float, boolean) must not allow a non-positive factor.");
         } catch (final IllegalArgumentException iae) {
             // expected
         }
 
-        try {
-            PoolUtils.erodingPool((KeyedObjectPool<Object, Object>) null, 1f, true);
+        try (final KeyedObjectPool<Object, Object> erodingPool = PoolUtils
+                .erodingPool((KeyedObjectPool<Object, Object>) null, 1f, true)) {
             fail("PoolUtils.erodingPool(KeyedObjectPool, float, boolean) must not allow a null pool.");
         } catch (final IllegalArgumentException iae) {
             // expected