JRuby (please use github issues at http://bugs.jruby.org)
  1. JRuby (please use github issues at http://bugs.jruby.org)
  2. JRUBY-6493

Calling dynamically defined method throws Java::JavaLang::NullPointerException or returns nil without executing method body

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.5.6, JRuby 1.6.6, JRuby 1.6.7
    • Fix Version/s: JRuby 1.7.0.pre2
    • Component/s: Interpreter, Ruby 1.8.7
    • Labels:
      None
    • Environment:
      $ java -version
      java version "1.6.0_23"
      OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10.1)
      OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)
    • Number of attachments :
      0

      Description

      Calling a dynamically generated method (defined using `define_method(:method)

      { ..body.. }

      ` ) having `require 'ruby-debug'; debugger` inside it throws

      Java::JavaLang::NullPointerException: 
      	from org.jruby.ast.RescueNode.handleJavaException(RescueNode.java:206)
      	from org.jruby.ast.RescueNode.interpretWithJavaExceptions(RescueNode.java:141)
      	from org.jruby.ast.RescueNode.interpret(RescueNode.java:110)
      	from org.jruby.ast.DAsgnNode.interpret(DAsgnNode.java:110)
      	from org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
      	from org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
      ...
      

      Without `require 'ruby-debug'; debugger` in method body the call just returns nil without executing the method body. The following pastie tries to clarify the setup (sadly without reproducing the issue) http://pastie.org/private/ivtgoimsy9px8qftklm0w

      The following pasties are Rails 2.3.9 console sessions manifesting the problem with different JRubies
      http://pastie.org/private/gwx0g9tz6yzytmqs2s2jnq
      http://pastie.org/private/ycc8hmwjiyicfhsppslhw
      http://pastie.org/private/h2kr22mujqts2qilknhiig

      Console is launched

      $ jruby --server -J-Xms512m -J-Xmx512m -J-Xmn128m -J-Djruby.thread.pooling=true console.rb development
      

        Activity

        Hide
        Charles Oliver Nutter added a comment -

        The line of code in question confuses me. It should not cause NPE unless something is seriously misconfigured in the JVM.

        Here's the line of code:

        UnsafeFactory.getUnsafe().throwException(throwable);
        

        UnsafeFactory should be using a piece of code we generate in our build called GeneratedUnsafe. You should be able to find that in the jruby.jar file.

        This is the second report I've had of this problem, so I don't doubt that it's real.

        Are you able to build JRuby? If so, you could check out the jruby-1_6 branch and modify src/org/jruby/util/unsafe/UnsafeFactory.java setting the static DEBUG field to true. That would print out what's happening in there at startup; I assume we'll see an exception trace.

        Show
        Charles Oliver Nutter added a comment - The line of code in question confuses me. It should not cause NPE unless something is seriously misconfigured in the JVM. Here's the line of code: UnsafeFactory.getUnsafe().throwException(throwable); UnsafeFactory should be using a piece of code we generate in our build called GeneratedUnsafe. You should be able to find that in the jruby.jar file. This is the second report I've had of this problem, so I don't doubt that it's real. Are you able to build JRuby? If so, you could check out the jruby-1_6 branch and modify src/org/jruby/util/unsafe/UnsafeFactory.java setting the static DEBUG field to true. That would print out what's happening in there at startup; I assume we'll see an exception trace.
        Hide
        Tero Tilus added a comment -

        I thought I had my basis covered (wrapped up the state of app, deps and environment which manifested the issue) but I seem not to be able to reproduce the NPE issue anymore. Debugger seems not to be the trigger factor, even though I previously had a situation where commenting out debugger line made the NPE disappear.

        The other part (the call not executing the method body) still is there.

        I will still try to dig deeper. Suggestions are welcome.

        Show
        Tero Tilus added a comment - I thought I had my basis covered (wrapped up the state of app, deps and environment which manifested the issue) but I seem not to be able to reproduce the NPE issue anymore. Debugger seems not to be the trigger factor, even though I previously had a situation where commenting out debugger line made the NPE disappear. The other part (the call not executing the method body) still is there. I will still try to dig deeper. Suggestions are welcome.
        Hide
        Tero Tilus added a comment -

        Cloned JRuby, checked out jruby-1_6, set DEBUG=true, compiled and used the compiled JRuby to run the app. I did not get an exception trace (at least no to STDOUT or STDERR) or anything else different from what the published 1.6.7 does.

        Show
        Tero Tilus added a comment - Cloned JRuby, checked out jruby-1_6, set DEBUG=true, compiled and used the compiled JRuby to run the app. I did not get an exception trace (at least no to STDOUT or STDERR) or anything else different from what the published 1.6.7 does.
        Hide
        Tero Tilus added a comment -

        I ran into the NPE again. Now it only appears when exiting the console. With that homebrewn 1.6.7 having previously mentioned DEBUG=true it looks like this

        java.lang.NoClassDefFoundError: Could not initialize class org.jruby.util.unsafe.UnsafeFactory
        	at org.jruby.ast.RescueNode.interpretWithJavaExceptions(RescueNode.java:138)
        	at org.jruby.ast.RescueNode.interpret(RescueNode.java:110)
        	at org.jruby.ast.BeginNode.interpret(BeginNode.java:83)
        	at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
        	at org.jruby.evaluator.ASTInterpreter.INTERPRET_BLOCK(ASTInterpreter.java:111)
        	at org.jruby.runtime.InterpretedBlock.evalBlockBody(InterpretedBlock.java:374)
        	at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:295)
        	at org.jruby.runtime.InterpretedBlock.yieldSpecific(InterpretedBlock.java:229)
        	at org.jruby.runtime.Block.yieldSpecific(Block.java:99)
        	at org.jruby.RubyKernel.loop(RubyKernel.java:1410)
        

        Complete trace
        http://pastie.org/private/j4embn5nhrrjnvckqssma

        Show
        Tero Tilus added a comment - I ran into the NPE again. Now it only appears when exiting the console. With that homebrewn 1.6.7 having previously mentioned DEBUG=true it looks like this java.lang.NoClassDefFoundError: Could not initialize class org.jruby.util.unsafe.UnsafeFactory at org.jruby.ast.RescueNode.interpretWithJavaExceptions(RescueNode.java:138) at org.jruby.ast.RescueNode.interpret(RescueNode.java:110) at org.jruby.ast.BeginNode.interpret(BeginNode.java:83) at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104) at org.jruby.evaluator.ASTInterpreter.INTERPRET_BLOCK(ASTInterpreter.java:111) at org.jruby.runtime.InterpretedBlock.evalBlockBody(InterpretedBlock.java:374) at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:295) at org.jruby.runtime.InterpretedBlock.yieldSpecific(InterpretedBlock.java:229) at org.jruby.runtime.Block.yieldSpecific(Block.java:99) at org.jruby.RubyKernel.loop(RubyKernel.java:1410) Complete trace http://pastie.org/private/j4embn5nhrrjnvckqssma
        Hide
        Tero Tilus added a comment -

        I had already lost my hopes of reproducing but then it appeared again. This is a full reproduction of the NPE issue as it appeared before and using debug-enabled JRuby build: http://pastie.org/private/s3ogftmt0ykusuvtyus4fg

        Show
        Tero Tilus added a comment - I had already lost my hopes of reproducing but then it appeared again. This is a full reproduction of the NPE issue as it appeared before and using debug-enabled JRuby build: http://pastie.org/private/s3ogftmt0ykusuvtyus4fg
        Hide
        Tero Tilus added a comment - - edited
        $ cd jruby-dir/lib
        $ jar -tf jruby.jar | grep UnsafeFactory
        org/jruby/util/unsafe/UnsafeFactory.class
        
        Show
        Tero Tilus added a comment - - edited $ cd jruby-dir/lib $ jar -tf jruby.jar | grep UnsafeFactory org/jruby/util/unsafe/UnsafeFactory.class
        Hide
        Charles Oliver Nutter added a comment -

        I expect this is fixed now. The exception-handling logic has been rewritten for JRuby 1.7 to just raise the original error. Most of the lines in these traces no longer match up.

        If it's possible to reproduce, feel free to reopen.

        Show
        Charles Oliver Nutter added a comment - I expect this is fixed now. The exception-handling logic has been rewritten for JRuby 1.7 to just raise the original error. Most of the lines in these traces no longer match up. If it's possible to reproduce, feel free to reopen.

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Tero Tilus
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: