% jirb
irb(main):002:0> require 'rubygems'
=> true
irb(main):003:0> require 'zip/zip'
=> true
irb(main):004:0> Zip::ZipFile.open('path/to/file.zip')
TypeError: can't dup NilClass
from /opt/jruby-1.0/lib/ruby/gems/1.8/gems/rubyzip-0.9.1/lib/zip/zip.rb:1369:in `map'
from /opt/jruby-1.0/lib/ruby/gems/1.8/gems/rubyzip-0.9.1/lib/zip/zip.rb:1132:in `dup'
from /opt/jruby-1.0/lib/ruby/gems/1.8/gems/rubyzip-0.9.1/lib/zip/zip.rb:1369:in `initialize'
from /opt/jruby-1.0/lib/ruby/gems/1.8/gems/rubyzip-0.9.1/lib/zip/zip.rb:1379:in `new'
from /opt/jruby-1.0/lib/ruby/gems/1.8/gems/rubyzip-0.9.1/lib/zip/zip.rb:1379:in `open'
from (irb):4:in `binding'
from /opt/jruby-1.0/lib/ruby/1.8/irb.rb:150:in `eval_input'
from /opt/jruby-1.0/lib/ruby/1.8/irb.rb:70:in `signal_status'
from /opt/jruby-1.0/lib/ruby/1.8/irb.rb:189:in `eval_input'
from /opt/jruby-1.0/lib/ruby/1.8/irb.rb:70:in `each_top_level_statement'
from /opt/jruby-1.0/lib/ruby/1.8/irb.rb:190:in `loop'
from /opt/jruby-1.0/lib/ruby/1.8/irb.rb:190:in `catch'
from /opt/jruby-1.0/lib/ruby/1.8/irb.rb:190:in `eval_input'
from /opt/jruby-1.0/lib/ruby/1.8/irb.rb:70:in `start'
from :-1:in `catch'
from /opt/jruby-1.0/lib/ruby/1.8/irb.rb:71:in `start'
from :-1irb(main):005:0>
It seems that the rubyzip code is failing to successfully read the zip file, but it does not realize and results in the error. This exact same sequence works fine with native irb.
Basically, need to add the following line to RubyIO:
if (len == 0) return RubyString.newString(getRuntime(),"");
The problem was that when reading an entry, the zip.rb code goes through the following code:
@comment = io.read(commentLength)
unless (@comment && @comment.length == commentLength)
raise ZipError, "Truncated cdir zip entry header"
end
which looks pretty innocent, but commentLength was 0, thus the code in JRuby was returning null instead of an empty string.
The following code of zip was then raising an exception, this resulting in a null entry, which could not be duplicated, thus the following exception:
/zip.rb:1390:in `map': can't dup NilClass (TypeError)
from /Users/niko/tools/gems/gems/rubyzip-0.9.1/lib/zip/zip.rb:1148:in `dup'
from /Users/niko/tools/gems/gems/rubyzip-0.9.1/lib/zip/zip.rb:1390:in `initialize'
from /Users/niko/tools/gems/gems/rubyzip-0.9.1/lib/zip/zip.rb:1401:in `new'
from /Users/niko/tools/gems/gems/rubyzip-0.9.1/lib/zip/zip.rb:1401:in `open'
from :1
The patch is also including the path for (since it hasn't been committed in the trunk yet):
http://jira.codehaus.org/browse/JRUBY-1108