Error with jruby 1.6.1 and net/http in 1.9 mode

I am running jruby 1.6.1 in ruby 1.9 mode and when i run this code:

require ‘active_resource’

class EmailAccount < ActiveResource::Base
self.site=“http://localhost:3000
end
EmailAccount.find(23)

I get:

ArgumentError: wrong number of arguments (2 for 1)
from
/home/ubuntu/.rvm/rubies/jruby-1.6.1/lib/ruby/1.9/net/http.rb:886:in
get' from /home/ubuntu/.rvm/rubies/jruby-1.6.1/lib/ruby/1.9/net/http.rb:1186:in transport_request’
from
/home/ubuntu/.rvm/rubies/jruby-1.6.1/lib/ruby/1.9/net/http.rb:2334:in
reading_body' from /home/ubuntu/.rvm/rubies/jruby-1.6.1/lib/ruby/1.9/net/http.rb:1185:in transport_request’
from
/home/ubuntu/.rvm/rubies/jruby-1.6.1/lib/ruby/1.9/net/http.rb:1169:in
request' from /home/ubuntu/.rvm/rubies/jruby-1.6.1/lib/ruby/1.9/net/http.rb:1162:in request’
from
/home/ubuntu/.rvm/rubies/jruby-1.6.1/lib/ruby/1.9/net/http.rb:627:in
start' from /home/ubuntu/.rvm/rubies/jruby-1.6.1/lib/ruby/1.9/net/http.rb:1160:in request’
from
/home/ubuntu/.rvm/rubies/jruby-1.6.1/lib/ruby/1.9/net/http.rb:880:in
get' from org/jruby/RubyBasicObject.java:1679:in send
from org/jruby/RubyKernel.java:2081:in send' from /home/ubuntu/.rvm/gems/jruby-1.6.1/gems/activeresource-2.3.9/lib/active_resource/connection.rb:171:in request’
from
/home/ubuntu/.rvm/gems/jruby-1.6.1/gems/activesupport-2.3.9/lib/active_support/core_ext/benchmark.rb:17:in
ms' from /home/ubuntu/.rvm/rubies/jruby-1.6.1/lib/ruby/1.9/benchmark.rb:309:in realtime’
from
/home/ubuntu/.rvm/gems/jruby-1.6.1/gems/activesupport-2.3.9/lib/active_support/core_ext/benchmark.rb:17:in
ms' from /home/ubuntu/.rvm/gems/jruby-1.6.1/gems/activeresource-2.3.9/lib/active_resource/connection.rb:171:in request’
from
/home/ubuntu/.rvm/gems/jruby-1.6.1/gems/activeresource-2.3.9/lib/active_resource/connection.rb:138:in
get' from /home/ubuntu/.rvm/gems/jruby-1.6.1/gems/activeresource-2.3.9/lib/active_resource/base.rb:661:in find_single’
from
/home/ubuntu/.rvm/gems/jruby-1.6.1/gems/activeresource-2.3.9/lib/active_resource/base.rb:589:in
find' from (irb):6:in evaluate’
from org/jruby/RubyKernel.java:1093:in eval' from org/jruby/RubyKernel.java:1418:in loop’
from org/jruby/RubyKernel.java:1205:in catch' from org/jruby/RubyKernel.java:1205:in catch’
from /home/ubuntu/.rvm/rubies/jruby-1.6.1/bin/irb:18:in
`(root)'jruby-1.6.1 >

The above does not happen if i run in jruby 1.8.7 mode.

I am using:

2.6.32-305-ec2 #9-Ubuntu
java version “1.6.0_18”
OpenJDK Runtime Environment (IcedTea6 1.8.1) (6b18-1.8.1-0ubuntu1)
OpenJDK 64-Bit Server VM (build 16.0-b13, mixed mode)

Thx

-karl

Ok, i had a stab at looking into the problem myself this morning and I
learned a few things. It looks like the problem is the extra encoding
arg to the ZLIB::GzipReader constructor.

request(Get.new(path, initheader)) {|r|
if r.key?(“content-encoding”) and @compression
@compression = nil # Clear it till next set.
the_body = r.read_body dest, &block
case r[“content-encoding”]
when “gzip”
r.body= Zlib::GzipReader.new(StringIO.new(the_body),
encoding: “ASCII-8BIT”).read
r.delete(“content-encoding”)
when “deflate”
r.body= Zlib::Inflate.inflate(the_body);

If i change it to this:

request(Get.new(path, initheader)) {|r|
if r.key?(“content-encoding”) and @compression
@compression = nil # Clear it till next set.
the_body = r.read_body dest, &block
case r[“content-encoding”]
when “gzip”
r.body= Zlib::GzipReader.new(StringIO.new(the_body)).read
r.delete(“content-encoding”)
when “deflate”
r.body= Zlib::Inflate.inflate(the_body);
r.delete(“content-encoding”)
when “identity”

Then things seem to be ok. Coincidentally, my change matches with the
MRI ruby 1.9.2 http.rb file.

Thx

So Karl, do you think this is still a JRuby compatibility issue with
1.9 net/http? I couldn’t quite tell from your followup. If so, please
file this as a bug at http://bugs.jruby.org.

Thanks,
/Nick

Hi Hiroshi. Nick said i should put in a ticket. Should i still do
this?

Thx!

Hi,

On Fri, May 6, 2011 at 23:58, Nick S. [email protected] wrote:

So Karl, do you think this is still a JRuby compatibility issue with
1.9 net/http? I couldn’t quite tell from your followup. If so, please
file this as a bug at http://bugs.jruby.org.

Yeah, good catch. We’ve not yet implemented optional hash arg for
GzipReader…

% echo foo | gzip -c | ruby -rzlib -ve ‘Zlib::GzipReader.new(ARGF, {})’
ruby 1.9.2p188 (2011-03-28 revision 31204) [x86_64-linux]
% echo foo | gzip -c | jruby --1.9 -rzlib -ve
‘Zlib::GzipReader.new(ARGF, {})’
jruby 1.6.1 (ruby-1.9.2-p136) (2011-05-04 4705f9e) (OpenJDK 64-Bit
Server VM 1.6.0_22) [linux-amd64-java]
ArgumentError: wrong number of arguments (2 for 1)
(root) at -e:1
%

Regards,
// NaHi

Hi,

On Sat, May 7, 2011 at 00:59, Karl B. [email protected] wrote:

Hi Hiroshi. Nick said i should put in a ticket. Should i still do this?

Sorry for confusing you. Please do so. It would not be a simple
monkey-patch thing so we should track the progress of fix.

Regards,
// NaHi

http://jira.codehaus.org/browse/JRUBY-5778

Thx!