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

String#slice on multibyte chars raise Exception #1986

Closed
k77ch7 opened this Issue Sep 19, 2014 · 3 comments

Comments

Projects
None yet
3 participants
@k77ch7
Copy link
Contributor

commented Sep 19, 2014

The following example works in MRI Ruby 1.9.3/2.0.0,
but gives java.lang.ArrayIndexOutOfBoundsException on JRuby 1.7.15.

This issue may be related to JRUBY-6860.
https://jira.codehaus.org/browse/JRUBY-6860

Example

# encoding: utf-8

("Ã1#" * 15).slice(43, 43)

My environment

jruby 1.7.15 (1.9.3p392) 2014-09-03 82b5cc3 on Java HotSpot(TM) 64-Bit Server VM 1.8.0_05-b13 +jit [darwin-x86_64]
@headius

This comment has been minimized.

Copy link
Member

commented Sep 20, 2014

Appears to still be a problem on master, using a different script:

jruby -e "p ('øøø' * 15).slice(43, 43)"
UTF8Encoding.java:35:in `length': java.lang.ArrayIndexOutOfBoundsException: 90
    from StringSupport.java:90:in `preciseLength'
    from RubyString.java:2277:in `inspect19'
    from RubyString.java:2225:in `inspect19'
    from RubyString$INVOKER$i$0$0$inspect19.gen:-1:in `call'
    from RubyClass.java:615:in `finvoke'
    from Helpers.java:588:in `invoke'
    from RubyBasicObject.java:358:in `callMethod'
    from RubyBasicObject.java:1064:in `rbInspect'
    from RubyKernel.java:480:in `p'
    from RubyKernel$INVOKER$s$0$0$p.gen:-1:in `call'
    from JavaMethod.java:681:in `call'
    from DynamicMethod.java:206:in `call'
    from CachingCallSite.java:326:in `cacheAndCall'
    from CachingCallSite.java:170:in `call'
    from Interpreter.java:307:in `processCall'
    from Interpreter.java:564:in `interpret'
    from Interpreter.java:639:in `INTERPRET_ROOT'
    from IRScriptBody.java:112:in `interpret'
    from Interpreter.java:133:in `execute'
    from Interpreter.java:28:in `execute'
    from IRTranslator.java:43:in `execute'
    from Ruby.java:828:in `runInterpreter'
    from Ruby.java:835:in `runInterpreter'
    from Ruby.java:742:in `runNormally'
    from Ruby.java:553:in `runFromMain'
    from Main.java:404:in `doRunFromMain'
    from Main.java:299:in `internalRun'
    from Main.java:226:in `run'
    from Main.java:199:in `main'

Note that this is the result of slice creating a bogus string. The exception appears to be the same on both master and 1.7.

@headius headius added this to the JRuby 1.7.16 milestone Sep 20, 2014

@headius

This comment has been minimized.

Copy link
Member

commented Sep 25, 2014

enebo added a commit that referenced this issue Sep 25, 2014

@enebo

This comment has been minimized.

Copy link
Member

commented Sep 25, 2014

Something weird with UNSAFE impl. @headius fix had a few small porting errors but even with those fixed the new unsafe code would return too big of a value for length. It did eliminate the crash at least :)

So for now I put a FIXME and deleted the UNSAFE optimization. This is O(n) and not the fastest thing even with UNSAFE.

@enebo enebo closed this Sep 25, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.