Buggy code:
static int codeRangeAnd ( int cr1 , int cr2 ) { } private void copyCodeRangeForSubstr ( RubyString from , Encoding enc ) { } private void copyCodeRange ( RubyString from ) { } final int scanForCodeRange ( ) { } final boolean singleByteOptimizable ( ) { } final boolean singleByteOptimizable ( Encoding enc ) { } private Encoding isCompatibleWith ( RubyString other ) { } final Encoding isCompatibleWith ( EncodingCapable other ) { } final Encoding checkEncoding ( RubyString other ) { } final Encoding checkEncoding ( EncodingCapable other ) { } private Encoding checkDummyEncoding ( ) { } private boolean isComparableWith ( RubyString other ) { } private boolean isComparableViaCodeRangeWith ( RubyString other ) { } private int strLength ( Encoding enc ) { } final int strLength ( ) { } private int strLength ( ByteList bytes ) { } private int strLength ( ByteList bytes , Encoding enc ) { } final int subLength ( int pos ) { } @ Override public final boolean eql ( IRubyObject other ) { } private boolean eql18 ( Ruby runtime , IRubyObject other ) { } private boolean eql19 ( Ruby runtime , IRubyObject other ) { } public RubyString ( Ruby runtime , RubyClass rubyClass ) { } public RubyString ( Ruby runtime , RubyClass rubyClass , CharSequence value ) { } public RubyString ( Ruby runtime , RubyClass rubyClass , byte [ ] value ) { } public RubyString ( Ruby runtime , RubyClass rubyClass , ByteList value ) { } public RubyString ( Ruby runtime , RubyClass rubyClass , ByteList value , boolean objectSpace ) { } public RubyString ( Ruby runtime , RubyClass rubyClass , ByteList value , Encoding encoding , boolean objectSpace ) { } protected RubyString ( Ruby runtime , RubyClass rubyClass , ByteList value , Encoding enc , int cr ) { } protected RubyString ( Ruby runtime , RubyClass rubyClass , ByteList value , Encoding enc ) { } protected RubyString ( Ruby runtime , RubyClass rubyClass , ByteList value , int cr ) { } @ Deprecated public RubyString newString ( CharSequence s ) { } @ Deprecated public RubyString newString ( ByteList s ) { } @ Deprecated public static RubyString newString ( Ruby runtime , RubyClass clazz , CharSequence str ) { } public static RubyString newStringLight ( Ruby runtime , ByteList bytes ) { } public static RubyString newStringLight ( Ruby runtime , int size ) { } public static RubyString newStringLight ( Ruby runtime , int size , Encoding encoding ) { } public static RubyString newString ( Ruby runtime , CharSequence str ) { } public static RubyString newString ( Ruby runtime , String str ) { } public static RubyString newString ( Ruby runtime , byte [ ] bytes ) { } public static RubyString newString ( Ruby runtime , byte [ ] bytes , int start , int length ) { } public static RubyString newString ( Ruby runtime , ByteList bytes ) { } public static RubyString newString ( Ruby runtime , ByteList bytes , Encoding encoding ) { } public static RubyString newUnicodeString ( Ruby runtime , String str ) { } public static RubyString newUnicodeString ( Ruby runtime , CharSequence str ) { } public static RubyString newInternalFromJavaExternal ( Ruby runtime , String str ) { Encoding internal = runtime . getDefaultInternalEncoding ( ) ; Charset rubyInt = null ; if ( ( internal != null ) && ( ( internal . getCharset ( ) ) != null ) ) rubyInt = internal . getCharset ( ) ; Charset javaExt = Charset . defaultCharset ( ) ; Encoding javaExtEncoding = runtime . getEncodingService ( ) . getJavaDefault ( ) ; if ( rubyInt == null ) { return RubyString . newString ( runtime , new ByteList ( str . getBytes ( ) , javaExtEncoding ) ) ; } else { <START_BUG> return RubyString . newString ( runtime , new ByteList ( str . getBytes ( rubyInt ) , internal ) ) ; <END_BUG> } } public static RubyString newStringShared ( Ruby runtime , RubyString orig ) { } public static RubyString newStringShared ( Ruby runtime , ByteList bytes ) { } public static RubyString newStringShared ( Ruby runtime , ByteList bytes , Encoding encoding ) { } public static RubyString newStringShared ( Ruby runtime , ByteList bytes , int codeRange ) { } public static RubyString newStringShared ( Ruby runtime , RubyClass clazz , ByteList bytes ) { } public static RubyString newStringShared ( Ruby runtime , RubyClass clazz , ByteList bytes , Encoding encoding ) { } public static RubyString newStringShared ( Ruby runtime , byte [ ] bytes ) { } public static RubyString newStringShared ( Ruby runtime , byte [ ] bytes , int start , int length ) { } public static RubyString newEmptyString ( Ruby runtime ) { } public static RubyString newEmptyString ( Ruby runtime , RubyClass metaClass ) { } public static RubyString newStringNoCopy ( Ruby runtime , ByteList bytes ) { } public static RubyString newStringNoCopy ( Ruby runtime , RubyClass clazz , ByteList bytes ) { } public static RubyString newStringNoCopy ( Ruby runtime , byte [ ] bytes , int start , int length ) { } public static RubyString newStringNoCopy ( Ruby runtime , byte [ ] bytes ) { } private static final class EmptyByteListHolder { final ByteList bytes ; final int cr ; EmptyByteListHolder ( Encoding enc ) { } } private static RubyString . EmptyByteListHolder [ ] EMPTY_BYTELISTS = new RubyString . EmptyByteListHolder [ 4 ] ; static RubyString . EmptyByteListHolder getEmptyByteList ( Encoding enc ) { } private static RubyString . EmptyByteListHolder prepareEmptyByteList ( Encoding enc ) { } public static RubyString newEmptyString ( Ruby runtime , RubyClass metaClass , Encoding enc ) { } public static RubyString newEmptyString ( Ruby runtime , Encoding enc ) { }

Fix:
return RubyString . newString ( runtime , new ByteList ( RubyEncoding . encode ( str , rubyInt ) , internal ) ) ;