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: java.nio.ByteBuffer.clear() #5450

ahorek opened this issue Nov 15, 2018 · 6 comments

java.lang.NoSuchMethodError: java.nio.ByteBuffer.clear() #5450

ahorek opened this issue Nov 15, 2018 · 6 comments


Copy link

ahorek commented Nov 15, 2018


java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)

Actual behaviour

rvm get head

raises an error

    Installing rvm gem in 1 gemsetsUnhandled Java exception: java.lang.NoSuchMethodError: java.nio.ByteBuffer.clear()Ljava/nio/ByteBuffer;
java.lang.NoSuchMethodError: java.nio.ByteBuffer.clear()Ljava/nio/ByteBuffer;
           encode at org/jruby/
     doEncodeUTF8 at org/jruby/
   encodeBytelist at org/jruby/
           <init> at org/jruby/
        newString at org/jruby/
        newString at org/jruby/
  createFileClass at org/jruby/
         initCore at org/jruby/
        bootstrap at org/jruby/
             init at org/jruby/
      newInstance at org/jruby/
      internalRun at org/jruby/
              run at org/jruby/
             main at org/jruby/

the problem is that I have a jruby's binary that was compiled with java 9, but executed with java 8.

Expected behaviour

this should be a workaround

Copy link

kares commented Nov 15, 2018

should be easy to put up a PR ... mostly about: ((Buffer) buf).clear(); with a comment why its there.

Copy link
Contributor Author

ahorek commented Nov 20, 2018

there's also a problem with java.lang.Math

irb(main):001:0> require 'date'
=> true
irb(main):002:0> DateTime.strptime('-1', '%s')
Traceback (most recent call last):
       16: from
       15: from org.jruby.internal.runtime.methods.MixedModeIRMethod.INTERPRET_METHOD(
       14: from
       13: from
       12: from
       11: from
       10: from org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(
        9: from$INVOKER$s$$INVOKER$s$_strptime.gen)
        8: from
        7: from
        6: from
        5: from org.jruby.util.RubyDateParser.parse(
        4: from org.jruby.util.StrptimeParser.parse(
        3: from org.jruby.util.StrptimeParser$StringParser.access$100(
        2: from org.jruby.util.StrptimeParser$StringParser.parse(
        1: from org.jruby.util.StrptimeParser$StringParser.readDigitsMax(
Java::JavaLang::NoSuchMethodError (java.lang.Math.multiplyExact(JI)J)

Copy link

headius commented Nov 21, 2018

Hmm that is harder to avoid ☹️ If we wrap this in another method we may interfere with the VM intrinsic used to optimize these methods.

These cases should be pretty limited, though...we can just cast everything to long in those few places.

I hope there aren't going to be too many more of these; we are not ready to start depending on Java 11. Maybe we need to look into the build using JDK8 runtime library.

Copy link

headius commented Nov 21, 2018

Ok I looked into the Java 9+ -release flag for javac, and it gets us halfway there. If you specify -release 8 it will only compile against Java 8 APIs, which should solve all these cases in one swoop. Unfortunately, it also does not expose unsupported APIs like all of sun.misc from which we get signal-handling and Unsafe classes. So this might be a dead end, unless we can eliminate all uses of sun.misc in our main codebase (might be able to move to another library).

Copy link

headius commented Nov 27, 2018

@enebo We might be able to get the -release 8 flag to work if we reincorporate mock libraries for Unsafe and the whole SignalHandler stuff in sun.misc.

Copy link

kares commented Dec 10, 2018

resolved by 62dc58b (and some previous commits actually)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging a pull request may close this issue.

3 participants