Skip to content

Move all JI setAccessible to trySetAccessible.#5843

Merged
headius merged 2 commits intojruby:masterfrom
headius:ji_try_set_accessible
Aug 21, 2019
Merged

Move all JI setAccessible to trySetAccessible.#5843
headius merged 2 commits intojruby:masterfrom
headius:ji_try_set_accessible

Conversation

@headius
Copy link
Member

@headius headius commented Aug 21, 2019

The logic previously was depending on the ji.setAccessible
property, which by default would simply refuse to set accessible
at all when the Java version was >= "1.9" (also showing this
logic was introduced very early in the Java 9 development cycle.)

That default is removed here, along with a the CAN_SET_ACCESSIBLE
static field in RubyInstanceConfig deprecated and replaced with
the original meaning of this property, simply whether to attempt
setAccessible.

The direct calls to setAccessible have been replaced by the
trySetAccessible in backport9 library that checks if the target
member's module is open to JRuby, allowing users to opt-in to that
reflective access if their application needs it. Previously these
cases still skipped setAccessible just due to being on Java 9+.

Most of the changes here were masked by the property, but I have
also fixed several others that were not guarded by the property
or that were otherwise used in booting JRuby or extending Java
integration.

This fixes #5841 by allowing java_method Method objects to
go ahead and trySetAccessible when the module is open.

This relates to #5821, which fixed in 9.2.8 a similar issue where
even an open module would not set fields and methods accessible.

The logic previously was depending on the ji.setAccessible
property, which by default would simply refuse to set accessible
*at all* when the Java version was >= "1.9" (also showing this
logic was introduced very early in the Java 9 development cycle.)

That default is removed here, along with a the CAN_SET_ACCESSIBLE
static field in RubyInstanceConfig deprecated and replaced with
the original meaning of this property, simply whether to attempt
setAccessible.

The direct calls to setAccessible have been replaced by the
trySetAccessible in backport9 library that checks if the target
member's module is open to JRuby, allowing users to opt-in to that
reflective access if their application needs it. Previously these
cases still skipped setAccessible just due to being on Java 9+.

Most of the changes here were masked by the property, but I have
also fixed several others that were not guarded by the property
or that were otherwise used in booting JRuby or extending Java
integration.

This fixes jruby#5841 by allowing `java_method` Method objects to
go ahead and trySetAccessible when the module is open.

This relates to jruby#5821, which fixed in 9.2.8 a similar issue where
even an open module would not set fields and methods accessible.
@headius headius added this to the JRuby 9.2.9.0 milestone Aug 21, 2019
@headius headius requested a review from kares August 21, 2019 08:49
Copy link
Member

@kares kares left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great, we're finally behave 99.9+% same on 8 as on Java 9+

minor suggestion: have a JRuby trySetAccessible helper
... so we do not have to keep in mind to pass Ruby.class

@headius
Copy link
Member Author

headius commented Aug 21, 2019

minor suggestion: have a JRuby trySetAccessible helper
... so we do not have to keep in mind to pass Ruby.class

Yeah that might be a good idea. I hate to add something more to Ruby.java, but maybe to our Java class? It's already pretty fat and not really public API. Java.trySetAccessible would just do Modules.trySetAccessible(..., Java.class) and have the same effect.

@headius headius merged commit fe0411a into jruby:master Aug 21, 2019
@headius headius deleted the ji_try_set_accessible branch August 21, 2019 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't call methods of private subclasses with java_method in java 12

2 participants