[jira] [Commented] (POOL-338) GenericObjectPool constructor throws an exception
[ https://issues.apache.org/jira/browse/POOL-338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16491136#comment-16491136 ] Michael C commented on POOL-338: Attached _commons-pool-mc.patch_ has these key changes compared to _commons-pool-gg.patch_: 1) {{BaseGenericObjectPool.setEvictionPolicyClassName(,)}} now uses {{epClass.isInstance(policy)}} instead of _instanceof_ to safe-guard casting, which proved to be more robust in multiple class loaders environments like OSGi. 2) {{epClass}} is created at method call time instead of a static variable, which also contributes to the success of {{epClass.isInstance(policy)}} in 1). 3) {{BaseObjectPoolConfig.evictionPolicy}} default to _null_ to provide backward compatibility to pre-2.6 versions. 4) {{setConfig()}} of both {{GenericKeyedObjectPool}} and {{GenericObjectPool}} uses the _evictionPolicy_ being null to preserve backward compatibility to pre-2.6 while giving precedence to 2.6 applications that explicitly set _evictionPolicy_. 5) Included other minor optimizations. > 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, commons-pool-mc.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.(GenericObjectPool.java:115)}} > {{ at > org.apache.commons.pool2.impl.GenericObjectPool.(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)
[jira] [Commented] (POOL-338) GenericObjectPool constructor throws an exception
[ https://issues.apache.org/jira/browse/POOL-338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16490639#comment-16490639 ] Gary Gregory commented on POOL-338: --- [~mcgitty]: Please provide a patch. > 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.(GenericObjectPool.java:115)}} > {{ at > org.apache.commons.pool2.impl.GenericObjectPool.(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)
[jira] [Commented] (POOL-338) GenericObjectPool constructor throws an exception
[ https://issues.apache.org/jira/browse/POOL-338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16490206#comment-16490206 ] Michael C commented on POOL-338: The patch you posted yesterday (5/23) still does not help me. I posted *two* separate comments on 5/12. Please revisit both again. Both offer backward compatible solutions in two different places. Note the source code diff in the 2nd 5/12 comment, plus the stack trace in the original bug description. I am using the _DefaultEvictionPolicy_, so this if statement in your diff still prevents me from using the _EvitionPolicy_ instantiated in my code, which will avoid the _instanceof_ check failure. {{ +// Maintain compatibility: +if (!BaseObjectPoolConfig.DEFAULT_EVICTION_POLICY_CLASS_NAME.equals(conf.getEvictionPolicyClassName())) { +// Use the class name if it is not the default +setEvictionPolicyClassName(conf.getEvictionPolicyClassName()); +} else { +// Otherwise, use the class +setEvictionPolicy(conf.getEvictionPolicy()); +} }} Again, both changes in my 5/12 comments are backward compatible, and suggestion 1) and 2) in the second comment should be reconsidered. > 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.(GenericObjectPool.java:115)}} > {{ at > org.apache.commons.pool2.impl.GenericObjectPool.(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)
[jira] [Commented] (POOL-338) GenericObjectPool constructor throws an exception
[ https://issues.apache.org/jira/browse/POOL-338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16487500#comment-16487500 ] Gary Gregory commented on POOL-338: --- I'm finally coming back around to this. I am updating the patch attached to this ticket to account for the patch in your previous comment as well as some other minor clean ups. May you please test again and report here? WRT to your question (1): The reference is [https://docs.oracle.com/javase/specs/jls/se8/html/jls-12.html#jls-12.4.2] WRT to your question (2): We could just remove {{BaseGenericObjectPool.setEvictionPolicyClass()}} as a YAGNI. > 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.(GenericObjectPool.java:115)}} > {{ at > org.apache.commons.pool2.impl.GenericObjectPool.(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)
[jira] [Commented] (POOL-338) GenericObjectPool constructor throws an exception
[ https://issues.apache.org/jira/browse/POOL-338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16436374#comment-16436374 ] Michael C commented on POOL-338: The patch doesn't work for me, because you missed the logic that favors {{evictionPolicy}} in {{GenericObjectPool.setConfig()}}. Even for {{GenericKeyedObjectPool.setConfig()}}, I believe favoring {{evictionPolicy}} should simply be: {noformat} @@ -238,7 +238,7 @@ * * @see GenericKeyedObjectPoolConfig */ -public void setConfig(final GenericKeyedObjectPoolConfig conf) { +public void setConfig(final GenericKeyedObjectPoolConfig conf) { setLifo(conf.getLifo()); setMaxIdlePerKey(conf.getMaxIdlePerKey()); setMaxTotalPerKey(conf.getMaxTotalPerKey()); @@ -256,7 +256,14 @@ conf.getSoftMinEvictableIdleTimeMillis()); setTimeBetweenEvictionRunsMillis( conf.getTimeBetweenEvictionRunsMillis()); -setEvictionPolicyClassName(conf.getEvictionPolicyClassName()); +final EvictionPolicy policy = conf.getEvictionPolicy(); +if (policy == null) { +// Use the class name +setEvictionPolicyClassName(conf.getEvictionPolicyClassName()); +} else { +// Otherwise, use the class +setEvictionPolicy(policy); +} setEvictorShutdownTimeoutMillis(conf.getEvictorShutdownTimeoutMillis()); } {noformat} That does not break compatibility, because {{BaseObjectPoolConfig.evictionPolicy}} is new in 2.6. Speaking of the 2.6 API, if anything, this bug tells us to avoid class loaders. Here are my assessments: 1) This static member may be _created_ by an unknown thread: {{+ static final Class EVICTION_POLICY_TYPE = EvictionPolicy.class;}} What is {{EVICTION_POLICY_TYPE.getClassLoader()}}? Is it from that unknown thread or the default class loader? 2) What is the value of {{BaseGenericObjectPool.setEvictionPolicyClass()}} when you already have the {{setEvictionPolicy()}} pair? It's one more potential problem down the road. Thanks > 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.(GenericObjectPool.java:115)}} > {{ at > org.apache.commons.pool2.impl.GenericObjectPool.(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)
[jira] [Commented] (POOL-338) GenericObjectPool constructor throws an exception
[ https://issues.apache.org/jira/browse/POOL-338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16435701#comment-16435701 ] Gary Gregory commented on POOL-338: --- I see what you mean here, but.. I would like you to try my patch as it introduces your idea that I do want to have, namely adding: {{ BaseObjectPoolConfig.setEvictionPolicy(EvictionPolicy evictionPolicy)}} {{ BaseObjectPoolConfig.getEvictionPolicy()}} Gary > 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.(GenericObjectPool.java:115)}} > {{ at > org.apache.commons.pool2.impl.GenericObjectPool.(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)
[jira] [Commented] (POOL-338) GenericObjectPool constructor throws an exception
[ https://issues.apache.org/jira/browse/POOL-338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16435697#comment-16435697 ] Michael C commented on POOL-338: 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)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.(GenericObjectPool.java:115)}} > {{ at > org.apache.commons.pool2.impl.GenericObjectPool.(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)
[jira] [Commented] (POOL-338) GenericObjectPool constructor throws an exception
[ https://issues.apache.org/jira/browse/POOL-338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16434096#comment-16434096 ] Gary Gregory commented on POOL-338: --- Ah, yes, the ctor... please try the attached patch [^commons-pool-gg.patch] Gary > 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.(GenericObjectPool.java:115)}} > {{ at > org.apache.commons.pool2.impl.GenericObjectPool.(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)
[jira] [Commented] (POOL-338) GenericObjectPool constructor throws an exception
[ https://issues.apache.org/jira/browse/POOL-338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16431549#comment-16431549 ] Michael C commented on POOL-338: Your diff won't help my use case of calling default constructor {{GenericObjectPool()}}. See the original stack trace. It is not the class loader that throws the exception. It is the {{if (policy instanceof EvictionPolicy)}} line evaluates to false for whatever odd reason. Nice addition to the 2.6 API, but consider adding: {{ BaseObjectPoolConfig.setEvictionPolicy(EvictionPolicy evictionPolicy)}} {{ BaseObjectPoolConfig.getEvictionPolicy()}} plus the logic that favors a not null {{evictionPolicy}} over {{evictionPolicyClassName}}. > 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 > > 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.(GenericObjectPool.java:115)}} > {{ at > org.apache.commons.pool2.impl.GenericObjectPool.(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)
[jira] [Commented] (POOL-338) GenericObjectPool constructor throws an exception
[ https://issues.apache.org/jira/browse/POOL-338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16431213#comment-16431213 ] Gary Gregory commented on POOL-338: --- Can you try the following on top of out git master: {noformat} diff --git a/pom.xml b/pom.xml index f913e97..cc8f799 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ 4.0.0 commons-pool2 - 2.5.1-SNAPSHOT + 2.6.0-SNAPSHOT Apache Commons Pool 2001 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 d9a4df7..a19f41a 100644 --- a/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java +++ b/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java @@ -589,30 +589,44 @@ } /** - * Sets the name of the {@link EvictionPolicy} implementation that is - * used by this pool. The Pool will attempt to load the class using the - * thread context class loader. If that fails, the Pool will attempt to load - * the class using the class loader that loaded this class. + * Sets the eviction policy for this pool. + * + * @param evictionPolicy + *the eviction policy for this pool. + * @since 2.6.0 + */ +public void setEvictionPolicy(EvictionPolicy evictionPolicy) { +this.evictionPolicy = evictionPolicy; +} + + +/** + * Sets the name of the {@link EvictionPolicy} implementation that is used by this pool. The Pool will attempt to + * load the class using the given class loader. If that fails, use the class loader for the {@link EvictionPolicy} + * interface. * - * @param evictionPolicyClassName the fully qualified class name of the - * new eviction policy + * @param evictionPolicyClassName + *the fully qualified class name of the new eviction policy + * @param classLoader + *the class loader to load the given {@code evictionPolicyClassName}. * * @see #getEvictionPolicyClassName() + * @since 2.6.0 If loading the class using the given class loader fails, use the class loader for the + *{@link EvictionPolicy} interface. */ -public final void setEvictionPolicyClassName(final String evictionPolicyClassName) { +public final void setEvictionPolicyClassName(final String evictionPolicyClassName, final ClassLoader classLoader) { final String EVICTION_POLICY_TYPE_NAME = EvictionPolicy.class.getName(); final String exMessage = "Unable to create " + EVICTION_POLICY_TYPE_NAME + " instance of type " + evictionPolicyClassName; try { Class clazz; -final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); String epcnClassLoaderDesc; try { -epcnClassLoaderDesc = "Thread context class loader: " + classLoader; +epcnClassLoaderDesc = "Class loader: " + classLoader; clazz = Class.forName(evictionPolicyClassName, true, classLoader); } catch (final ClassNotFoundException e) { -epcnClassLoaderDesc = "Default class loader"; -clazz = Class.forName(evictionPolicyClassName); +epcnClassLoaderDesc = EVICTION_POLICY_TYPE_NAME + " class loader"; +clazz = Class.forName(evictionPolicyClassName, true, EvictionPolicy.class.getClassLoader()); } final Object policy = clazz.getConstructor().newInstance(); if (policy instanceof EvictionPolicy) { @@ -631,6 +645,22 @@ } /** + * Sets the name of the {@link EvictionPolicy} implementation that is used by this pool. The Pool will attempt to + * load the class using the thread context class loader. If that fails, the use the class loader for the + * {@link EvictionPolicy} interface. + * + * @param evictionPolicyClassName + *the fully qualified class name of the new eviction policy + * + * @see #getEvictionPolicyClassName() + * @since 2.6.0 If loading the class using the thread context class loader fails, use the class loader for the + *{@link EvictionPolicy} interface. + */ +public final void setEvictionPolicyClassName(final String evictionPolicyClassName) { +setEvictionPolicyClassName(evictionPolicyClassName, Thread.currentThread().getContextClassLoader()); +} + +/** * Gets the timeout that will be used when waiting for the Evictor to * shutdown if this pool is closed and it is the only pool still using the * the value for the Evictor. @@ -1317,4 +1347,5 @@ builder.append(swallowedExceptionListener); } + } diff --git a/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
[jira] [Commented] (POOL-338) GenericObjectPool constructor throws an exception
[ https://issues.apache.org/jira/browse/POOL-338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16430654#comment-16430654 ] Michael C commented on POOL-338: I also question using {{Class.forName}} to create {{EvictionPolicy}}. All these class loader trouble actually makes the API harder to use compare to just a {{setEvictionPolicy(EvictionPolicy)}} method. For example, you cannot have a class that extends {{GenericObjectPoolConfig}} also implements {{EvictionPolicy}}, because the former must be instantiated first with all the customization needed. > 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 > > 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.(GenericObjectPool.java:115)}} > {{ at > org.apache.commons.pool2.impl.GenericObjectPool.(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)
[jira] [Commented] (POOL-338) GenericObjectPool constructor throws an exception
[ https://issues.apache.org/jira/browse/POOL-338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16430519#comment-16430519 ] Michael C commented on POOL-338: Nice touch. Here is the new log that shows two class loaders: java.lang.IllegalArgumentException: Class org.apache.commons.pool2.impl.DefaultEvictionPolicy from class loader [Thread context class loader: org.eclipse.osgi.internal.framework.ContextFinder@383d49e2] does not implement org.apache.commons.pool2.impl.EvictionPolicy from class loader [org.eclipse.osgi.internal.loader.EquinoxClassLoader@d099faf[com.rivetlogic.liferay.store.box:1.0.0(id=42)]] Since the error came from line 618 _{{if (policy instanceof EvictionPolicy)}}_, it makes sense to me to use the same class loader of EvictionPolicy to load _{{policy}}_ in line 608: {{ final ClassLoader classLoader = EvictionPolicy.class.getClassLoader();}} It works in my OSGi environment. > 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 > > 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.(GenericObjectPool.java:115)}} > {{ at > org.apache.commons.pool2.impl.GenericObjectPool.(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)
[jira] [Commented] (POOL-338) GenericObjectPool constructor throws an exception
[ https://issues.apache.org/jira/browse/POOL-338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16429206#comment-16429206 ] Gary Gregory commented on POOL-338: --- Can you please try again with 2.5.1-SNAPSHOT? I added information about class loaders to exception message when the instance created does not implement the expected interface {{EvictionPolicy}}. > 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 > > 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.(GenericObjectPool.java:115)}} > {{ at > org.apache.commons.pool2.impl.GenericObjectPool.(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)
[jira] [Commented] (POOL-338) GenericObjectPool constructor throws an exception
[ https://issues.apache.org/jira/browse/POOL-338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16429162#comment-16429162 ] Gary Gregory commented on POOL-338: --- When you are at https://issues.apache.org/jira/browse/POOL-338?focusedCommentId=16427494=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-16427494 it would be interesting to see the class loader for each object. > 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 > > 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.(GenericObjectPool.java:115)}} > {{ at > org.apache.commons.pool2.impl.GenericObjectPool.(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)
[jira] [Commented] (POOL-338) GenericObjectPool constructor throws an exception
[ https://issues.apache.org/jira/browse/POOL-338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16427516#comment-16427516 ] Gary Gregory commented on POOL-338: --- You can also use the 2.5.1-SNAPSHOT version or our sources directly to get the latest code. > 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 > > 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.(GenericObjectPool.java:115)}} > {{ at > org.apache.commons.pool2.impl.GenericObjectPool.(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)
[jira] [Commented] (POOL-338) GenericObjectPool constructor throws an exception
[ https://issues.apache.org/jira/browse/POOL-338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16427494#comment-16427494 ] Michael C commented on POOL-338: Eclipse debugger shows while at that if statement: {{clazz: class org.apache.commons.pool2.impl.DefaultEvictionPolicy}} {{policy: org.apache.commons.pool2.impl.DefaultEvictionPolicy@4591dc8f}} {{evictionPolicyClassName: "org.apache.commons.pool2.impl.DefaultEvictionPolicy"}} Looks good to me symbolically. May be I should write a unit test ... > 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 > > 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.(GenericObjectPool.java:115)}} > {{ at > org.apache.commons.pool2.impl.GenericObjectPool.(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)
[jira] [Commented] (POOL-338) GenericObjectPool constructor throws an exception
[ https://issues.apache.org/jira/browse/POOL-338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16427368#comment-16427368 ] Gary Gregory commented on POOL-338: --- I've improved the exception messages in {{org.apache.commons.pool2.impl.BaseGenericObjectPool.setEvictionPolicyClassName(String)}} to include the FQN of the {{EvictionPolicy}} interface: {{apache.commons.pool2.impl.EvictionPolicy}}. This won't fix anything for you but it will make it clear what the excepted interface the given class has to implement. The next improvement would be to include in the message some class loader information... suggestions welcome. > 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 > > 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.(GenericObjectPool.java:115)}} > {{ at > org.apache.commons.pool2.impl.GenericObjectPool.(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)
[jira] [Commented] (POOL-338) GenericObjectPool constructor throws an exception
[ https://issues.apache.org/jira/browse/POOL-338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16427303#comment-16427303 ] Gary Gregory commented on POOL-338: --- You can see from the source code that {{org.apache.commons.pool2.impl.DefaultEvictionPolicy}} does implement {{org.apache.commons.pool2.impl.EvictionPolicy}}, so this should be a class loader issue... > 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 > > 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.(GenericObjectPool.java:115)}} > {{ at > org.apache.commons.pool2.impl.GenericObjectPool.(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)
[jira] [Commented] (POOL-338) GenericObjectPool constructor throws an exception
[ https://issues.apache.org/jira/browse/POOL-338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16427292#comment-16427292 ] Michael C commented on POOL-338: It is possible. This exception is observed from Liferay DXP, an OSGi environment. > 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 >Reporter: Michael C >Priority: Major > > 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.(GenericObjectPool.java:115)}} > {{ at > org.apache.commons.pool2.impl.GenericObjectPool.(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)
[jira] [Commented] (POOL-338) GenericObjectPool constructor throws an exception
[ https://issues.apache.org/jira/browse/POOL-338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16426123#comment-16426123 ] Gary Gregory commented on POOL-338: --- I wonder if this is a class loader issue. Can you describe your environment? > 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 >Reporter: Michael C >Priority: Major > > 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.(GenericObjectPool.java:115)}} > {{ at > org.apache.commons.pool2.impl.GenericObjectPool.(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)