NullPointerException while trying to pass closure

I am getting this exception:

each_table_path: s3bucket=bucket, domain=alpha
Exception in thread “main” java.lang.NullPointerException
at
org.jruby.javasupport.util.RuntimeHelpers.processBlockArgument(RuntimeHelpers.java:440)
at ruby.tmp.test_2.method__2$RUBY$each_subdir(/tmp/test_2.rb)
at
ruby.tmp.test_2Invokermethod__2$RUBY$each_subdirFixed3.call(Unknown
Source)
at
org.jruby.runtime.CallSite$InlineCachingCallSite.cacheAndCall(CallSite.java:235)
at
org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:414)
at
ruby.tmp.test_2.method__3$RUBY$each_table_path(/tmp/test_2.rb:28)
at
ruby.tmp.test_2Invokermethod__3$RUBY$each_table_pathFixed3.call(Unknown
Source)
at
org.jruby.runtime.CallSite$InlineCachingCallSite.cacheAndCall(CallSite.java:235)
at
org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:414)
at ruby.tmp.test_2.file(/tmp/test_2.rb:38)
at ruby.tmp.test_2.file(/tmp/test_2.rb)
at ruby.tmp.test_2.load(/tmp/test_2.rb)
at org.jruby.Ruby.runScript(Ruby.java:512)
at org.jruby.Ruby.runNormally(Ruby.java:432)
at org.jruby.Ruby.runFromMain(Ruby.java:312)
at org.jruby.Main.run(Main.java:144)
at org.jruby.Main.run(Main.java:89)
at org.jruby.Main.main(Main.java:80)

With the following code (The actual code was reduced to the smallest
reproducable chunk):

require ‘java’

def iterator_each(iterator)
puts “iterator_each: #{iterator}”
while iterator.has_next
yield(iterator.next)
end
end

def each_entry(s3, s3bucket, path, &block)
data = java.util.ArrayList.new
data.add “#{path}/one_f”
data.add “#{path}/two_f”
iterator_each(data.iterator, &block)
end

def each_subdir(s3, s3bucket, path, &block)
$stderr.puts “each_subdir: s3bucket=#{s3bucket}, path=#{path}”
data = java.util.ArrayList.new
data.add “#{path}/one_d”
data.add “#{path}/two_d”
iterator_each(data.iterator, &block)
end

def each_table_path(s3, s3bucket, domain)
$stderr.puts “each_table_path: s3bucket=#{s3bucket}, domain=#{domain}”
each_subdir(s3, s3bucket, “#{domain}/”) do |db_path|
$stderr.puts(“db_path -> #{db_path}”)
each_subdir(s3, s3bucket, db_path) do |node_path|
each_subdir(s3, s3bucket, node_path) do |table_path|
yield(table_path)
end
end
end
end

each_table_path(nil, “bucket”, “alpha”) { puts “here” }

I don’t see anything wrong with my code. Could this be a bug? I am
using ruby 1.8.6 (2008-06-29 rev 0000) [i386-jruby1.1.2].

If I change this:

def each_subdir(s3, s3bucket, path, &block)
$stderr.puts “each_subdir: s3bucket=#{s3bucket}, path=#{path}”
data = java.util.ArrayList.new
data.add “#{path}/one_d”
data.add “#{path}/two_d”
iterator_each(data.iterator, &block)
end

to this:

def each_subdir(s3, s3bucket, path)
$stderr.puts “each_subdir: s3bucket=#{s3bucket}, path=#{path}”
data = java.util.ArrayList.new
data.add “#{path}/one_d”
data.add “#{path}/two_d”
iterator_each(data.iterator) { |*args| yield(*args) }
end

Then my code works.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Hi Bryan,

Thanks for the report. The problem has been fixed and the fix will
apper in the (soon-to-be-realeased) JRuby 1.1.3.

I encourage you to try out the lastest trunk version to make sure this
is indeed fixed.

Thanks,
–Vladimir

On Tue, Jul 15, 2008 at 10:08 PM, Bryan Castillo
[email protected] wrote:

   at ruby.tmp.test_2.method__3$RUBY$each_table_path(/tmp/test_2.rb:28)
   at org.jruby.Main.run(Main.java:144)

data.add “#{path}/two_f”

end

iterator_each(data.iterator) { |*args| yield(*args) }


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Tue, Jul 15, 2008 at 1:10 PM, Vladimir S. [email protected]
wrote:

Hi Bryan,

Thanks for the report. The problem has been fixed and the fix will
apper in the (soon-to-be-realeased) JRuby 1.1.3.

I encourage you to try out the lastest trunk version to make sure this
is indeed fixed.

The latest trunk does not have this error.

Thanks.

   at org.jruby.javasupport.util.RuntimeHelpers.processBlockArgument(RuntimeHelpers.java:440)
   at ruby.tmp.test_2.__file__(/tmp/test_2.rb:38)

end
$stderr.puts “each_subdir: s3bucket=#{s3bucket}, path=#{path}”
each_subdir(s3, s3bucket, db_path) do |node_path|

$stderr.puts “each_subdir: s3bucket=#{s3bucket}, path=#{path}”

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email