JRuby (please use github issues at http://bugs.jruby.org)
  1. JRuby (please use github issues at http://bugs.jruby.org)
  2. JRUBY-5960

Something in rails causes File#each to throw InvalidByteSequenceError in 1.9 mode

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.6.3
    • Fix Version/s: JRuby 1.6.4
    • Component/s: None
    • Labels:
      None
    • Testcase included:
      yes
    • Number of attachments :
      0

      Description

      I'm not sure how to track this down, but something in rails is causing File#each in Jruby 1.9 mode to throw an exception when reading certain files (like jpegs). This means you can't really use send_file in a rails app on 1.9 jruby.

      For now here's a git repo that illustrates the problem. The rails apps contain nothing but the base generated code plus lib/task/read.rake which is the same as the Rakefile in the root that works fine.

      It doesn't seem to be KCODE related since KCODE was "NONE" in all my test cases.

      Have a look at https://github.com/matschaffer/jruby-encoding-testcase and run ./runtests.sh with jruby in your PATH to see the effects.

        Activity

        Hide
        Mat Schaffer added a comment - - edited

        I could understand calling this a rails bug. But for now the error has so little information that I'm hoping you folks have some thoughts about how to track it down.

        Oh and here's the output:

        === Each from plain ruby file
        === Each from plain Rake file
        ** Invoke read (first_time)
        ** Execute read
        === Each from rails 3.0.9 Rake file
        ** Invoke read (first_time)
        ** Execute read
        Error class: Encoding::InvalidByteSequenceError
        rake aborted!
        
        org/jruby/RubyIO.java:3137:in `each'
        /Users/mat/code/jrubytest/rails309/lib/tasks/read.rake:3:in `(root)'
        org/jruby/RubyProc.java:256:in `call'
        /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/task.rb:205:in `execute'
        org/jruby/RubyArray.java:1603:in `each'
        /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
        /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/task.rb:158:in `invoke_with_call_chain'
        /Users/mat/.rvm/rubies/jruby-1.6.3/lib/ruby/1.9/monitor.rb:201:in `mon_synchronize'
        /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
        /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
        /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_task'
        /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:90:in `top_level'
        org/jruby/RubyArray.java:1603:in `each'
        /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:90:in `top_level'
        /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
        /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level'
        /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:62:in `run'
        /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
        /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
        /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/bin/rake:32:in `(root)'
        org/jruby/RubyKernel.java:1073:in `load'
        /Users/mat/.rvm/rubies/jruby-1.6.3/bin/rake:19:in `(root)'
        Tasks: TOP => read
        /Users/mat/code/jrubytest
        === Each from rails 3.1.0rc5 Rake file
        ** Invoke read (first_time)
        ** Execute read
        Error class: Encoding::InvalidByteSequenceError
        rake aborted!
        
        org/jruby/RubyIO.java:3137:in `each'
        /Users/mat/code/jrubytest/rails310rc5/lib/tasks/read.rake:3:in `(root)'
        org/jruby/RubyProc.java:256:in `call'
        /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/task.rb:205:in `execute'
        org/jruby/RubyArray.java:1603:in `each'
        /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
        /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/task.rb:158:in `invoke_with_call_chain'
        /Users/mat/.rvm/rubies/jruby-1.6.3/lib/ruby/1.9/monitor.rb:201:in `mon_synchronize'
        /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
        /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
        /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_task'
        /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:90:in `top_level'
        org/jruby/RubyArray.java:1603:in `each'
        /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:90:in `top_level'
        /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
        /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level'
        /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:62:in `run'
        /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
        /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
        /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/bin/rake:32:in `(root)'
        org/jruby/RubyKernel.java:1073:in `load'
        /Users/mat/.rvm/rubies/jruby-1.6.3/bin/rake:19:in `(root)'
        Tasks: TOP => read
        /Users/mat/code/jrubytest
        
        Show
        Mat Schaffer added a comment - - edited I could understand calling this a rails bug. But for now the error has so little information that I'm hoping you folks have some thoughts about how to track it down. Oh and here's the output: === Each from plain ruby file === Each from plain Rake file ** Invoke read (first_time) ** Execute read === Each from rails 3.0.9 Rake file ** Invoke read (first_time) ** Execute read Error class: Encoding::InvalidByteSequenceError rake aborted! org/jruby/RubyIO.java:3137:in `each' /Users/mat/code/jrubytest/rails309/lib/tasks/read.rake:3:in `(root)' org/jruby/RubyProc.java:256:in `call' /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/task.rb:205:in `execute' org/jruby/RubyArray.java:1603:in `each' /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute' /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/task.rb:158:in `invoke_with_call_chain' /Users/mat/.rvm/rubies/jruby-1.6.3/lib/ruby/1.9/monitor.rb:201:in `mon_synchronize' /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain' /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke' /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_task' /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:90:in `top_level' org/jruby/RubyArray.java:1603:in `each' /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:90:in `top_level' /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling' /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level' /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:62:in `run' /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling' /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:59:in `run' /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/bin/rake:32:in `(root)' org/jruby/RubyKernel.java:1073:in `load' /Users/mat/.rvm/rubies/jruby-1.6.3/bin/rake:19:in `(root)' Tasks: TOP => read /Users/mat/code/jrubytest === Each from rails 3.1.0rc5 Rake file ** Invoke read (first_time) ** Execute read Error class: Encoding::InvalidByteSequenceError rake aborted! org/jruby/RubyIO.java:3137:in `each' /Users/mat/code/jrubytest/rails310rc5/lib/tasks/read.rake:3:in `(root)' org/jruby/RubyProc.java:256:in `call' /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/task.rb:205:in `execute' org/jruby/RubyArray.java:1603:in `each' /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute' /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/task.rb:158:in `invoke_with_call_chain' /Users/mat/.rvm/rubies/jruby-1.6.3/lib/ruby/1.9/monitor.rb:201:in `mon_synchronize' /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain' /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke' /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_task' /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:90:in `top_level' org/jruby/RubyArray.java:1603:in `each' /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:90:in `top_level' /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling' /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level' /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:62:in `run' /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling' /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:59:in `run' /Users/mat/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/bin/rake:32:in `(root)' org/jruby/RubyKernel.java:1073:in `load' /Users/mat/.rvm/rubies/jruby-1.6.3/bin/rake:19:in `(root)' Tasks: TOP => read /Users/mat/code/jrubytest
        Hide
        Charles Oliver Nutter added a comment -

        Simple fixes are the best fixes! It appears 1.9 sets external_encoding on the IO to ASCII8BIT when you specify binary. I added that logic, and your case runs to completion now.

        Pushed to jruby-1_6 in a20c652 and master in e4b8742. RubySpec pushed in 7cf0aae.

        Show
        Charles Oliver Nutter added a comment - Simple fixes are the best fixes! It appears 1.9 sets external_encoding on the IO to ASCII8BIT when you specify binary. I added that logic, and your case runs to completion now. Pushed to jruby-1_6 in a20c652 and master in e4b8742. RubySpec pushed in 7cf0aae.
        Hide
        Mat Schaffer added a comment -

        Awesome! Confirmed using jruby-head via rvm. Thanks for the fix. Looking forward to 1.6.4

        Show
        Mat Schaffer added a comment - Awesome! Confirmed using jruby-head via rvm. Thanks for the fix. Looking forward to 1.6.4

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Mat Schaffer
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: