Skip to content

Replace deprecated calls where context is already in scope - #9835

Draft
zev wants to merge 2 commits into
jruby:jruby-10.0from
zev:deprecations-10.0-batch-a
Draft

zev wants to merge 2 commits into
jruby:jruby-10.0from
zev:deprecations-10.0-batch-a

Conversation

@zev

@zev zev commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

First chunk of the deprecation cleanup discussed in #9810. Every change follows the zero-sum rule: context is already in scope (no new getCurrentContext()), and the replacement behaves the same as the deprecated call.

Deprecated call Replacement Site Why it's equivalent
RubyNumeric#getLongValue() asLong(context) RubyModule#hashCode getLongValue() is asLong(getCurrentContext()); convertToInteger() returns a Fixnum or Bignum, both of which implement asLong
RubyFixnum#getLongValue() getValue() RubyBignum#float_eq both return the value field
RubyString.newStringShared(Ruby, byte[], Encoding) newStringShared(Ruby, byte[], 0, bytes.length, Encoding) RubyInteger.singleCharString the deprecated method's body
RubyString.newStringShared(Ruby, byte[], int, int) newStringShared(Ruby, byte[], int, int, ASCIIEncoding.INSTANCE) RubyRegexp#named_captures the deprecated method's body
new RubyString(Ruby, RubyClass, byte[]) RubyString.newString(Ruby, byte[]) MarshalDumper#writeEncoding the class was stringClass(context); newString calls the same constructor with runtime.getString(). The constructor was deprecated in 1bda114 ("Deprecate all public String constructors") so callers go through factories
RubyString#inspect() inspect(context) RubyTimeParser (2 error messages) inspect() reaches inspect(getCurrentContext()) via RubyBasicObject#inspect()

Removes 7 deprecation warnings from core, adds none. Checked with a full -Xlint:deprecation,removal -Xmaxwarns compile, since the CI log stops at 100 warnings.

mspec ci on core marshal, regexp, time, module, integer and String#inspect: 3451 examples, 0 failures.

Adding @Deprecated to overrides of deprecated methods will be a separate PR.

🤖 Generated with Claude Code

zev and others added 2 commits October 19, 2026 17:47
Zero-sum deprecation cleanups for 10.0. Each replacement either is the
body of the deprecated method, or uses the ThreadContext the caller
already has. No new getCurrentContext() calls.

- RubyNumeric#getLongValue() -> asLong(context)
  RubyModule#hashCode: the result of convertToInteger() is a Fixnum or
  Bignum; getLongValue() ended up in asLong(getCurrentContext()).

- RubyFixnum#getLongValue() -> getValue()
  RubyBignum#float_eq: both return the value field.

- RubyString.newStringShared(Ruby, byte[], Encoding)
  -> newStringShared(Ruby, byte[], 0, bytes.length, Encoding)
  RubyInteger.singleCharString: the deprecated method's body.

- RubyString.newStringShared(Ruby, byte[], int, int)
  -> newStringShared(Ruby, byte[], int, int, ASCIIEncoding.INSTANCE)
  RubyRegexp#named_captures: the deprecated method's body.

- new RubyString(Ruby, RubyClass, byte[]) -> RubyString.newString(Ruby, byte[])
  MarshalDumper#writeEncoding: the class was stringClass(context), and
  newString(Ruby, byte[]) is that constructor with runtime.getString().
  Drops the now-unused stringClass import.

- RubyString#inspect() -> inspect(context)
  RubyTimeParser (two error messages): inspect() went through
  RubyBasicObject#inspect() to inspect(getCurrentContext()).

Removes 7 deprecation warnings from core.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Optional follow-up for review. org.jruby.api.Create.newString(context,
byte[]) delegates to RubyString.newString(context.runtime, byte[]), so
behavior is identical; this only uses the context-taking API.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zev

zev commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

@headius the last commit (Use Create.newString(context, bytes) in MarshalDumper#writeEncoding) is optional, and I'd like your call on it.

The first commit replaces the deprecated new RubyString(runtime, stringClass(context), bytes) with RubyString.newString(context.runtime, bytes). The second commit uses org.jruby.api.Create.newString(context, bytes) instead, which just delegates to the first:

public static RubyString newString(ThreadContext context, byte[] bytes) {
    return RubyString.newString(context.runtime, bytes);
}

Either way the behavior is the same. The question is whether you'd rather have the cleanup move callers to the org.jruby.api.Create helpers when context is in scope, or keep the smaller diff with the RubyString factory. If the Create form is preferred, I'll do the same for later batches. If not, I'll drop the commit.

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.

1 participant