OSGi Netty / Vertx error when running from bndtools/eclipse

327 views Asked by At

I am trying to run vertx under OSGi (bndtools/eclipse) and getting this error message from the underlying Netty.

I am using vertx 3.3.3 using bndtools in standalone mode (maven) so all dependencies are imported using maven and not the standard bndtools (cnf) template.

17:00:05.935 [main] DEBUG io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework 17:00:05.938 [main] DEBUG io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple 17:00:05.939 [main] DEBUG io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.maxRecords: 4 17:00:05.971 [main] DEBUG io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 17:00:05.993 [main] DEBUG io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available 17:00:05.994 [main] DEBUG io.netty.util.internal.PlatformDependent - Platform: Windows 17:00:05.994 [main] DEBUG io.netty.util.internal.PlatformDependent - Java version: 8 17:00:05.994 [main] DEBUG io.netty.util.internal.PlatformDependent - -Dio.netty.noUnsafe: false 17:00:05.995 [main] DEBUG io.netty.util.internal.PlatformDependent - maxDirectMemory: 3776970752 bytes (maybe) ! Failed to start bundle mybundle.vertx-2.0.0, exception activator error Could not initialize class io.netty.util.internal.PlatformDependent0 from: io.netty.util.internal.PlatformDependent:<clinit>#101

In my bundle activator I try to create a new vertx using the static method :

```

@Override
public void start(BundleContext bc) throws Exception {
   Vertx vertx = Vertx.vertx();

```

In the standard bndtools template (none maven) this works fine. I am not sure I can mix the two modes in the same project and I prefer to stick to the maven format.

EDIT

I created this sample project cloned from the main Paremus project hello example to demonstrate the issue I am having with Vert.x & OSGi https://github.com/gadieichhorn/hello-examples/tree/hello-1.13.x

EDIT 2

I moved the Vertx initialization to a service (not bundle activator) and now I am getting a more detailed error.

ERROR: helloworld-web (6): [com.example.hello.web.VertxRegistrationService(0)] The start method has thrown an exception
java.lang.NoClassDefFoundError: Could not initialize class io.netty.util.internal.PlatformDependent0
    at io.netty.util.internal.PlatformDependent.<clinit>(PlatformDependent.java:101)
    at io.netty.util.ConstantPool.<init>(ConstantPool.java:32)
    at io.netty.util.Signal$1.<init>(Signal.java:27)
    at io.netty.util.Signal.<clinit>(Signal.java:27)
    at io.netty.util.concurrent.DefaultPromise.<clinit>(DefaultPromise.java:42)
    at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:36)
    at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:58)
    at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:47)
    at io.netty.channel.MultithreadEventLoopGroup.<init>(MultithreadEventLoopGroup.java:58)
    at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:77)
    at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:72)
    at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:59)
    at io.vertx.core.impl.VertxImpl.<init>(VertxImpl.java:133)
    at io.vertx.core.impl.VertxImpl.<init>(VertxImpl.java:122)
    at io.vertx.core.impl.VertxImpl.<init>(VertxImpl.java:118)
    at io.vertx.core.impl.VertxFactoryImpl.vertx(VertxFactoryImpl.java:34)
    at io.vertx.core.Vertx.vertx(Vertx.java:80)
    at com.example.hello.web.VertxRegistrationService.lambda$0(VertxRegistrationService.java:26)
    at com.example.hello.web.TcclSwitch.executeWithTCCLSwitch(TcclSwitch.java:11)
    at com.example.hello.web.VertxRegistrationService.start(VertxRegistrationService.java:26)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.felix.scr.impl.helper.BaseMethod.invokeMethod(BaseMethod.java:222)
    at org.apache.felix.scr.impl.helper.BaseMethod.access$500(BaseMethod.java:37)
    at org.apache.felix.scr.impl.helper.BaseMethod$Resolved.invoke(BaseMethod.java:615)
    at org.apache.felix.scr.impl.helper.BaseMethod.invoke(BaseMethod.java:499)
    at org.apache.felix.scr.impl.helper.ActivateMethod.invoke(ActivateMethod.java:295)
    at org.apache.felix.scr.impl.manager.SingleComponentManager.createImplementationObject(SingleComponentManager.java:302)
    at org.apache.felix.scr.impl.manager.SingleComponentManager.createComponent(SingleComponentManager.java:113)
    at org.apache.felix.scr.impl.manager.SingleComponentManager.getService(SingleComponentManager.java:866)
    at org.apache.felix.scr.impl.manager.SingleComponentManager.getServiceInternal(SingleComponentManager.java:833)
    at org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInternal(AbstractComponentManager.java:724)
    at org.apache.felix.scr.impl.manager.AbstractComponentManager.enable(AbstractComponentManager.java:399)
    at org.apache.felix.scr.impl.config.ConfigurableComponentHolder.enableComponents(ConfigurableComponentHolder.java:676)
    at org.apache.felix.scr.impl.BundleComponentActivator.initialEnable(BundleComponentActivator.java:339)
    at org.apache.felix.scr.impl.Activator.loadComponents(Activator.java:360)
    at org.apache.felix.scr.impl.Activator.access$000(Activator.java:53)
    at org.apache.felix.scr.impl.Activator$ScrExtension.start(Activator.java:260)
    at org.apache.felix.utils.extender.AbstractExtender.createExtension(AbstractExtender.java:259)
    at org.apache.felix.utils.extender.AbstractExtender.modifiedBundle(AbstractExtender.java:232)
    at org.apache.felix.utils.extender.AbstractExtender.addingBundle(AbstractExtender.java:192)
    at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:469)
    at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:415)
    at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
    at org.osgi.util.tracker.AbstractTracked.trackInitial(AbstractTracked.java:183)
    at org.osgi.util.tracker.BundleTracker.open(BundleTracker.java:156)
    at org.apache.felix.utils.extender.AbstractExtender.startTracking(AbstractExtender.java:150)
    at org.apache.felix.utils.extender.AbstractExtender.doStart(AbstractExtender.java:142)
    at org.apache.felix.scr.impl.Activator.doStart(Activator.java:170)
    at org.apache.felix.utils.extender.AbstractExtender.start(AbstractExtender.java:114)
    at org.apache.felix.scr.impl.Activator.restart(Activator.java:140)
    at org.apache.felix.scr.impl.config.ScrConfiguration.configure(ScrConfiguration.java:215)
    at org.apache.felix.scr.impl.config.ScrConfiguration.start(ScrConfiguration.java:136)
    at org.apache.felix.scr.impl.Activator.start(Activator.java:110)
    at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:697)
    at org.apache.felix.framework.Felix.activateBundle(Felix.java:2226)
    at org.apache.felix.framework.Felix.startBundle(Felix.java:2144)
    at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:998)
    at aQute.launcher.Launcher.update(Launcher.java:483)
    at aQute.launcher.Launcher.activate(Launcher.java:382)
    at aQute.launcher.Launcher.run(Launcher.java:276)
    at aQute.launcher.Launcher.main(Launcher.java:133)

any help appreciated

1

There are 1 answers

2
alex29260 On

It is because "PlatformDependent0" import "sun.misc".

You can solve this by setting "org.osgi.framework.system.packages.extra=sun.misc"

EDIT 1 :

I start the OSGi framework (Apache Felix) this way :

Map<String, String> configProperties = Main.loadConfigProperties();
Main.copySystemProperties(configProperties);
configProperties.put("org.osgi.framework.system.packages.extra","sun.misc");
Framework fw = new Felix(configProperties);
fw.init();
AutoProcessor.process(configProperties, fw.getBundleContext());

But I guess you can directly put this setting in the "felix.config.properties" file.

The problems occurs because sun.misc is private API. So you have to explicitly add the package as an extra package provided by the Main Bundle. It is done implicitly for public API (java.lang, java.util...)