Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Reflective methods should not create symbols for nonexistent elements #5169
Currently our logic for reflective methods like Object#instance_variable_get, Struct#, etc goes like this:
The logic we need to match in MRI is as follows:
MRI only creates symbols for nonexistent key strings passed to the write methods, like instance_variable_set. Our logic has the following issues that should be addressed in some way before 9.2 (or if possible, we should match MRI's logic exactly):
In general MRI will assume that if a string is passed in, and no such symbol exists, no such entry can exists in whatever is being searched.
We all agree that the hard symbol issue should be fixed for 9.2.
The simple fix is to make them soft, and I mention above that although it would not leak it would temporarily pollute the symbol table with useless entries.
However, the surface area for this case seems very small:
And the impact of this would be fairly limited: if it's a check to see if the reflective value has been set, so it can be initialized, it would almost immediately be made a proper hard identifier symbol. So for the 9.2 release I believe the risk is low in the soft symbol option.
@enebo We should evaluate if this is still really an issue. Your work on symbols landed for 9.2, and the surface area for this bug remains small: you must be accessing non-existing identifiers using the Java-facing reflective methods like instance_variable_get.
The dance that's a problem is the use of validateInstanceVariable, which always creates a symbol whether the variable exists or not.