Skip to content

can not re-reify sub-class of a Java sub-class #8141

@kares

Description

@kares

This is a bit of a stretch, usually not something that happens in production but still Ruby class removing is not that uncommon.

class SubList < java.util.ArrayList
  def initialize(arg1, arg2)
    puts "initialize #{self}"
    super(arg1 + arg2)
  end
end

class SubSubList < SubList
end

p SubSubList.new(1, 2)

Object.send(:remove_const, :SubSubList) 
# ... while parent SubList stays around (if it's removed as well it's not an issue)

class SubSubList < SubList
end

p SubSubList.new(1, 2)

Environment Information

Provide at least:

  • JRuby 9.3.0.0 - 9.4.6.0

Expected Behavior

  • Script works, reification is able to deal with the removed sub-class while parent was kept

Actual Behavior

  • Second SubSubList.new will fail:
initialize 
#<SubSubList: []>
ArgumentError: wrong number of arguments for constructor
  <main> at repro_java_sub_class.rb:26

due (-XreifylogErrors):

2024-03-05T15:10:02.637+01:00 [main] ERROR RubyClass : failed to reify class SubSubList due to: 
java.lang.LinkageError: loader org.jruby.util.OneShotClassLoader @1f172892 attempted duplicate class definition for rubyobj.SubSubList. (rubyobj.SubSubList is in unnamed module of loader org.jruby.util.OneShotClassLoader @1f172892, parent loader org.jruby.java.codegen.MultiClassLoader @6ba6557e)
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
	at org.jruby.dist/org.jruby.util.OneShotClassLoader.defineClass(OneShotClassLoader.java:20)
	at org.jruby.dist/org.jruby.RubyClass.reify(RubyClass.java:1447)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions