The following example should simply clear bad bytes during encode. Instead, it tries to call [] on the empty string, thinking that it is a function to handle the error.
$ jruby -e 'p "foo\xFF".force_encoding("ASCII-8BIT").encode("US-ASCII", replace: "")'
NoMethodError: undefined method '[]' for nil
encode at org/jruby/RubyString.java:6844
<main> at -e:1
We clearly aren't handling the :replace option right here.