Buggy code:
public class PsychParser extends RubyObject { private static final Logger LOG = LoggerFactory . getLogger ( "PsychParser" ) ; public static final int YAML_ANY_ENCODING = 0 ; public static final int YAML_UTF8_ENCODING = INSTANCE . getIndex ( ) ; public static final int YAML_UTF16LE_ENCODING = UTF16LEEncoding . INSTANCE . getIndex ( ) ; public static final int YAML_UTF16BE_ENCODING = UTF16BEEncoding . INSTANCE . getIndex ( ) ; public static void initPsychParser ( Ruby runtime , RubyModule psych ) { } public PsychParser ( Ruby runtime , RubyClass klass ) { } @ JRubyMethod public IRubyObject parse ( ThreadContext context , IRubyObject target ) { Ruby runtime = context . runtime ; boolean tainted = target . isTaint ( ) ; StreamReader reader ; if ( target . respondsTo ( "read" ) ) { <START_BUG> reader = new StreamReader ( new InputStreamReader ( new org . jruby . util . IOInputStream ( target ) ) ) ; <END_BUG> if ( target instanceof RubyIO ) { tainted = true ; } } else { reader = new StreamReader ( new StringReader ( target . convertToString ( ) . asJavaString ( ) ) ) ; } parser = new org . yaml . snakeyaml . parser . ParserImpl ( reader ) ; IRubyObject handler = getInstanceVariable ( "@handler" ) ; while ( true ) { try { event = parser . getEvent ( ) ; if ( event . is ( StreamStart ) ) { invoke ( context , handler , "start_stream" , runtime . newFixnum ( PsychParser . YAML_ANY_ENCODING ) ) ; } else if ( event . is ( DocumentStart ) ) { DocumentStartEvent dse = ( ( DocumentStartEvent ) ( event ) ) ; Integer [ ] versionInts = dse . getVersion ( ) ; IRubyObject version = ( versionInts == null ) ? runtime . getNil ( ) : RubyArray . newArray ( runtime , runtime . newFixnum ( versionInts [ 0 ] ) , runtime . newFixnum ( versionInts [ 1 ] ) ) ; Map < String , String > tagsMap = dse . getTags ( ) ; RubyArray tags = RubyArray . newArray ( runtime ) ; if ( ( tags . size ( ) ) > 0 ) { for ( Map . Entry < String , String > tag : tagsMap . entrySet ( ) ) { RubyString key = RubyString . newString ( runtime , tag . getKey ( ) ) ; RubyString value = RubyString . newString ( runtime , tag . getValue ( ) ) ; key . setTaint ( tainted ) ; value . setTaint ( tainted ) ; tags . append ( RubyArray . newArray ( runtime , key , value ) ) ; } } invoke ( context , handler , "start_document" , version , tags , runtime . newBoolean ( ( ! ( dse . getExplicit ( ) ) ) ) ) ; } else if ( event . is ( DocumentEnd ) ) { DocumentEndEvent dee = ( ( DocumentEndEvent ) ( event ) ) ; invoke ( context , handler , "end_document" , runtime . newBoolean ( ( ! ( dee . getExplicit ( ) ) ) ) ) ; } else if ( event . is ( Alias ) ) { AliasEvent ae = ( ( AliasEvent ) ( event ) ) ; IRubyObject alias = runtime . getNil ( ) ; if ( ( ae . getAnchor ( ) ) != null ) { alias = RubyString . newString ( runtime , ae . getAnchor ( ) ) ; alias . setTaint ( tainted ) ; } invoke ( context , handler , "alias" , alias ) ; } else if ( event . is ( Scalar ) ) { ScalarEvent se = ( ( ScalarEvent ) ( event ) ) ; IRubyObject anchor = ( ( se . getAnchor ( ) ) == null ) ? runtime . getNil ( ) : RubyString . newString ( runtime , se . getAnchor ( ) ) ; IRubyObject tag = ( ( se . getTag ( ) ) == null ) ? runtime . getNil ( ) : RubyString . newString ( runtime , se . getTag ( ) ) ; IRubyObject plain_implicit = runtime . newBoolean ( se . getImplicit ( ) . canOmitTagInPlainScalar ( ) ) ; IRubyObject quoted_implicit = runtime . newBoolean ( se . getImplicit ( ) . canOmitTagInNonPlainScalar ( ) ) ; IRubyObject style = runtime . newFixnum ( PsychParser . translateStyle ( se . getStyle ( ) ) ) ; IRubyObject val = RubyString . newString ( runtime , se . getValue ( ) ) ; val . setTaint ( tainted ) ; anchor . setTaint ( tainted ) ; tag . setTaint ( tainted ) ; invoke ( context , handler , "scalar" , val , anchor , tag , plain_implicit , quoted_implicit , style ) ; } else if ( event . is ( SequenceStart ) ) { SequenceStartEvent sse = ( ( SequenceStartEvent ) ( event ) ) ; IRubyObject anchor = ( ( sse . getAnchor ( ) ) == null ) ? runtime . getNil ( ) : RubyString . newString ( runtime , sse . getAnchor ( ) ) ; IRubyObject tag = ( ( sse . getTag ( ) ) == null ) ? runtime . getNil ( ) : RubyString . newString ( runtime , sse . getTag ( ) ) ; IRubyObject implicit = runtime . newBoolean ( sse . getImplicit ( ) ) ; IRubyObject style = runtime . newFixnum ( PsychParser . translateFlowStyle ( sse . getFlowStyle ( ) ) ) ; anchor . setTaint ( tainted ) ; tag . setTaint ( tainted ) ; invoke ( context , handler , "start_sequence" , anchor , tag , implicit , style ) ; } else if ( event . is ( SequenceEnd ) ) { invoke ( context , handler , "end_sequence" ) ; }

Fix:
reader = new StreamReader ( new InputStreamReader ( new org . jruby . util . IOInputStream ( target ) , RubyEncoding . UTF8 ) ) ;