Exception java.lang.NoClassDefFoundError:sun.misc.Unsafe

1,787 views
Skip to first unread message

Manoj

unread,
Jul 30, 2011, 11:58:35 PM7/30/11
to hector-users
I am using Hector 0.7.0-31 and create an OSGI bundle for the hector. I
created a OSGI bundle with all the required libraries as below
cassandra-all-0.7.4.jar
cassandra-javautils-0.7.0.jar
FastInfoset-1.2.2.jar
guava-r08.jar
high-scale-lib-1.1.1.jar
jul-to-slf4j-1.6.1.jar
perf4j-0.9.12.jar
slf4j-api-1.6.1.jar
slf4j-simple-1.6.1.jar
hector-core-0.7.0-31.jar
libthrift-0.5.0.jar

When I run my application I get the below mentioned
java.lang.NoClassDefFoundError. It seems high_scale_lib calls a
sun.misc.Unsafe which it is not founding in the classpath.
I ran my client application by passing with --verbose:class and see
this particular class loaded as well. I am using ibm jre.

I will appreciate any help resolving this issue.

Exception in thread "StackGatewayConnector"
java.lang.NoClassDefFoundError: sun.misc.Unsafe
at org.cliffc.high_scale_lib.UtilUnsafe.getUnsafe(UtilUnsafe.java:21)
at
org.cliffc.high_scale_lib.NonBlockingHashMap.<clinit>(NonBlockingHashMap.java:
79)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
at
me.prettyprint.cassandra.connection.HConnectionManager.<init>(HConnectionManager.java:
61)
at
me.prettyprint.cassandra.service.AbstractCluster.<init>(AbstractCluster.java:
69)
at
me.prettyprint.cassandra.service.AbstractCluster.<init>(AbstractCluster.java:
65)
at
me.prettyprint.cassandra.service.ThriftCluster.<init>(ThriftCluster.java:
17)
at
me.prettyprint.hector.api.factory.HFactory.createCluster(HFactory.java:
157)
at
me.prettyprint.hector.api.factory.HFactory.getOrCreateCluster(HFactory.java:
136)
at
me.prettyprint.hector.api.factory.HFactory.getOrCreateCluster(HFactory.java:
109)
at
com.approuter.gateway.server.StackGatewayConnector.run(StackGatewayConnector.java:
63)
Caused by: java.lang.ClassNotFoundException: sun.misc.Unsafe
at
org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(BundleLoader.java:
481)
at
org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:
397)
at
org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:
385)
at
org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:
87)
at java.lang.ClassLoader.loadClass(ClassLoader.java:619)

Nate McCall

unread,
Jul 31, 2011, 12:11:53 AM7/31/11
to hector...@googlegroups.com
The Unsafe class provides some direct access to memory management and
low-level stuff for folks who know what that are doing.

I have very little OSGi foo, so I have no advice here.

Jim Newsham

unread,
Jul 31, 2011, 1:14:43 AM7/31/11
to hector-users
Note that Unsafe is in package sun.misc... any classes under sun.* are
not standard Java and won't be portable to non-Sun (Oracle) JVMs.
Manoj says he's using an IBM jre. :(

Jim

Manoj

unread,
Jul 31, 2011, 2:38:36 PM7/31/11
to hector-users
Thanks guys for the response. I figured out the problem. The issue is
OSGI has a concept of the framework bundle and by default it only
exports the java.*, javax.* packages. It doesn't export the sun.*
packages. So when user invoke the client application using hector it
needs to pass -Dorg.osgi.framework.bootdelegation=* and then the
framework bundle will export all the classes.

To understand more on the OSGI and details please look at the
following blogs. http://blog.springsource.com/2009/01/19/exposing-the-boot-classpath-in-osgi/

I think it will be very valuable to have hector as a part of the osgi
spring source repository so that it can be used easily in the OSGI
Container.
Reply all
Reply to author
Forward
0 new messages