Skip to content

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

Merged
headius merged 1 commit intojruby:jruby-9.4from
headius:backport_loaded_feature_fix
Aug 14, 2025
Merged

Fix index -1 error while searching for feature path#8961
headius merged 1 commit intojruby:jruby-9.4from
headius:backport_loaded_feature_fix

Conversation

@headius
Copy link
Member

@headius headius commented Aug 14, 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

Backport of #8960

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
@headius headius added this to the JRuby 9.4.14.0 milestone Aug 14, 2025
@headius headius merged commit 5c99241 into jruby:jruby-9.4 Aug 14, 2025
96 checks passed
@headius headius deleted the backport_loaded_feature_fix branch August 15, 2025 16:26
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.

1 participant