You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2013/10/14 15:37:14 UTC

svn commit: r1531891 - in /commons/proper/pool/trunk: ./ src/test/java/org/apache/commons/pool2/ src/test/java/org/apache/commons/pool2/performance/ src/test/java/org/apache/commons/pool2/proxy/

Author: markt
Date: Mon Oct 14 13:37:14 2013
New Revision: 1531891

URL: http://svn.apache.org/r1531891
Log:
Fix some FindBugs warnings

Modified:
    commons/proper/pool/trunk/findbugs-exclude-filter.xml
    commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/TestPoolUtils.java
    commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/WaiterFactory.java
    commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/performance/SleepingObjectFactory.java
    commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/proxy/BaseTestProxiedObjectPool.java

Modified: commons/proper/pool/trunk/findbugs-exclude-filter.xml
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/findbugs-exclude-filter.xml?rev=1531891&r1=1531890&r2=1531891&view=diff
==============================================================================
--- commons/proper/pool/trunk/findbugs-exclude-filter.xml (original)
+++ commons/proper/pool/trunk/findbugs-exclude-filter.xml Mon Oct 14 13:37:14 2013
@@ -81,6 +81,7 @@
     <Or>
       <Class name="org.apache.commons.pool2.MethodCallPoolableObjectFactory" />
       <Class name="org.apache.commons.pool2.TestKeyedObjectPool$FailingKeyedPooledObjectFactory" />
+      <Class name="org.apache.commons.pool2.performance.SleepingObjectFactory" />
     </Or>
     <Method name="makeObject" />
     <Bug pattern="DM_NUMBER_CTOR" />
@@ -93,4 +94,10 @@
     </Or>
     <Bug pattern="DM_NUMBER_CTOR" />
   </Match>
+  <Match>
+    <!-- Use of no-arg constructor is intentional -->
+    <Class name="org.apache.commons.pool2.TestPoolUtils" />
+    <Method name="testJavaBeanInstantiation" />
+    <Bug pattern="ISC_INSTANTIATE_STATIC_CLASS" />
+  </Match>
 </FindBugsFilter>

Modified: commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/TestPoolUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/TestPoolUtils.java?rev=1531891&r1=1531890&r2=1531891&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/TestPoolUtils.java (original)
+++ commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/TestPoolUtils.java Mon Oct 14 13:37:14 2013
@@ -457,7 +457,7 @@ public class TestPoolUtils {
                 Object o = super.invoke(proxy, method, args);
                 if (o instanceof Integer) {
                     // so getNumActive/getNumIdle are not zero.
-                    o = new Integer(1);
+                    o = Integer.valueOf(1);
                 }
                 return o;
             }
@@ -551,7 +551,7 @@ public class TestPoolUtils {
                 Object o = super.invoke(proxy, method, args);
                 if (o instanceof Integer) {
                     // so getNumActive/getNumIdle are not zero.
-                    o = new Integer(1);
+                    o = Integer.valueOf(1);
                 }
                 return o;
             }
@@ -633,7 +633,7 @@ public class TestPoolUtils {
                 Object o = super.invoke(proxy, method, args);
                 if (o instanceof Integer) {
                     // so getNumActive/getNumIdle are not zero.
-                    o = new Integer(1);
+                    o = Integer.valueOf(1);
                 }
                 return o;
             }
@@ -780,9 +780,9 @@ public class TestPoolUtils {
             if (boolean.class.equals(method.getReturnType())) {
                 return Boolean.FALSE;
             } else if (int.class.equals(method.getReturnType())) {
-                return new Integer(0);
+                return Integer.valueOf(0);
             } else if (long.class.equals(method.getReturnType())) {
-                return new Long(0);
+                return Long.valueOf(0);
             } else if (Object.class.equals(method.getReturnType())) {
                 return new Object();
             } else if (PooledObject.class.equals(method.getReturnType())) {

Modified: commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/WaiterFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/WaiterFactory.java?rev=1531891&r1=1531890&r2=1531891&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/WaiterFactory.java (original)
+++ commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/WaiterFactory.java Mon Oct 14 13:37:14 2013
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -33,37 +33,37 @@ import org.apache.commons.pool2.impl.Def
  */
 public class WaiterFactory<K> implements PooledObjectFactory<Waiter>,
 KeyedPooledObjectFactory<K,Waiter> {
-    
+
     /** Latency of activateObject */
     private final long activateLatency;
-    
+
     /** Latency of destroyObject */
     private final long destroyLatency;
-    
+
     /** Latency of makeObject */
     private final long makeLatency;
-    
+
     /** Latency of passivateObject */
     private final long passivateLatency;
-    
+
     /** Latency of validateObject */
     private final long validateLatency;
-    
+
     /** Latency of doWait for Waiter instances created by this factory */
     private final long waiterLatency;
-    
+
     /** Probability that passivation will invalidate Waiter instances */
     private final double passivateInvalidationProbability;
-    
+
     /** Count of (makes - destroys) since last reset */
     private long activeCount = 0;
-    
+
     /** Count of (makes - destroys) per key since last reset */
     private Map<K,Integer> activeCounts = new HashMap<K,Integer>();
-    
+
     /** Maximum of (makes - destroys) - if exceeded IllegalStateException */
     private final long maxActive;  // GKOP 1.x calls this maxTotal
-    
+
     /** Maximum of (makes - destroys) per key */
     private final long maxActivePerKey;  // GKOP 1.x calls this maxActive
 
@@ -81,14 +81,14 @@ KeyedPooledObjectFactory<K,Waiter> {
         this.maxActivePerKey = maxActivePerKey;
         this.passivateInvalidationProbability = passivateInvalidationProbability;
     }
-    
+
     public WaiterFactory(long activateLatency, long destroyLatency,
             long makeLatency, long passivateLatency, long validateLatency,
             long waiterLatency) {
         this(activateLatency, destroyLatency, makeLatency, passivateLatency,
                 validateLatency, waiterLatency, Long.MAX_VALUE, Long.MAX_VALUE, 0);
     }
-    
+
     public WaiterFactory(long activateLatency, long destroyLatency,
             long makeLatency, long passivateLatency, long validateLatency,
             long waiterLatency,long maxActive) {
@@ -107,7 +107,7 @@ KeyedPooledObjectFactory<K,Waiter> {
         doWait(destroyLatency);
         obj.getObject().setValid(false);
         obj.getObject().setActive(false);
-        // Decrement *after* destroy 
+        // Decrement *after* destroy
         synchronized (this) {
             activeCount--;
         }
@@ -142,7 +142,7 @@ KeyedPooledObjectFactory<K,Waiter> {
         doWait(validateLatency);
         return obj.getObject().isValid();
     }
-    
+
     protected void doWait(long latency) {
         try {
             Thread.sleep(latency);
@@ -150,7 +150,7 @@ KeyedPooledObjectFactory<K,Waiter> {
             // ignore
         }
     }
-    
+
     public synchronized void reset() {
         activeCount = 0;
         if (activeCounts.isEmpty()) {
@@ -159,7 +159,7 @@ KeyedPooledObjectFactory<K,Waiter> {
         Iterator<K> it = activeCounts.keySet().iterator();
         while (it.hasNext()) {
             K key = it.next();
-            activeCounts.put(key, new Integer (0));
+            activeCounts.put(key, Integer.valueOf(0));
         }
     }
 
@@ -171,7 +171,7 @@ KeyedPooledObjectFactory<K,Waiter> {
     }
 
     // KeyedPoolableObjectFactory methods
-    
+
     @Override
     public void activateObject(K key, PooledObject<Waiter> obj) throws Exception {
         activateObject(obj);
@@ -182,7 +182,7 @@ KeyedPooledObjectFactory<K,Waiter> {
         destroyObject(obj);
         synchronized (this) {
             Integer count = activeCounts.get(key);
-            activeCounts.put(key, new Integer(count.intValue() - 1));
+            activeCounts.put(key, Integer.valueOf(count.intValue() - 1));
         }
     }
 
@@ -191,16 +191,16 @@ KeyedPooledObjectFactory<K,Waiter> {
         synchronized (this) {
             Integer count = activeCounts.get(key);
             if (count == null) {
-                count = new Integer(1);
+                count = Integer.valueOf(1);
                 activeCounts.put(key, count);
             } else {
                 if (count.intValue() >= maxActivePerKey) {
                     throw new IllegalStateException("Too many active " +
-                    "instances for key = " + key + ": " + count.intValue() + 
-                    " in circulation " + "with maxActivePerKey = " + 
+                    "instances for key = " + key + ": " + count.intValue() +
+                    " in circulation " + "with maxActivePerKey = " +
                     maxActivePerKey);
                 } else {
-                    activeCounts.put(key, new Integer(count.intValue() + 1));
+                    activeCounts.put(key, Integer.valueOf(count.intValue() + 1));
                 }
             }
         }

Modified: commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/performance/SleepingObjectFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/performance/SleepingObjectFactory.java?rev=1531891&r1=1531890&r2=1531891&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/performance/SleepingObjectFactory.java (original)
+++ commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/performance/SleepingObjectFactory.java Mon Oct 14 13:37:14 2013
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,8 +23,8 @@ import org.apache.commons.pool2.impl.Def
 
 /**
  * Sleepy ObjectFactory (everything takes a while longer)
- * 
- * @version $Revision$ 
+ *
+ * @version $Revision$
  */
 public class SleepingObjectFactory implements PooledObjectFactory<Integer> {
 
@@ -33,6 +33,8 @@ public class SleepingObjectFactory imple
 
     @Override
     public PooledObject<Integer> makeObject() throws Exception {
+        // Deliberate choice to create a new object in case future unit tests
+        // check for a specific object.
         Integer obj = new Integer(counter++);
         debug("makeObject", obj);
         sleep(500);
@@ -63,14 +65,14 @@ public class SleepingObjectFactory imple
         debug("passivateObject", obj);
         sleep(10);
     }
-    
+
     private void debug(String method, Object obj) {
         if (debug) {
             String thread = "thread" + Thread.currentThread().getName();
             System.out.println(thread + ": " + method + " " + obj);
         }
     }
-    
+
     private void sleep(long millis) {
         try {
             Thread.sleep(millis);

Modified: commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/proxy/BaseTestProxiedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/proxy/BaseTestProxiedObjectPool.java?rev=1531891&r1=1531890&r2=1531891&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/proxy/BaseTestProxiedObjectPool.java (original)
+++ commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/proxy/BaseTestProxiedObjectPool.java Mon Oct 14 13:37:14 2013
@@ -38,8 +38,8 @@ public abstract class BaseTestProxiedObj
     private static final String DATA1 = "data1";
     private static final int ABANDONED_TIMEOUT_SECS = 3;
 
-    private ObjectPool<TestObject> pool;
-    private StringWriter log;
+    private ObjectPool<TestObject> pool = null;
+    private StringWriter log = null;
 
     @Before
     public void setup() {