Skip to content

java.lang.NullPointerException: unwrapJavaObject at org/jruby/javasupport/JavaUtil.java:287 #4132

@slackfan

Description

@slackfan

Example code:

class IteratorEnumeration
  include Java::JavaUtil::Enumeration
  include Java::JavaUtil::Iterator

  def initialize(aIterator)
    @iterator = aIterator
  end

  def nextElement
    @iterator.next
  end

  alias :next_element nextElement

  def hasMoreElements
    @iterator.hasNext
  end

  def hasNext
    @iterator.hasNext
  end

  alias :has_next hasNext
  alias :has_next? hasNext

  def next
    @iterator.next
  end

  def remove
    @iterator.remove
  end

  alias :has_more_elements hasMoreElements
  alias :has_more_elements? hasMoreElements
end


linkedHashMap = Java::JavaUtil::LinkedHashMap.new
linkedHashMap.put('foo', 'foo')
linkedHashMap.put('bar', 'bar')
linkedHashMap.put('baz', 'baz')
iten = IteratorEnumeration.new(linkedHashMap.keySet.iterator)
puts 'start'
iten.each do |entry|
  puts entry
end
puts 'end'

Behavior in Jruby 9.0.5.0 (jruby 9.0.5.0 (2.2.3) 2016-01-26 7bee00d Java HotSpot(TM) 64-Bit Server VM 25.101-b13 on 1.8.0_101-b13 +jit [Windows 10-amd64])

c:\tools>jruby foo.rb
start
foo
bar
baz
end

Behavior in Jruby 9.1.4.0 (jruby 9.1.4.0 (2.3.1) 2016-09-01 2e1327f Java HotSpot(TM) 64-Bit Server VM 25.101-b13 on 1.8.0_101-b13 +jit [mswin32-x86_64])

c:\tools>jruby foo.rb

start
Unhandled Java exception: java.lang.NullPointerException
java.lang.NullPointerException: null
unwrapJavaObject at org/jruby/javasupport/JavaUtil.java:287
each at org/jruby/javasupport/ext/JavaUtil.java:104
call at org/jruby/javasupport/ext/JavaUtil$Iterator$INVOKER$s$0$0$each.gen:-1
cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:328
callBlock at org/jruby/runtime/callsite/CachingCallSite.java:141
call at org/jruby/runtime/callsite/CachingCallSite.java:145
invokeOther46:each at foo.rb:46

at foo.rb:46
invokeWithArguments at java/lang/invoke/MethodHandle.java:627
load at org/jruby/ir/Compiler.java:111
runScript at org/jruby/Ruby.java:834
runNormally at org/jruby/Ruby.java:749
runNormally at org/jruby/Ruby.java:767
runFromMain at org/jruby/Ruby.java:580
doRunFromMain at org/jruby/Main.java:425
internalRun at org/jruby/Main.java:313
run at org/jruby/Main.java:242
main at org/jruby/Main.java:204

Expected behavior is that Jruby 9.1.4.0 behaves as 9.0.5.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions