joni icon indicating copy to clipboard operation
joni copied to clipboard

ArrayIndexOutOfBoundsException for grapheme_clusters

Open eregon opened this issue 7 years ago • 2 comments

Not sure if I should report this here or to JRuby but the error seems to come from joni:

$ bin/jruby -e 'p [0xA4].pack("C").force_encoding("UTF-8").grapheme_clusters'
Unhandled Java exception: java.lang.ArrayIndexOutOfBoundsException: -1
java.lang.ArrayIndexOutOfBoundsException: -1
                          length at org/jcodings/specific/UTF8Encoding.java:30
                       isMbcHead at org/jcodings/Encoding.java:497
                      opCClassMB at org/joni/ByteCodeMachine.java:793
                         execute at org/joni/ByteCodeMachine.java:203
                         matchAt at org/joni/ByteCodeMachine.java:167
                     matchCommon at org/joni/Matcher.java:115
                           match at org/joni/Matcher.java:92
       enumerateGraphemeClusters at org/jruby/RubyString.java:5859
               grapheme_clusters at org/jruby/RubyString.java:5872
                            call at org/jruby/RubyString$INVOKER$i$0$0$grapheme_clusters.gen:-1
                            call at org/jruby/internal/runtime/methods/JavaMethod.java:309
                    cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:323
                            call at org/jruby/runtime/callsite/CachingCallSite.java:139
  invokeOther5:grapheme_clusters at -e:1
                          <main> at -e:1
             invokeWithArguments at java/lang/invoke/MethodHandle.java:627
                            load at org/jruby/ir/Compiler.java:94
                       runScript at org/jruby/Ruby.java:852
                     runNormally at org/jruby/Ruby.java:771
                     runNormally at org/jruby/Ruby.java:789
                     runFromMain at org/jruby/Ruby.java:601
                   doRunFromMain at org/jruby/Main.java:415
                     internalRun at org/jruby/Main.java:307
                             run at org/jruby/Main.java:234
                            main at org/jruby/Main.java:206

The new spec spec/ruby/core/string/shared/grapheme_clusters.rb added in https://github.com/jruby/jruby/pull/5385 fails due to this.

eregon avatar Oct 27 '18 13:10 eregon

Tags added in https://github.com/jruby/jruby/pull/5385/commits/e08e97ead41afcf3104ae555c0c756c185c961c2 and should be removed when this is fixed.

eregon avatar Oct 27 '18 13:10 eregon

this is related to https://github.com/jruby/jcodings/issues/25, until we'll have unsave and approximate length routines, we will be plagued by such cases.

lopex avatar Oct 27 '18 14:10 lopex