Skip to content

JRuby adds Java proxy classes to the Java module even if they are not from JRubyClassLoader #8156

@barrkel

Description

@barrkel

JRuby version 9.3.13.0
Platform 6.5.13-1rodete2

Expected behavior:

  • There is a class org.example.C which is in a jar which is not on the class path, call this C_jar
  • There is a class org.example.C which is in a jar which is on the class path, call this C_classpath
  • C_jar is loaded via URLClassLoader and instantiated in Java code. This is done to isolate the different versions of C.
  • Use Ruby to evaluate an object expression which results in an instance of an object with the class C_jar
  • Use the Java module to reference the class C, expecting to get C_classpath (i.e. Java::OrgExample::C)

Actual behavior:

  • Using the Java module syntax to access C results in C_jar

Workaround:

  • Use the Java module syntax to access C before any Ruby expression which evaluates to an object of class C_jar

In Java.java, generateClassProxy calls addToJavaPackageModule without checking the class loader of the class it generated a proxy for. Effectively, manipulating values from non-JRubyClassLoader classes pollutes the Java module with incompatible classes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions