New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
slackfan opened this Issue Sep 2, 2016 · 4 comments

Comments

Projects
None yet
2 participants
@slackfan

slackfan commented Sep 2, 2016

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

@kares

This comment has been minimized.

Show comment
Hide comment
@kares

kares Sep 2, 2016

Member

hey @slackfan, JRuby's Java integration part did receive a "rewrite" in 9.1 so that is now faster and more complete. seems like you found us a first regression. we will look into fixing this one. thanks.

Member

kares commented Sep 2, 2016

hey @slackfan, JRuby's Java integration part did receive a "rewrite" in 9.1 so that is now faster and more complete. seems like you found us a first regression. we will look into fixing this one. thanks.

@kares

This comment has been minimized.

Show comment
Hide comment
@kares

kares Sep 2, 2016

Member

... works in 9.0.5.0 and breaks in 9.1.2.0 so its definitely a 9.1 regression caused by the JI updates!

Member

kares commented Sep 2, 2016

... works in 9.0.5.0 and breaks in 9.1.2.0 so its definitely a 9.1 regression caused by the JI updates!

kares added a commit to kares/jruby that referenced this issue Sep 2, 2016

[ji] regression not handling Ruby types implementing 'ext' interfaces
... by moving .rb extensions to core Java types over from Ruby (in 9.1) and assuming they will be  called on Java objects Ruby extensions do not work

e.g. a pure Ruby "included" java.lang.Iterable fails to keep its Ruby Enumerable nature working. 

this only concerns enhanced interfaces and happens only if those enhanced methods are being re-used (from Ruby)

reported as #4132

@kares kares added this to the JRuby 9.1.5.0 milestone Sep 2, 2016

@kares

This comment has been minimized.

Show comment
Hide comment
@kares

kares Sep 2, 2016

Member

this is really unfortunate, but you might have to wait for 9.1.5.0 until its smoothed out.
when including "enhanced" interfaces (such as java.lang.Iterable, java.util.{Collection,List,Iterator,Enumeration}) in Ruby enhancements (such as the added Enumerable#each nature) will fail.

you can add the following patch as a temporary work-around (make sure its loaded before your part) :

module Java::java::util::Iterator
  def each
    while self.hasNext
      yield self.next
    end
  end
end if JRUBY_VERSION < '9.1.5'

module Java::java::util::Enumeration
  def each
    while self.hasMoreElements
      yield self.nextElement
    end
  end
end if JRUBY_VERSION < '9.1.5'
Member

kares commented Sep 2, 2016

this is really unfortunate, but you might have to wait for 9.1.5.0 until its smoothed out.
when including "enhanced" interfaces (such as java.lang.Iterable, java.util.{Collection,List,Iterator,Enumeration}) in Ruby enhancements (such as the added Enumerable#each nature) will fail.

you can add the following patch as a temporary work-around (make sure its loaded before your part) :

module Java::java::util::Iterator
  def each
    while self.hasNext
      yield self.next
    end
  end
end if JRUBY_VERSION < '9.1.5'

module Java::java::util::Enumeration
  def each
    while self.hasMoreElements
      yield self.nextElement
    end
  end
end if JRUBY_VERSION < '9.1.5'

@kares kares closed this in 7a7b349 Sep 2, 2016

@slackfan

This comment has been minimized.

Show comment
Hide comment
@slackfan

slackfan Sep 2, 2016

Thank you very much for looking into it! The temporary workaround fully works for me 👍

slackfan commented Sep 2, 2016

Thank you very much for looking into it! The temporary workaround fully works for me 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment