Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoClassDefFoundError: sun.misc.Unsafe since version 2.8.3 #1305

Closed
cnsgithub opened this issue Apr 30, 2018 · 3 comments
Closed

NoClassDefFoundError: sun.misc.Unsafe since version 2.8.3 #1305

cnsgithub opened this issue Apr 30, 2018 · 3 comments

Comments

@cnsgithub
Copy link

cnsgithub commented Apr 30, 2018

After upgrading gson to version 2.8.3 I receive a NoClassDefFoundError when starting up my WildFly 12 server.

Reproducer:

public class Foo {
   private static final Gson gson = new GsonBuilder().create();
}

Stacktrace:

Caused by: java.lang.NoClassDefFoundError: sun/misc/Unsafe
	at com.google.gson//com.google.gson.internal.reflect.UnsafeReflectionAccessor.getUnsafeInstance(UnsafeReflectionAccessor.java:47)
	at com.google.gson//com.google.gson.internal.reflect.UnsafeReflectionAccessor.<init>(UnsafeReflectionAccessor.java:31)
	at com.google.gson//com.google.gson.internal.reflect.ReflectionAccessor.<clinit>(ReflectionAccessor.java:36)
	at com.google.gson//com.google.gson.internal.ConstructorConstructor.<init>(ConstructorConstructor.java:51)
	at com.google.gson//com.google.gson.Gson.<init>(Gson.java:205)
	at com.google.gson//com.google.gson.GsonBuilder.create(GsonBuilder.java:597)
	at deployment.Foo.ear//Foo.<clinit>(Foo.java:24)
...
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
	at java.base/java.lang.Class.newInstance(Class.java:558)
	at org.jboss.as.weld.common//org.jboss.as.weld.deployment.WeldPortableExtensions.tryRegisterExtension(WeldPortableExtensions.java:53)
	at org.jboss.as.weld//org.jboss.as.weld.deployment.processors.WeldPortableExtensionProcessor.loadAttachments(WeldPortableExtensionProcessor.java:119)
	at org.jboss.as.weld//org.jboss.as.weld.deployment.processors.WeldPortableExtensionProcessor.deploy(WeldPortableExtensionProcessor.java:79)
	at org.jboss.as.server@4.0.0.Final//org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:144)
	... 8 more

Workaround in WildFly 12 module.xml:

<module xmlns="urn:jboss:module:1.1" name="com.google.gson">
    <resources>
        <resource-root path="gson-2.8.3.jar"/>
    </resources>
    <dependencies>
        <module name="sun.jdk" export="true" >
            <imports>
                <include path="sun/misc/Unsafe" />
            </imports>
        </module>
    </dependencies>   
</module>

Question:
Why did gson introduce this weird dependency?

@inder123
Copy link
Collaborator

Are you using Java 9? This code path gets exercised only for Java 9.
This stacktrace is harmless as we check whether Sun's Unsafe allocator is available. If unsafe allocator is not available, we use something else.

I will remove this spurious stacktrace in the next release.

@inder123
Copy link
Collaborator

inder123 commented May 1, 2018

Fixed in Gson 2.8.4 through #1306.
Please try it out and let me know if you still need the sun.misc.Unsafe dependency.

@inder123 inder123 closed this as completed May 1, 2018
@cnsgithub
Copy link
Author

Yes, I am using Java 9.

And I am not getting this stacktrace any longer with gson 2.8.4. Thanks for fixing and releasing it so quickly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants