Skip to content

[fix] avoid Class#subclasses deprecation with class.rb ext#8080

Merged
kares merged 1 commit intojruby:masterfrom
kares:un-deprecate-subclasses
Feb 3, 2024
Merged

[fix] avoid Class#subclasses deprecation with class.rb ext#8080
kares merged 1 commit intojruby:masterfrom
kares:un-deprecate-subclasses

Conversation

@kares
Copy link
Member

@kares kares commented Jan 25, 2024

When doing a require 'jruby/core_ext/class.rb' the Class#subclasses method gets re-defined and cause a deprecation warning. Rails 7.x relies on (the Ruby 3.1 feature) Class#subclasses causing a lot of warning under JRuby 9.4.

The javadoc should provide an explanation (history of Class#subclasses), here's the demonstration of the issue:

bin/jruby -v -rjruby/core_ext/class -e 'puts String.subclasses'
jruby 9.4.6.0-SNAPSHOT (3.1.4) 2024-01-25 98ca4a1a53 OpenJDK 64-Bit Server VM 11.0.14.1+1 on 11.0.14.1+1 +jit [x86_64-linux]
DidYouMean::ClassNameChecker::ClassName

🟢 no warning

bin/jruby -v -rjruby/core_ext/class -e 'puts String.subclasses'
jruby 9.4.6.0-SNAPSHOT (3.1.4) 2024-01-25 98ca4a1a53 OpenJDK 64-Bit Server VM 11.0.14.1+1 on 11.0.14.1+1 +jit [x86_64-linux]
-e:1: warning: klass.subclasses is deprecated, use JRuby.subclasses(klass) instead
DidYouMean::ClassNameChecker::ClassName

🔴


AFTER applying this patch:

bin/jruby -v -rjruby/core_ext/class -e 'puts String.subclasses'
jruby 9.4.6.0-SNAPSHOT (3.1.4) 2024-01-25 98ca4a1a53 OpenJDK 64-Bit Server VM 11.0.14.1+1 on 11.0.14.1+1 +jit [x86_64-linux]
DidYouMean::ClassNameChecker::ClassName
bin/jruby -v -rjruby/core_ext/class -e 'puts String.subclasses(all: false)'
jruby 9.4.6.0-SNAPSHOT (3.1.4) 2024-01-25 98ca4a1a53 OpenJDK 64-Bit Server VM 11.0.14.1+1 on 11.0.14.1+1 +jit [x86_64-linux]
-e:1: warning: Class#subclasses(opts) is deprecated, please use the supported Class#subclasses() version
DidYouMean::ClassNameChecker::ClassName

The only down-side is that String.subclasses(one_arg) will now be available even without doing a require 'jruby/core_ext/class' but than doing that "properly" seemed like a lot of extra work, lmkwyt.

@headius
Copy link
Member

headius commented Jan 25, 2024

Seems good to me. Should also get a PR in place to simply remove it in 9.5.

For that matter, we should consider putting together a PR for 9.5 that removes a whole bunch more deprecated stuff, since most of it has been there for years and years.

cc @enebo

@enebo
Copy link
Member

enebo commented Jan 29, 2024

@kares @headius yeah I think it looks good. We have quite a lot of warns when running Rails 7+ so anything to reduce noise is good.

@kares
Copy link
Member Author

kares commented Jan 30, 2024

Will mérge and open a follow up PR for 9.5.
The red CI is legit, will take a look at failures first.

@kares kares force-pushed the un-deprecate-subclasses branch from d80966d to 15fcd33 Compare February 3, 2024 13:49
@kares kares added this to the JRuby 9.4.6.0 milestone Feb 3, 2024
@kares kares merged commit f431c1b into jruby:master Feb 3, 2024
@kares kares deleted the un-deprecate-subclasses branch February 12, 2024 10:59
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.

3 participants