Skip to content

Fix index -1 error while searching for feature path#8960

Merged
headius merged 2 commits intojruby:masterfrom
headius:fix_loaded_feature_check
Aug 14, 2025
Merged

Fix index -1 error while searching for feature path#8960
headius merged 2 commits intojruby:masterfrom
headius:fix_loaded_feature_check

Conversation

@headius
Copy link
Member

@headius headius commented Aug 13, 2025

The code here is intended to walk the incoming feature, looking for either '.' or '/' in order to break up the feature into a path and filename. This is then compared with the load path to find a match, indicating that the feature has been loaded via those paths.

The bug is that it should find one of those characters or leave the search index 'e' at the beginning of the feature string for a subsequent check, but it was ported incorrectly from the original C code. Index of stopping at the beginning of the string, it allows one more decrement leaving 'e' as -1, and String.charAt raises.

This is normally only triggered for features that are being required at the same time across threads, and which have not yet been expanded to their full load path form. With the unexpanded feature in flight, the search will never encounter '.' or '/' and walk off the head of the string.

Fixes #8958

The code here is intended to walk the incoming feature, looking for
either '.' or '/' in order to break up the feature into a path and
filename. This is then compared with the load path to find a match,
indicating that the feature has been loaded via those paths.

The bug is that it should find one of those characters or leave the
search index 'e' at the beginning of the feature string for a
subsequent check, but it was ported incorrectly from the original
C code. Index of stopping at the beginning of the string, it allows
one more decrement leaving 'e' as -1, and String.charAt raises.

This is normally only triggered for features that are being
required at the same time across threads, and which have not yet
been expanded to their full load path form. With the unexpanded
feature in flight, the search will never encounter '.' or '/' and
walk off the head of the string.

Fixes jruby#8958
When a simple feature lock name is provided here, such as when a
thread has just started doing its search for a given feature, the
initial backward walk through that name used to walk past the first
character. This subsequently triggered an AIOOB exception.

The test here attempts to simulate this situation, since it's a
very tricky set of concurrent loads required to trigger it
organically.

See jruby#8958
@headius headius force-pushed the fix_loaded_feature_check branch from 08224c5 to 05064f7 Compare August 13, 2025 21:51
@headius
Copy link
Member Author

headius commented Aug 14, 2025

Not sure I'm going to come up with a better test for this, so we'll just go with the narrow one for now. A refactoring of all of this code will need to happen at some point.

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.

Concurrent requires can lead to StringIndexOutOfBoundsException

1 participant