"A terminally deprecated method in sun.misc.Unsafe has been called"
With the latest commits, and today's download from Oracle, the following error is omitted towards the end of JavaScript compilation:
WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::arrayBaseOffset has been called by com.google.common.hash.LittleEndianByteArray$UnsafeByteArray (file:/scratch/mark/cache/bazel/_bazel_mark/d465ce32b1ece8e176cd9a6c173f6b09/execroot/_main/bazel-out/k8-fastbuild/bin/compiler_uberjar_deploy.jar)
WARNING: Please consider reporting this to the maintainers of class com.google.common.hash.LittleEndianByteArray$UnsafeByteArray
WARNING: sun.misc.Unsafe::arrayBaseOffset will be removed in a future release
closure-compiler$ git describe --long
v20250317-0-g455c10971
$ java --version
java 24 2025-03-18
Java(TM) SE Runtime Environment (build 24+36-3646)
Java HotSpot(TM) 64-Bit Server VM (build 24+36-3646, mixed mode, sharing)
What project are you trying to compile? How do I reproduce this?
To reproduce, just install the latest java from Oracle (downloads)
It displays the warning with any JavaScript input, for example a blank input:
$ echo '' | /path/to/java -jar /path/to/closure-compiler-v20240317.jar
The compiler is waiting for input via stdin.
WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::arrayBaseOffset has been called by com.google.javascript.jscomp.jarjar.com.google.protobuf.UnsafeUtil$MemoryAccessor (file:/opt/google/closure-compiler/closure-compiler-v20240317.jar)
WARNING: Please consider reporting this to the maintainers of class com.google.javascript.jscomp.jarjar.com.google.protobuf.UnsafeUtil$MemoryAccessor
WARNING: sun.misc.Unsafe::arrayBaseOffset will be removed in a future release
It's also reproducible with the latest master of Closure Compiler.
From the errors, this is coming both from guava and protobuf. I don't yet see a guava issue tracking it, but for protobuf there's https://github.com/protocolbuffers/protobuf/issues/20760.
Guava line in latest: https://github.com/google/guava/blob/2aaa4548ec1d4dfcde6a98d1d8a87dbd4810a38d/guava/src/com/google/common/hash/LittleEndianByteArray.java#L249
If I'm reading both of those properly, failure to access these will not break the tool, though it will result in these logs.
According to JEP 498, this will log a warning in Java 24, then in Java 26 (or later) this will start to throw. To suppress the warning, the JVM arg --sun-misc-unsafe-memory-access=allow can be passed at least through Java 26 to continue to allow this without warnings.
We'll wait for Guava & protobuf to fix this - we can upgrade then, or if that doesn't happen & we want to move to Java 21, suppress this.
We're currently on Java 21 specifically to align with how this is built internally within Google.
Same warning issues: WARNING: A terminally deprecated method in sun.misc.Unsafe has been called WARNING: sun.misc.Unsafe::arrayBaseOffset has been called by com.google.javascript.jscomp.jarjar.com.google.protobuf.UnsafeUtil$MemoryAccessor (file:/.../closure-compiler-v20250402.jar) WARNING: Please consider reporting this to the maintainers of class com.google.javascript.jscomp.jarjar.com.google.protobuf.UnsafeUtil$MemoryAccessor WARNING: sun.misc.Unsafe::arrayBaseOffset will be removed in a future release
java --version java 24 2025-03-18 Java(TM) SE Runtime Environment (build 24+36-3646) Java HotSpot(TM) 64-Bit Server VM (build 24+36-3646, mixed mode, sharing)
Since this error is emitted by the JRE when executed (as opposed to just a build time), I'm adding the suppression flag to the npm library. Unfortunately that flag is unrecognized before JDK 24, so you have to also ignore unrecognized flags.
Guava reports that it is fixed: https://github.com/google/guava/issues/7811
I got this same error today:
WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::arrayBaseOffset has been called by com.google.common.hash.LittleEndianByteArray$UnsafeByteArray (file:/C:/buildbot/win11-arm64-8gb-snapdragon-7c/emscripten_win11_arm64/build/emscripten/main/node_modules/google-closure-compiler-java/compiler.jar)
WARNING: Please consider reporting this to the maintainers of class com.google.common.hash.LittleEndianByteArray$UnsafeByteArray
WARNING: sun.misc.Unsafe::arrayBaseOffset will be removed in a future release
Downgrading from Java 24 down to Java 21 avoided this issue.