Skip to content

fix: avoid invalid TextRange in @Value reference provider (#236)#238

Open
imuromtsev wants to merge 1 commit into
mainfrom
imuromtsev/fix-value-property-invalid-range
Open

fix: avoid invalid TextRange in @Value reference provider (#236)#238
imuromtsev wants to merge 1 commit into
mainfrom
imuromtsev/fix-value-property-invalid-range

Conversation

@imuromtsev
Copy link
Copy Markdown
Collaborator

Fixes #236.

Problem

ValueConfigurationPropertyReferenceProvider.getReferencesForInjectionHost built a TextRange from host.text.indexOf(key). When the @Value placeholder key comes from an evaluated string that does not appear literally in the raw host text (e.g. a Kotlin template referencing a const), indexOf returns -1 and TextRange.from(-1, n) throws IllegalArgumentException: Invalid range specified: (-1, n).

Fix

Switch mapmapNotNull and skip any reference whose key cannot be located in the host text (startOffset < 0) instead of constructing an invalid range.

Tests

Added ValueConfigurationPropertyReferenceProviderTest:

  • testValueReferencingConstantKeyDoesNotThrow — reproduces the crash (key from a const); now highlights without throwing.
  • testValueWithLiteralPlaceholderResolvesReference — happy path still resolves a reference.

Module test run: tests=2, failures=0, errors=0.

When the @value placeholder key is resolved from a constant or template, the evaluated string does not appear literally in the host text, so indexOf returns -1 and TextRange.from(-1, n) threw IllegalArgumentException. Skip references whose key cannot be located in the host text. Adds regression tests.
@github-actions
Copy link
Copy Markdown

TestsPassed ✅Skipped ⚠️Failed
JUnit Test Report1532 ran1526 passed6 skipped0 failed

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.

[BUG] IllegalArgumentException: Invalid range (-1, n) in @Value reference provider

1 participant