airlift/aircompressor

Does not work with java 16+?

mvaudel opened this issue · 5 comments

Hi,

We are very happy users of your library, many thanks for this awesome piece of code.

We are however having initialization issues on machines using java 16 and above, which seems to be caused by a change in nio.Buffer. A StackTrace is below. Do you have an idea on how to circumvent this?

Many thanks for your help,

Marc

Exception in thread "ImportThread" java.lang.ExceptionInInitializerError
	at io.airlift.compress.zstd.ZstdFrameCompressor.writeMagic(ZstdFrameCompressor.java:57)
	at io.airlift.compress.zstd.ZstdFrameCompressor.compress(ZstdFrameCompressor.java:143)
	at io.airlift.compress.zstd.ZstdCompressor.compress(ZstdCompressor.java:45)
	...
        Suppressed: java.lang.NoClassDefFoundError: Could not initialize class io.airlift.compress.zstd.UnsafeUtil
		at io.airlift.compress.zstd.ZstdFrameCompressor.writeMagic(ZstdFrameCompressor.java:57)
		at io.airlift.compress.zstd.ZstdFrameCompressor.compress(ZstdFrameCompressor.java:143)
		at io.airlift.compress.zstd.ZstdCompressor.compress(ZstdCompressor.java:45)
		...
Caused by: io.airlift.compress.IncompatibleJvmException: Zstandard requires access to java.nio.Buffer raw address field
	at io.airlift.compress.zstd.UnsafeUtil.<clinit>(UnsafeUtil.java:53)
	...

Hi,

I ran into the same issue while migrating a project from Java 8 to 16. After some investigating, it seems the issue is due to the module system introduced in Java 9. The java package "java.nio" is not open for modification.

As a workaround, you can try adding "--add-opens java.base/java.nio=ALL-UNNAMED" when launching your application. See the following StackOverflow post.

@svenofix Thanks for the suggested workaround! I can confirm that it works for our project as well.

However, the adding of "--add-opens java.base/java.nio=ALL-UNNAMED" is only supported from Java 9 onwards. Hence we would have to first detect the Java version and then apply this fix only for Java versions newer than Java 8. Did you find a generic workaround for this as well? Or did you simply introduce the requirement of Java 16 for your project?

@hbarsnes I simply introduced the requirement of Java 16, since we only need it for new projects. We're creating a new custom docker image anyways, so no need to check for different java versions.

This is now fixed in version 0.19, which we just released.

Great! Thanks! I can confirm that it solves the issue on our end.