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

java.lang.NoSuchMethodError when calling compress(ByteBuffer, ByteBuffer) #251

Closed
domesticsimian opened this issue Aug 8, 2020 · 13 comments

Comments

@domesticsimian
Copy link

Starting in version 1.1.7.4 of snappy, when I attempt to call compress(ByteBuffer, ByteBuffer), I see the following exception:

Exception in thread "main" java.lang.NoSuchMethodError: java.nio.ByteBuffer.limit(I)Ljava/nio/ByteBuffer;
        at org.xerial.snappy.Snappy.compress(Snappy.java:152)
        at SnappyRepro.App.main(App.java:15)

This is almost certainly the issue that is described in this stackoverflow post. I suspect that between version 1.1.7.3 and 1.1.7.4 of snappy, the JDK used to compile the official version of the library was updated.

I've uploaded https://github.com/disturbedsaint/SnappyRepro with reproduction instructions.

@domesticsimian
Copy link
Author

domesticsimian commented Aug 8, 2020

I just noticed #247 - and have confirmed that 1.1.7.5 also works for me. But the issue appears to be back in 1.1.7.6.

@xerial
Copy link
Owner

xerial commented Aug 26, 2020

Released 1.1.7.7 recompiled with JDK8. I still need a more reliable way to compile snappy-java with jdk11 to avoid this type of incompatibility issue.

@bokken
Copy link
Contributor

bokken commented Aug 26, 2020

I am not sure how to do it with gradle, but jdk 9 introduced the "release" argument for javac. Here is the jdk 11 doc.

Compiles against the public, supported and documented API for a specific VM version. Supported release targets are 6, 7, 8, 9, 10, and 11.

@xerial
Copy link
Owner

xerial commented Aug 26, 2020

Yeah. I've tried --release 8 option, but it caused another issue because this option totally hides sun.misc.Unsafe APIs, which are used inside the pure-scala implementation.

@bokken
Copy link
Contributor

bokken commented Aug 26, 2020

Ah yes. That is noted:

When using --release for a version of the Java Platform that supports modules, you can’t use --add-modules to access internal JDK modules, nor can you use --add-exports to access internal JDK APIs in the modules.

@xerial
Copy link
Owner

xerial commented Aug 26, 2020

--add-exports is worth trying. Thanks

@xerial
Copy link
Owner

xerial commented Aug 26, 2020

ah. The doc says it can't be used with release option. Hm. We need to seek an option to use only JDK8/11 compatible ByteBuffer methods.

@xerial
Copy link
Owner

xerial commented Aug 26, 2020

Let me close this issue as 1.1.7.7 should solve this issue. The future improvement ideas are ticketed in #252 #253

@xerial xerial closed this as completed Aug 26, 2020
@ijuma
Copy link

ijuma commented Oct 20, 2020

@xerial In Apache Kafka, we use --release 8 and it works fine. We had to upgrade to a recent Gradle version that includes a recent enough version of Zinc for it to work.

@xerial
Copy link
Owner

xerial commented Oct 21, 2020

@ijuma Yes. I've tried --release 8 but snappy-java uses sun.misc.Unsafe and this option caused compilation errors.

@ijuma
Copy link

ijuma commented Oct 21, 2020

@xerial
Copy link
Owner

xerial commented Oct 21, 2020

I see. So instead of importing sun.misc.Unsafe, we can use reflection to avoid direct reference to sun.misc.Unsafe

@xerial
Copy link
Owner

xerial commented Feb 1, 2023

Now that pure-java Snappy code has been removed, we can enable --release 8 option. #390 This issue should be fixed in the upcoming version.

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

4 participants