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 2017/03/12 19:48:09 UTC
[39/50] [abbrv] commons-pool git commit: Check class used for
evictionPolicyClassName implements EvictionPolicy
Check class used for evictionPolicyClassName implements EvictionPolicy
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/pool/trunk@1767714 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/commons-pool/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-pool/commit/108f44a4
Tree: http://git-wip-us.apache.org/repos/asf/commons-pool/tree/108f44a4
Diff: http://git-wip-us.apache.org/repos/asf/commons-pool/diff/108f44a4
Branch: refs/heads/master
Commit: 108f44a45f1e95dd6bbb6db3934fc0a2cc7019ab
Parents: dcf4d6d
Author: Mark Thomas <ma...@apache.org>
Authored: Wed Nov 2 15:53:08 2016 +0000
Committer: Mark Thomas <ma...@apache.org>
Committed: Wed Nov 2 15:53:08 2016 +0000
----------------------------------------------------------------------
src/changes/changes.xml | 4 +++
.../pool2/impl/BaseGenericObjectPool.java | 3 ++
.../pool2/impl/TestGenericObjectPool.java | 38 ++++++++++++--------
3 files changed, 30 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-pool/blob/108f44a4/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 65ca2b8..5cca806 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -67,6 +67,10 @@ The <action> type attribute can be add,update,fix,remove.
maxTotal threads try to borrow objects with different keys at the same
time and the factory destroys objects on return.
</action>
+ <action dev="markt" type="fix">
+ Ensure that any class name used for evictionPolicyClassName represents a
+ class that implements EvictionPolicy.
+ </action>
</release>
<release version="2.4.2" date="2015-08-01" description=
"This is a patch release, including bug fixes only.">
http://git-wip-us.apache.org/repos/asf/commons-pool/blob/108f44a4/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java b/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java
index 8d5efbd..8afa8f1 100644
--- a/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java
+++ b/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java
@@ -613,6 +613,9 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject {
final
EvictionPolicy<T> evicPolicy = (EvictionPolicy<T>) policy;
this.evictionPolicy = evicPolicy;
+ } else {
+ throw new IllegalArgumentException("[" + evictionPolicyClassName +
+ "] does not implement EvictionPolicy");
}
} catch (final ClassNotFoundException e) {
throw new IllegalArgumentException(
http://git-wip-us.apache.org/repos/asf/commons-pool/blob/108f44a4/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java b/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
index 75b9438..c9014ac 100644
--- a/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
+++ b/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
@@ -1080,6 +1080,14 @@ public class TestGenericObjectPool extends TestBaseObjectPool {
// expected
}
+ try {
+ pool.setEvictionPolicyClassName(java.lang.String.class.getName());
+ fail("setEvictionPolicyClassName must throw an error if a class that does not "
+ + "implement EvictionPolicy is specified.");
+ } catch (final IllegalArgumentException e) {
+ // expected
+ }
+
pool.setEvictionPolicyClassName(TestEvictionPolicy.class.getName());
assertEquals(TestEvictionPolicy.class.getName(), pool.getEvictionPolicyClassName());
@@ -1704,49 +1712,49 @@ public class TestGenericObjectPool extends TestBaseObjectPool {
public SimpleFactory() {
this(true);
}
-
+
public SimpleFactory(final boolean valid) {
this(valid,valid);
}
-
+
public SimpleFactory(final boolean evalid, final boolean ovalid) {
evenValid = evalid;
oddValid = ovalid;
}
-
+
public synchronized void setValid(final boolean valid) {
setEvenValid(valid);
setOddValid(valid);
}
-
+
public synchronized void setEvenValid(final boolean valid) {
evenValid = valid;
}
-
+
public synchronized void setOddValid(final boolean valid) {
oddValid = valid;
}
-
+
public synchronized void setThrowExceptionOnPassivate(final boolean bool) {
exceptionOnPassivate = bool;
}
-
+
public synchronized void setMaxTotal(final int maxTotal) {
this.maxTotal = maxTotal;
}
-
+
public synchronized void setDestroyLatency(final long destroyLatency) {
this.destroyLatency = destroyLatency;
}
-
+
public synchronized void setMakeLatency(final long makeLatency) {
this.makeLatency = makeLatency;
}
-
+
public synchronized void setValidateLatency(final long validateLatency) {
this.validateLatency = validateLatency;
}
-
+
@Override
public PooledObject<String> makeObject() {
final long waitLatency;
@@ -1767,7 +1775,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool {
}
return new DefaultPooledObject<String>(String.valueOf(counter));
}
-
+
@Override
public void destroyObject(final PooledObject<String> obj) throws Exception {
final long waitLatency;
@@ -1786,7 +1794,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool {
throw new Exception();
}
}
-
+
@Override
public boolean validateObject(final PooledObject<String> obj) {
final boolean validate;
@@ -1809,7 +1817,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool {
}
return true;
}
-
+
@Override
public void activateObject(final PooledObject<String> obj) throws Exception {
final boolean hurl;
@@ -1828,7 +1836,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool {
}
}
}
-
+
@Override
public void passivateObject(final PooledObject<String> obj) throws Exception {
final boolean hurl;