You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
IndexOutOfBoundsException during SWAR string encoding #859
This is likely a result of the extension being built with a newer Java than 1.8. there are ways we can fix the build so that that can still work, but the short-term fix would be to use Java 1.8 to build and re-release the Java extension.
The problem is that the method it's using is from a newer version of Java so when it runs on the older version it can't find it.
Right the error message is a bit misleading. It complains about a missing function, but that's after it ran into an IndexOutOfBoundsException which seem to be the root cause.
I don't use java regularly any longer (so it's possible the format of the exception messages changed) but when it can't find a method due to classpath incompatibility we should (or at least used to) receive a java.lang.NoSuchMethodError. This would when compiling against one version of a library but running against another version that didn't have that method.
I am away from my computer but I can help in a while or tomorrow. Still pretty sure this is a problem of compiling against a newer version, and the source and target flags only set the version of bytecode that gets emitted. There is a separate flag that would force it to use older versions of APIs... But that flag only exists on newer versions of java which would prevent this from building on 1.8.
Basically like compiling them against a newer version of glibc and breaking binary compatibility with older ones.
Yeah I know, it's a mess, the transition from 1.8 to 9 has caused all sorts of little headaches like this, which is why JRuby 10 has jumped way forward to Java 21. I can help patch this up though and it won't be a problem in the future.
Now that I'm "in the office" and not on my phone I realize that other warning is not what I thought it was. That is just a warning that rspec emits when it's trying to parse a Java exception and it doesn't know how to display the failing Java source line:
[] json $ cat npe_spec.rb
describe "spec that raises NPE" do
it "breaks stack analysis" do
java.lang.System.getProperty(nil)
end
end
[] json $ rspec npe_spec.rb
Ignoring resolv-0.6.2 because its extensions are not built. Try: gem pristine resolv --version 0.6.2
Ignoring resolv-0.6.2 because its extensions are not built. Try: gem pristine resolv --version 0.6.2
F
Failures:
1) spec that raises NPE breaks stack analysis
Failure/Error: Unable to find java.lang.System.checkKey(java/lang/System.java to read failed line
Java::JavaLang::NullPointerException:
key can't be null
# java.lang.System.checkKey(java/lang/System.java:854)
# java.lang.System.getProperty(java/lang/System.java:730)
# java.lang.reflect.Method.invoke(java/lang/reflect/Method.java:498)
# RUBY.<main>(/Users/headius/work/json/npe_spec.rb:3)
# java.lang.invoke.MethodHandle.invokeWithArguments(java/lang/invoke/MethodHandle.java:627)
There's no bug in json.
I did go ahead and modify the build to guarantee it always builds for Java 8/1.8 using the --release flag when it's available, as part of a few other build tweaks in #866. We haven't actually seen that problem yet, but if releases start getting built with JDK versions newer than 8, this is he the way to avoid it.
changed the title [-]Unable to find java.base/java.nio.Buffer.checkIndex[/-][+]IndexOutOfBoundsException during SWAR string encoding[/+]on Sep 20, 2025
Just FYI I saw that selenium-webdriver has shipped a new version that adds a version requirement because of this bug. It seems like their CI hadn't tested 2.15.0.
Activity
byroot commentedon Sep 18, 2025
Sadly I don't know much about Java / JRuby, but I assume it's a result of #835.
@headius / @samyron could one of you take care of this?
headius commentedon Sep 18, 2025
This is likely a result of the extension being built with a newer Java than 1.8. there are ways we can fix the build so that that can still work, but the short-term fix would be to use Java 1.8 to build and re-release the Java extension.
The problem is that the method it's using is from a newer version of Java so when it runs on the older version it can't find it.
byroot commentedon Sep 18, 2025
Isn't it what
json/Rakefile
Line 143 in 55552ca
Why would it suddenly be a problem? I don't want to have to deal with figuring out how to downgrade to Java 8 on my machine.
samyron commentedon Sep 18, 2025
Could this actually be a bug?
If
ptr = 0then all is fine... ifptr > 0then we may read off the end of the buffer.samyron commentedon Sep 18, 2025
It looks like there are a few instances in this class where I missed that...
byroot commentedon Sep 18, 2025
Right the error message is a bit misleading. It complains about a missing function, but that's after it ran into an
IndexOutOfBoundsExceptionwhich seem to be the root cause.samyron commentedon Sep 18, 2025
I don't use java regularly any longer (so it's possible the format of the exception messages changed) but when it can't find a method due to classpath incompatibility we should (or at least used to) receive a
java.lang.NoSuchMethodError. This would when compiling against one version of a library but running against another version that didn't have that method.I'll spin up a PR really quick...
byroot commentedon Sep 18, 2025
@sl0thentr0py could you try #860 ? You should be able to point your gemfile to it assuming recent enough bundler:
samyron commentedon Sep 18, 2025
Looking back at
2.13.2I'm now not quite convinced the fix in the PR is correct or the root cause.I would have expected that to raise an
IndexOutOfBoundsExceptionifptr > 0.headius commentedon Sep 18, 2025
I am away from my computer but I can help in a while or tomorrow. Still pretty sure this is a problem of compiling against a newer version, and the source and target flags only set the version of bytecode that gets emitted. There is a separate flag that would force it to use older versions of APIs... But that flag only exists on newer versions of java which would prevent this from building on 1.8.
Basically like compiling them against a newer version of glibc and breaking binary compatibility with older ones.
Yeah I know, it's a mess, the transition from 1.8 to 9 has caused all sorts of little headaches like this, which is why JRuby 10 has jumped way forward to Java 21. I can help patch this up though and it won't be a problem in the future.
fix issue reading off the end of the ByteBuffer if ptr > 0
byroot commentedon Sep 18, 2025
I'm going to ship the
IndexOutOfBoundsExceptiontoday, given it's the issue at hand.However a fix for
Unable to find java.base/java.nio.Buffer.checkIndexwould indeed be welcome, even though it's never supposed to reach that codepath.byroot commentedon Sep 18, 2025
2.14.1 is out with the fix.
sl0thentr0py commentedon Sep 18, 2025
can confirm the issue is fixed, thank you for the quick release!
headius commentedon Sep 18, 2025
Thank you @samyron for the patch. I'll fix the build to avoid the other issue in the future.
headius commentedon Sep 18, 2025
And thank you @byroot for the quick release!
[ruby/json] fix issue reading off the end of the ByteBuffer if ptr > 0
[ruby/json] fix issue reading off the end of the ByteBuffer if ptr > 0
Use --release flag on Java 9+
Use --release flag on Java 9+
headius commentedon Sep 20, 2025
Now that I'm "in the office" and not on my phone I realize that other warning is not what I thought it was. That is just a warning that rspec emits when it's trying to parse a Java exception and it doesn't know how to display the failing Java source line:
There's no bug in json.
I did go ahead and modify the build to guarantee it always builds for Java 8/1.8 using the
--releaseflag when it's available, as part of a few other build tweaks in #866. We haven't actually seen that problem yet, but if releases start getting built with JDK versions newer than 8, this is he the way to avoid it.[-]Unable to find java.base/java.nio.Buffer.checkIndex[/-][+]IndexOutOfBoundsException during SWAR string encoding[/+]headius commentedon Sep 20, 2025
Updated subject to reflect the actual issue and not the rspec stumble.
etiennebarrie commentedon Oct 6, 2025
Just FYI I saw that
selenium-webdriverhas shipped a new version that adds a version requirement because of this bug. It seems like their CI hadn't tested 2.15.0.fix issue reading off the end of the ByteBuffer if ptr > 0
Use --release flag on Java 9+