JDK-8269602 : Gracefully handle absence of Unsafe.defineAnonymousClass
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Priority: P1
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2021-06-29
  • Updated: 2022-03-21
  • Resolved: 2022-03-21
Related Reports
Duplicate :  
Relates :  
Description
With JDK 17, Unsafe.defineAnonymousClass is no more. Nashorn must handle its absence gracefully when --anonymous-classes option is set to "auto" (which is the default). It should still reject starting up if someone explicitly set the option to "true". The behavior when it's set to "false" is unchanged.
Comments
Before this is fixed, attempts to start Nashorn on JDK 17 result in : Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: no such method: sun.misc.Unsafe.defineAnonymousClass(Class,byte[],Object[])Class/invokeVirtual at org.openjdk.nashorn/org.openjdk.nashorn.internal.runtime.Context$AnonymousContextCodeInstaller.lambda$getDefineAnonymousClass$0(Context.java:335) at java.base/java.security.AccessController.doPrivileged(AccessController.java:318) at org.openjdk.nashorn/org.openjdk.nashorn.internal.runtime.Context$AnonymousContextCodeInstaller.getDefineAnonymousClass(Context.java:327) at org.openjdk.nashorn/org.openjdk.nashorn.internal.runtime.Context$AnonymousContextCodeInstaller.<clinit>(Context.java:317) ...
29-06-2021