Skip to content

Use prepared accessors to retrieve Data fields#9252

Merged
headius merged 1 commit intojruby:masterfrom
headius:data_var_accessors
Feb 18, 2026
Merged

Use prepared accessors to retrieve Data fields#9252
headius merged 1 commit intojruby:masterfrom
headius:data_var_accessors

Conversation

@headius
Copy link
Member

@headius headius commented Feb 18, 2026

Data types are initialized with a set of accessors for the requested fields, which allows caching those accessors and avoiding costly hash lookups for future accesses. Due to a bug in how these accessors are initialized, parent and subclasses may have a different view of how those fields are stored in the object.

Here, the cached accessors are iterated, but then not used to read the field. This results in a second field being created for the subclass, in a different order from definition time. Using the original accessor here accesses the correct field.

Fixes #9241.

Note that there's other problems with the data layout inside a Data type and other fixes will be needed to clean up how these accessors are allocated and shared with subclasses.

Data types are initialized with a set of accessors for the
requested fields, which allows caching those accessors and
avoiding costly hash lookups for future accesses. Due to a bug in
how these accessors are initialized, parent and subclasses may
have a different view of how those fields are stored in the object.

Here, the cached accessors are iterated, but then not used to read
the field. This results in a second field being created for the
subclass, in a different order from definition time. Using the
original accessor here accesses the correct field.

Fixes jruby#9241.

Note that there's other problems with the data layout inside a Data
type and other fixes will be needed to clean up how these accessors
are allocated and shared with subclasses.
@headius headius added this to the JRuby 10.0.4.0 milestone Feb 18, 2026
@headius headius merged commit 53eca6d into jruby:master Feb 18, 2026
79 checks passed
@headius headius deleted the data_var_accessors branch February 18, 2026 20:57
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.

Data#to_h and Data#deconstruct return values in wrong order when module overrides initialize in a subclassed Data class

1 participant