[ 
https://issues.apache.org/jira/browse/KAFKA-3218?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15147425#comment-15147425
 ] 

Robert Lowe edited comment on KAFKA-3218 at 2/15/16 2:45 PM:
-------------------------------------------------------------

Suggested workaround throws error on bundle:start
{code}
org.apache.karaf.shell.support.MultiException: Error executing command on 
bundles:
        Error starting bundle66: Activator start error in bundle 
com.openet.testcase.ContextClassLoaderBug [66].
        at 
org.apache.karaf.shell.support.MultiException.throwIf(MultiException.java:61)
        at 
org.apache.karaf.bundle.command.BundlesCommand.doExecute(BundlesCommand.java:69)
        at 
org.apache.karaf.bundle.command.BundlesCommand.execute(BundlesCommand.java:54)
        at 
org.apache.karaf.shell.impl.action.command.ActionCommand.execute(ActionCommand.java:83)
        at 
org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:67)
        at 
org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:87)
        at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:480)
        at 
org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:406)
        at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)
        at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:182)
        at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:119)
        at 
org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:94)
        at 
org.apache.karaf.shell.impl.console.ConsoleSessionImpl.run(ConsoleSessionImpl.java:270)
        at java.lang.Thread.run(Thread.java:745)
        Suppressed: java.lang.Exception: Error starting bundle66: Activator 
start error in bundle com.openet.testcase.ContextClassLoaderBug [66].
                at 
org.apache.karaf.bundle.command.BundlesCommand.doExecute(BundlesCommand.java:66)
                ... 12 more
        Caused by: org.osgi.framework.BundleException: Activator start error in 
bundle com.openet.testcase.ContextClassLoaderBug [66].
                at 
org.apache.felix.framework.Felix.activateBundle(Felix.java:2270)
                at org.apache.felix.framework.Felix.startBundle(Felix.java:2138)
                at 
org.apache.felix.framework.BundleImpl.start(BundleImpl.java:977)
                at 
org.apache.karaf.bundle.command.Start.executeOnBundle(Start.java:38)
                at 
org.apache.karaf.bundle.command.BundlesCommand.doExecute(BundlesCommand.java:64)
                ... 12 more
        Caused by: java.lang.NoClassDefFoundError: Could not initialize class 
org.apache.kafka.clients.producer.ProducerConfig
                at 
org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:156)
                at com.openet.testcase.Activator.start(Activator.java:18)
                at 
org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:697)
                at 
org.apache.felix.framework.Felix.activateBundle(Felix.java:2220)
                ... 16 more

{code}


was (Author: lowerobert):
Suggested fix throws error on bundle:start
{code}
org.apache.karaf.shell.support.MultiException: Error executing command on 
bundles:
        Error starting bundle66: Activator start error in bundle 
com.openet.testcase.ContextClassLoaderBug [66].
        at 
org.apache.karaf.shell.support.MultiException.throwIf(MultiException.java:61)
        at 
org.apache.karaf.bundle.command.BundlesCommand.doExecute(BundlesCommand.java:69)
        at 
org.apache.karaf.bundle.command.BundlesCommand.execute(BundlesCommand.java:54)
        at 
org.apache.karaf.shell.impl.action.command.ActionCommand.execute(ActionCommand.java:83)
        at 
org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:67)
        at 
org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:87)
        at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:480)
        at 
org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:406)
        at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)
        at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:182)
        at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:119)
        at 
org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:94)
        at 
org.apache.karaf.shell.impl.console.ConsoleSessionImpl.run(ConsoleSessionImpl.java:270)
        at java.lang.Thread.run(Thread.java:745)
        Suppressed: java.lang.Exception: Error starting bundle66: Activator 
start error in bundle com.openet.testcase.ContextClassLoaderBug [66].
                at 
org.apache.karaf.bundle.command.BundlesCommand.doExecute(BundlesCommand.java:66)
                ... 12 more
        Caused by: org.osgi.framework.BundleException: Activator start error in 
bundle com.openet.testcase.ContextClassLoaderBug [66].
                at 
org.apache.felix.framework.Felix.activateBundle(Felix.java:2270)
                at org.apache.felix.framework.Felix.startBundle(Felix.java:2138)
                at 
org.apache.felix.framework.BundleImpl.start(BundleImpl.java:977)
                at 
org.apache.karaf.bundle.command.Start.executeOnBundle(Start.java:38)
                at 
org.apache.karaf.bundle.command.BundlesCommand.doExecute(BundlesCommand.java:64)
                ... 12 more
        Caused by: java.lang.NoClassDefFoundError: Could not initialize class 
org.apache.kafka.clients.producer.ProducerConfig
                at 
org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:156)
                at com.openet.testcase.Activator.start(Activator.java:18)
                at 
org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:697)
                at 
org.apache.felix.framework.Felix.activateBundle(Felix.java:2220)
                ... 16 more

{code}

> Kafka-0.9.0.0 does not work as OSGi module
> ------------------------------------------
>
>                 Key: KAFKA-3218
>                 URL: https://issues.apache.org/jira/browse/KAFKA-3218
>             Project: Kafka
>          Issue Type: Bug
>          Components: clients
>    Affects Versions: 0.9.0.0
>         Environment: Apache Felix OSGi container
> jdk_1.8.0_60
>            Reporter: Joe O'Connor
>            Assignee: Rajini Sivaram
>         Attachments: ContextClassLoaderBug.tar.gz
>
>
> KAFKA-2295 changed all Class.forName() calls to use 
> currentThread().getContextClassLoader() instead of the default "classloader 
> that loaded the current class". 
> OSGi loads each module's classes using a separate classloader so this is now 
> broken.
> Steps to reproduce: 
> # install the kafka-clients servicemix OSGi module 0.9.0.0_1
> # attempt to initialize the Kafka producer client from Java code 
> Expected results: 
> - call to "new KafkaProducer()" succeeds
> Actual results: 
> - "new KafkaProducer()" throws ConfigException:
> {quote}        Suppressed: java.lang.Exception: Error starting bundle54: 
> Activator start error in bundle com.openet.testcase.ContextClassLoaderBug 
> [54].
>                 at 
> org.apache.karaf.bundle.command.BundlesCommand.doExecute(BundlesCommand.java:66)
>                 ... 12 more
>         Caused by: org.osgi.framework.BundleException: Activator start error 
> in bundle com.openet.testcase.ContextClassLoaderBug [54].
>                 at 
> org.apache.felix.framework.Felix.activateBundle(Felix.java:2276)
>                 at 
> org.apache.felix.framework.Felix.startBundle(Felix.java:2144)
>                 at 
> org.apache.felix.framework.BundleImpl.start(BundleImpl.java:998)
>                 at 
> org.apache.karaf.bundle.command.Start.executeOnBundle(Start.java:38)
>                 at 
> org.apache.karaf.bundle.command.BundlesCommand.doExecute(BundlesCommand.java:64)
>                 ... 12 more
>         Caused by: java.lang.ExceptionInInitializerError
>                 at 
> org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:156)
>                 at com.openet.testcase.Activator.start(Activator.java:16)
>                 at 
> org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:697)
>                 at 
> org.apache.felix.framework.Felix.activateBundle(Felix.java:2226)
>                 ... 16 more
>         *Caused by: org.apache.kafka.common.config.ConfigException: Invalid 
> value org.apache.kafka.clients.producer.internals.DefaultPartitioner for 
> configuration partitioner.class: Class* 
> *org.apache.kafka.clients.producer.internals.DefaultPartitioner could not be 
> found.*
>                 at 
> org.apache.kafka.common.config.ConfigDef.parseType(ConfigDef.java:255)
>                 at 
> org.apache.kafka.common.config.ConfigDef.define(ConfigDef.java:78)
>                 at 
> org.apache.kafka.common.config.ConfigDef.define(ConfigDef.java:94)
>                 at 
> org.apache.kafka.clients.producer.ProducerConfig.<clinit>(ProducerConfig.java:206)
> {quote}
> Workaround is to call "currentThread().setContextClassLoader(null)" before 
> initializing the kafka producer.
> Possible fix is to catch ClassNotFoundException at ConfigDef.java:247 and 
> retry the Class.forName() call with the default classloader. However with 
> this fix there is still a problem at AbstractConfig.java:206,  where the 
> newInstance() call succeeds but "instanceof" is false because the classes 
> were loaded by different classloaders.
> Testcase attached, see README.txt for instructions.
> See also SM-2743



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to