Skip to content

Commit 84538f1

Browse files
committed
Use prepared accessors to retrieve Data fields
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.
1 parent 6ed4909 commit 84538f1

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

core/src/main/java/org/jruby/RubyData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public static void initialize(ThreadContext context, IRubyObject self, IRubyObje
123123
String keyString = toSymbol(context, k).idString();
124124
VariableAccessor variableAccessor = variableAccessors.get(keyString);
125125
if (variableAccessor != null) {
126-
selfObj.setInternalVariable(keyString, v);
126+
variableAccessor.set(self, v);
127127
} else {
128128
RubyArray unknownKeywords = unknownKeywordsPtr[0];
129129
if (unknownKeywords == null) {

0 commit comments

Comments
 (0)