You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by sp...@planet.ms on 2020/10/02 10:38:45 UTC

Sling Starter 12: for using ehcache 3 : sun.misc.Unsafe not accessible

Hi!

I'm currently having serious trouble running our application on the current Sling Starter 12 snapshot
since we are using ehache 3, which uses sun.misc.Unsafe internally. This works with Sling Starter 11,
but since it changed to the feature launcher, this class seems to have disappeared from the
classpath (the class loading of ehcache classes fails with a java.lang.NoClassDefFoundError: sun/misc/Unsafe).

I tried to add command line arguments
--add-modules=jdk.unsupported
and
--add-opens=jdk.unsupported/sun.misc=ALL-UNNAMED
to the launcher command line, as I've seen that suggested on the net for similar problems, but it didn't help.
In fact, this doesn't seem to be the problem: even without those flags the jdk.unsupported module does export sun.misc:

module { name: jdk.unsupported@11.0.6, [mandated java.base], exports: [com.sun.nio.file, sun.misc, sun.reflect], opens: [sun.misc, sun.reflect] }

So it seems the module is loaded, but not used to load the class.

The easiest way to reproduce the problem is to add this to some JSP:
<%
    Class clazz = sun.misc.Unsafe.class;
%>
In case that matters: I tried JDK 11 and 13 on MacOS, as well as JDK 11 on an x86_64 Linux.
This works on Sling Starter 11, but not the current 12 snapshot.

Do you have suggestions what to do to allow sun.misc.Unsafe to be used by the ehcache 3 bundle?
Any help would be greatly appreciated!

Thank you and best regards,

Hans-Peter


Re: Sling Starter 12: for using ehcache 3 : sun.misc.Unsafe not accessible

Posted by Robert Munteanu <ro...@apache.org>.
Hi,

On Mon, 2020-10-05 at 09:14 +0200, spiegelyu@planet.ms wrote:
> Hi!
> 
> "Robert Munteanu" <ro...@apache.org> wrote:
> > I am not sure how clean this solution is, but you might want to add
> > the
> > following to your feature model
> > 
> >   "framework-properties": {
> >     "org.osgi.framework.system.packages.extra": "sun.misc"
> >   }
> > 
> > I think you can also set it via the CLI with
> > 
> > -D org.osgi.framework.system.packages.extra=sun.misc
> 
> Thank you, yes,
> -D org.osgi.framework.system.packages.extra=sun.misc
> is a workaround which does help and makes sun.misc.Unsafe3 accessible
> again to the ehcache 3 bundle on Sling Starter 12, though I have an
> uneasy feeling about it. Setting system properties is not a nice
> thing you should have to do when
> deploying an application, and we don't create a feature model for it
> so far.
> 
> This is, however, something different than what happens on Sling 11 -
> now sun.misc is "officially" exported by the felix framework bundle 
> http://localhost:9090/system/console/bundles/0 which it isn't on
> Sling Starter 11. Not sure whether this is good or bad.
> 
> I'm still wondering whether I should open a bug for this, though,
> since that is a sudden change of the behavior when going from 11 to
> 12. I'm not quite sure about that and for which subproject this would
> be. What do you think?

I think you can file this against the Starter. If it's a regression
compared to version 11 we should fix it.

Thanks,
Robert


Re: Sling Starter 12: for using ehcache 3 : sun.misc.Unsafe not accessible

Posted by sp...@planet.ms.
Hi!

"Robert Munteanu" <ro...@apache.org> wrote:
> I am not sure how clean this solution is, but you might want to add the
> following to your feature model
>
>   "framework-properties": {
>     "org.osgi.framework.system.packages.extra": "sun.misc"
>   }
>
> I think you can also set it via the CLI with
>
> -D org.osgi.framework.system.packages.extra=sun.misc

Thank you, yes,
-D org.osgi.framework.system.packages.extra=sun.misc
is a workaround which does help and makes sun.misc.Unsafe3 accessible again to the ehcache 3 bundle on Sling Starter 12, though I have an uneasy feeling about it. Setting system properties is not a nice thing you should have to do when
deploying an application, and we don't create a feature model for it so far.

This is, however, something different than what happens on Sling 11 - now sun.misc is "officially" exported by the felix framework bundle http://localhost:9090/system/console/bundles/0 which it isn't on Sling Starter 11. Not sure whether this is good or bad.

I'm still wondering whether I should open a bug for this, though, since that is a sudden change of the behavior when going from 11 to 12. I'm not quite sure about that and for which subproject this would be. What do you think?

Thanks and best regards,

Hans-Peter


Re: Sling Starter 12: for using ehcache 3 : sun.misc.Unsafe not accessible

Posted by Robert Munteanu <ro...@apache.org>.
Hi Hans-Peter,

On Fri, 2020-10-02 at 12:38 +0200, spiegelyu@planet.ms wrote:
> Do you have suggestions what to do to allow sun.misc.Unsafe to be
> used by the ehcache 3 bundle?
> Any help would be greatly appreciated!

I am not sure how clean this solution is, but you might want to add the
following to your feature model

  "framework-properties": {
    "org.osgi.framework.system.packages.extra": "sun.misc"
  }

I think you can also set it via the CLI with

-D org.osgi.framework.system.packages.extra=sun.misc

Hope this helps,
Robert