Skip to content

Prepending a module to a module extended by a class gives NPE when calling super #4678

@donv

Description

@donv

jruby 9.1.12.0 (2.3.3) 2017-06-15 33c6439 Java HotSpot(TM) 64-Bit Server VM 25.112-b16 on 1.8.0_112-b16 +jit [darwin-x86_64]
Darwin Gratass.local 16.6.0 Darwin Kernel Version 16.6.0: Fri Apr 14 16:21:16 PDT 2017; root:xnu-3789.60.24~6/RELEASE_X86_64 x86_64

Given the following code:

module A
  def self.included(clazz)
    clazz.extend ClassMethods
  end

  module ClassMethods
    def foo
      puts 'super'
    end
  end
end

class B
  include A
end

module C
  def foo
    super
  end
end
A::ClassMethods.prepend C

B.foo

JRuby 9.1.12.0 gives the following stack trace:

Unhandled Java exception: java.lang.NullPointerException
java.lang.NullPointerException: null
                      unresolvedSuper at org/jruby/ir/runtime/IRRuntimeHelpers.java:1014
  invokeSuper6:-unknown-super-target- at jruby_example.rb:19
                                  foo at jruby_example.rb:19
                                 call at org/jruby/internal/runtime/methods/CompiledIRMethod.java:155
                         cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:318
                                 call at org/jruby/runtime/callsite/CachingCallSite.java:131
                    invokeOther10:foo at jruby_example.rb:24
                               <main> at jruby_example.rb:24
                  invokeWithArguments at java/lang/invoke/MethodHandle.java:627
                                 load at org/jruby/ir/Compiler.java:95
                            runScript at org/jruby/Ruby.java:827
                          runNormally at org/jruby/Ruby.java:746
                          runNormally at org/jruby/Ruby.java:764
                          runFromMain at org/jruby/Ruby.java:577
                        doRunFromMain at org/jruby/Main.java:417
                          internalRun at org/jruby/Main.java:305
                                  run at org/jruby/Main.java:232
                                 main at org/jruby/Main.java:204

With MRI 2.4.1 it prints "super".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions