Remove `throws IOException` from `Weight.scorerSupplier()`
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 1.4k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 88
Description
## Summary
`Weight.scorerSupplier(LeafReaderContext)` currently declares `throws IOException`. Removing it would make the existing planning-time contract enforceable at compile time.
## Motivation
`scorerSupplier()` is a planning-time method, invoked on every segment and every clause of a `BooleanQuery` before execution begins. It should be cheap: no reader opens or other I/O. Expensive work belongs in `ScorerSupplier#get(long leadCost)`, which is invoked only during execution.
The `throws IOException` declaration makes it possible to accidentally call I/O methods such as `LeafReader.getBinaryDocValues()` directly inside `scorerSupplier()`. The API therefore relies on documentation and code review to enforce the contract.
Lucene has already removed `throws IOException` from a number of methods that are not expected to perform I/O: `LeafReader#getPointValues` (#16057), `LeafReader#terms` (#16058), `LeafReader#getDocCount` (#16059), and `ScorerSupplier#setTopLevelScoringClause` (#14291). Removing it from `Weight.scorerSupplier()` would follow the same direction.
## Proposed change
Remove `throws IOException` from `Weight.scorerSupplier(LeafReaderContext)` and update implementations accordingly. Existing overrides would need to drop the `throws IOException` declaration. Implementations that currently perform I/O inside `scorerSupplier()` would also need to defer that work to `ScorerSupplier#get()`, while implementations that only perform metadata lookups would require no behavioral changes.
The Javadoc should be updated in the same change by removing the `@throws IOException` tag and explicitly documenting that `scorerSupplier()` must not perform I/O or other expensive work, which should instead be deferred to `ScorerSupplier#get()`.
Contributor guide
Research direction
Start at Weight.scorerSupplier(LeafReaderContext) and inspect its Javadoc, overrides, and callers across the repository. Check implementations for I/O that must move to ScorerSupplier#get(long leadCost), update the contract and declarations, then run the relevant Java tests and compilation checks to confirm all overrides still build.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- search
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100