Skip to content

Keep the encoding of constant names in constant warnings - #10089

Open
sampokuokkanen wants to merge 2 commits into
jruby:masterfrom
sampokuokkanen:constant-warning-encoding
Open

sampokuokkanen wants to merge 2 commits into
jruby:masterfrom
sampokuokkanen:constant-warning-encoding

Conversation

@sampokuokkanen

Copy link
Copy Markdown
Contributor

The "already initialized constant" and "constant ... is deprecated" warnings joined the constant's id string (raw bytes) into a Java String, so X定数 printed as X宿°.

Build the message as a RubyString and quote the name like CRuby's QUOTE_ID, with a new port of rb_id_quote_unprintable. If the module and constant names have incompatible encodings, escape the constant name so the warning cannot raise Encoding::CompatibilityError. Name the module by its class path, not to_s, as CRuby does.

Narrow the TestConst#test_redefinition exclude to the missing "previous definition" line.

The "already initialized constant" and "constant ... is deprecated"
warnings joined the constant's id string (raw bytes) into a Java String,
so X定数 printed as X宿°.

Build the message as a RubyString and quote the name like CRuby's
QUOTE_ID, with a new port of rb_id_quote_unprintable. If the module and
constant names have incompatible encodings, escape the constant name so
the warning cannot raise Encoding::CompatibilityError. Name the module
by its class path, not to_s, as CRuby does.

Narrow the TestConst#test_redefinition exclude to the missing
"previous definition" line.
@headius headius added this to the JRuby 10.1.4.0 milestone Nov 17, 2026

@headius headius left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe this change could be made smaller by using the str methods in RubyStringBuilder, which have various forms to properly handle encoding an error string. There's several examples in the codebase.

@sampokuokkanen

Copy link
Copy Markdown
Contributor Author

Switched to str from RubyStringBuilder. I didn't use ids for the name since it still puts quotes around escaped names, as CRuby did before 3.1 (ruby/ruby@eec45a93ef changed QUOTE_ID to escape without quotes). So I kept a small port of the current rb_id_quote_unprintable, but maybe we should just fix ids()? Probably better as a follow up as it would be quite a big change.

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.

2 participants