[
https://issues.apache.org/jira/browse/POOL-338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16435697#comment-16435697
]
Michael C edited comment on POOL-338 at 4/12/18 2:39 PM:
---------------------------------------------------------
The issue steams from the {{instancesof}} check. Why not work on the {{else}}
block with the following, which gives the method a 3rd chance to succeed (diff
with commit {{d0f2514}} on April 5). Avoiding an incorrectly thrown exception
should not be considered as breaking backward compatibility:
{noformat}
diff BaseGenericObjectPool.java-d0f2514 BaseGenericObjectPool.java
623c623,628
< throw new IllegalArgumentException("Class " +
evictionPolicyClassName + " from class loader ["
---
> final ClassLoader epClassLoader =
>EvictionPolicy.class.getClassLoader();
> clazz = Class.forName(evictionPolicyClassName, true,
>epClassLoader);
> try {
> this.evictionPolicy =
>(EvictionPolicy<T>)clazz.newInstance();
> } catch (Exception e) {
> throw new IllegalArgumentException("Class " +
>evictionPolicyClassName + " from class loader ["
625c630,631
< + " from class loader [" +
EvictionPolicy.class.getClassLoader() + "]");
---
> + " from class loader [" + epClassLoader + "]");
> }{noformat}
I will comment on the 2.6 API separately.
was (Author: mcgitty):
The issue steams from the {{instancesof}} check. Why not work on the {{else}}
block with the following, which gives the method a 3rd chance to succeed (diff
with commit d0f2514 on April 5). Avoiding an incorrectly thrown exception
should not be considered as breaking backward compatibility:
{noformat}
diff BaseGenericObjectPool.java-d0f2514 BaseGenericObjectPool.java
623c623,628
< throw new IllegalArgumentException("Class " +
evictionPolicyClassName + " from class loader ["
---
> final ClassLoader epClassLoader =
>EvictionPolicy.class.getClassLoader();
> clazz = Class.forName(evictionPolicyClassName, true,
>epClassLoader);
> try {
> this.evictionPolicy =
>(EvictionPolicy<T>)clazz.newInstance();
> } catch (Exception e) {
> throw new IllegalArgumentException("Class " +
>evictionPolicyClassName + " from class loader ["
625c630,631
< + " from class loader [" +
EvictionPolicy.class.getClassLoader() + "]");
---
> + " from class loader [" + epClassLoader + "]");
> }{noformat}
I will comment on the 2.6 API separately.
> GenericObjectPool constructor throws an exception
> -------------------------------------------------
>
> Key: POOL-338
> URL: https://issues.apache.org/jira/browse/POOL-338
> Project: Commons Pool
> Issue Type: Bug
> Affects Versions: 2.4.2, 2.4.3, 2.5.0
> Environment: Java 8, Liferay DXP (an OSGi environment).
> Reporter: Michael C
> Priority: Major
> Attachments: commons-pool-gg.patch
>
>
> Version 2.4.3 GenericObjectPool constructor throws this exception:
> {{java.lang.IllegalArgumentException:
> [org.apache.commons.pool2.impl.DefaultEvictionPolicy] does not implement
> EvictionPolicy}}
> {{ at
> org.apache.commons.pool2.impl.BaseGenericObjectPool.setEvictionPolicyClassName(BaseGenericObjectPool.java:618)}}
> {{ at
> org.apache.commons.pool2.impl.GenericObjectPool.setConfig(GenericObjectPool.java:318)}}
> {{ at
> org.apache.commons.pool2.impl.GenericObjectPool.<init>(GenericObjectPool.java:115)}}
> {{ at
> org.apache.commons.pool2.impl.GenericObjectPool.<init>(GenericObjectPool.java:88)}}
>
> Version 2.5.0 throws the same exception. Version 2.4.2 or older's
> setEvictionPolicyClassName method fail silently for the same reason. This
> line in BaseGenericObjectPool evaluates to false for all versions:
> {{ if (policy instanceof EvictionPolicy<?>) {}}
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)