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

ClassNotFoundException: sun.misc.Unsafe when using Java 17/JBoss EAP 8.0.0.GA #3222

Open
ludade opened this issue Apr 10, 2024 · 0 comments
Open

Comments

@ludade
Copy link

ludade commented Apr 10, 2024

Hello,

We have a similar issue than #3220 with an application under JBoss EAP 8.0.0.GA running with java 17. On the REST get call we use caching feature with ehcache-3.10.8-jakarta.jar and it throws the following error (log server error) :

	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//org.ehcache.impl.internal.concurrent.ThreadLocalRandomUtil.getSMU(ThreadLocalRandomUtil.java:52)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//org.ehcache.impl.internal.concurrent.ThreadLocalRandomUtil.<clinit>(ThreadLocalRandomUtil.java:37)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//org.ehcache.impl.internal.concurrent.ConcurrentHashMap$TreeBin.<clinit>(ConcurrentHashMap.java:3316)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//org.ehcache.impl.internal.concurrent.ConcurrentHashMap.<clinit>(ConcurrentHashMap.java:283)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//org.ehcache.impl.internal.store.heap.SimpleBackend.<init>(SimpleBackend.java:38)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//org.ehcache.impl.internal.store.heap.OnHeapStore.lambda$new$4(OnHeapStore.java:229)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//org.ehcache.impl.internal.store.heap.OnHeapStore.<init>(OnHeapStore.java:233)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//org.ehcache.impl.internal.store.heap.OnHeapStore$Provider.createStoreInternal(OnHeapStore.java:1668)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//org.ehcache.impl.internal.store.heap.OnHeapStore$Provider.createStore(OnHeapStore.java:1647)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//org.ehcache.impl.internal.store.heap.OnHeapStore$Provider.createStore(OnHeapStore.java:1620)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//org.ehcache.core.EhcacheManager.getStore(EhcacheManager.java:507)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//org.ehcache.core.EhcacheManager.createNewEhcache(EhcacheManager.java:346)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//org.ehcache.core.EhcacheManager.createCache(EhcacheManager.java:274)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//org.ehcache.core.EhcacheManager.createCache(EhcacheManager.java:252)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//org.ehcache.jsr107.Eh107CacheManager.createCache(Eh107CacheManager.java:180)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//com.myapplication.framework.commons.cache.AbstractMultiCacheAccessor.getCacheOrCreate(AbstractMultiCacheAccessor.java:61)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//com.myapplication.framework.commons.cache.AbstractMultiCacheAccessor.getValue(AbstractMultiCacheAccessor.java:82)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//com.myapplication.framework.commons.nrest.util.RestCache.computeIfAbsent(RestCache.java:296)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//com.myapplication.framework.commons.nrest.util.RestCache.computeIfAbsent(RestCache.java:268)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//com.myapplication.framework.commons.nrest.rules.SBFRuleReader.findEndPointRule(SBFRuleReader.java:136)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//com.myapplication.framework.nrest.api.AbstractRestApi.findRule(AbstractRestApi.java:309)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//com.myapplication.framework.nrest.security.SBFBusinessValidatorDefault.isValid(SBFBusinessValidatorDefault.java:205)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//com.myapplication.framework.nrest.util.BusinessContextUtility.lambda$verifyAndSetServiceContext$2(BusinessContextUtility.java:364)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//com.myapplication.framework.nrest.util.BusinessContextUtility.proceedForValidation(BusinessContextUtility.java:425)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//com.myapplication.framework.nrest.util.BusinessContextUtility.verifyAndSetServiceContext(BusinessContextUtility.java:364)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//com.myapplication.framework.nrest.util.BusinessContextUtility.verifyAndSetServiceContext(BusinessContextUtility.java:311)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//com.myapplication.framework.nrest.util.BusinessContextUtility$Proxy$_$$_WeldClientProxy.verifyAndSetServiceContext(Unknown Source)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear.myapplication-rest-jaxrs-6.0.0-SNAPSHOT-jboss7.war//com.myapplication.banking.myapplication.rest.api.v1.admin.NotificationApi.listNotification(NotificationApi.java:37)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at [email protected]//org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:154)
	at [email protected]//org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:118)
	at [email protected]//org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:560)
	at [email protected]//org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:452)
	at [email protected]//org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$2(ResourceMethodInvoker.java:413)
	at [email protected]//org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:321)
	at [email protected]//org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:415)
	at [email protected]//org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:378)
	at [email protected]//org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:356)
	at [email protected]//org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:70)
	at [email protected]//org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:429)
	at [email protected]//org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:240)
	at [email protected]//org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:154)
	at [email protected]//org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:321)
	at [email protected]//org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:157)
	at [email protected]//org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:229)
	at [email protected]//org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:222)
	at [email protected]//org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
	at [email protected]//org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
	at [email protected]//jakarta.servlet.http.HttpServlet.service(HttpServlet.java:614)
	at [email protected]//io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
	at [email protected]//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:204)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:239)
	at [email protected]//io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:67)
	at [email protected]//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//com.myapplication.framework.nrest.filter.RestWebFilter.doFilter(RestWebFilter.java:64)
	at [email protected]//io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:67)
	at [email protected]//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//com.myapplication.framework.security.filter.AbstractSecurityFilter.filter(AbstractSecurityFilter.java:533)
	at deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear//com.myapplication.framework.security.filter.AbstractSecurityFilter.doFilter(AbstractSecurityFilter.java:461)
	at [email protected]//io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:67)
	at [email protected]//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
	at [email protected]//io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
	at [email protected]//io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
	at [email protected]//io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
	at [email protected]//io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
	at org.wildfly.security.elytron-web.undertow-server@4.0.0.Final-redhat-00001//org.wildfly.elytron.web.undertow.server.ElytronRunAsHandler.lambda$handleRequest$1(ElytronRunAsHandler.java:68)
	at [email protected]//org.wildfly.security.auth.server.FlexibleIdentityAssociation.runAsFunctionEx(FlexibleIdentityAssociation.java:103)
	at [email protected]//org.wildfly.security.auth.server.Scoped.runAsFunctionEx(Scoped.java:161)
	at [email protected]//org.wildfly.security.auth.server.Scoped.runAs(Scoped.java:73)
	at org.wildfly.security.elytron-web.undertow-server@4.0.0.Final-redhat-00001//org.wildfly.elytron.web.undertow.server.ElytronRunAsHandler.handleRequest(ElytronRunAsHandler.java:67)
	at [email protected]//io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:68)
	at [email protected]//io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:117)
	at [email protected]//io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
	at [email protected]//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
	at [email protected]//io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
	at [email protected]//io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
	at [email protected]//io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
	at org.wildfly.security.elytron-web.undertow-server-servlet@4.0.0.Final-redhat-00001//org.wildfly.elytron.web.undertow.server.servlet.CleanUpHandler.handleRequest(CleanUpHandler.java:38)
	at [email protected]//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
	at [email protected]//org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
	at [email protected]//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
	at [email protected]//org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
	at [email protected]//io.undertow.servlet.handlers.SendErrorPageHandler.handleRequest(SendErrorPageHandler.java:52)
	at [email protected]//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
	at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:276)
	at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
	at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:132)
	at [email protected]//io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
	at [email protected]//io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
	at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1430)
	at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1430)
	at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1430)
	at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1430)
	at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1430)
	at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:256)
	at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:101)
	at [email protected]//io.undertow.server.Connectors.executeRootHandler(Connectors.java:393)
	at [email protected]//io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:859)
	at [email protected]//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
	at [email protected]//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
	at [email protected]//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
	at [email protected]//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1348)
	at [email protected]//org.xnio.XnioWorker$WorkerThreadFactory$1$1.run(XnioWorker.java:1282)
	at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: java.lang.ClassNotFoundException: sun.misc.Unsafe from [Module "deployment.myapplication-ear-6.0.0-SNAPSHOT-jboss7.ear" from Service Module Loader]
	at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:200)
	at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:410)
	at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
	at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
	... 108 more

Maybe addition of module-info file in the ehcache jar can resolve the issue under WildFly/JBoss EAP runtimes, see

After some investigation we have found that Redhat has removed the following code on Jboss EAP startup scripts:

call :setModularJdk  
  if "!MODULAR_JDK!" == "true" (
    echo "%~1" | findstr /I "\-\-add\-modules" > nul
    if errorlevel == 1 (
      rem Set default modular jdk options
      set "DEFAULT_MODULAR_JVM_OPTIONS=!DEFAULT_MODULAR_JVM_OPTIONS! --add-exports=java.base/sun.nio.ch=ALL-UNNAMED"
      set "DEFAULT_MODULAR_JVM_OPTIONS=!DEFAULT_MODULAR_JVM_OPTIONS! --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED"
      set "DEFAULT_MODULAR_JVM_OPTIONS=!DEFAULT_MODULAR_JVM_OPTIONS! --add-exports=jdk.unsupported/sun.reflect=ALL-UNNAMED"
    ) else (
      set "DEFAULT_MODULAR_JVM_OPTIONS="
    )
  )
goto:eof

Addition of the following code can resolve this issue on Jboss EAP 8.0.0. However it's a short term workaround because more and more libraries include module-info file now. And we need to apply this workaround on other runtimes such as: Wilfly, OpenLiberty, etc.

Regards.

Originally posted by @ludade in #3220 (comment)

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

1 participant