remove *Ref.copy/append/grow [LUCENE-4675]
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 1.4k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 88
Description
These methods are dangerous:
In general if we want a StringBuilder type class, then it should own the array, and it can freely do allocation stuff etc. this is the only way to make it safe.
Otherwise if we want a ByteBuffer type class, then its reference should be immutable (the byte[]/offset/length should be final), and it should not have allocation stuff.
BytesRef is none of these, its like a C pointer. Unfortunately lucene puts these unsafe, dangerous, trappy APIs directly in front of the user.
What happens if i have a bug in my application and it accidentally mucks with the term bytes returned by TermsEnum or the payloads from DocsAndPositionsEnum? Will this get merged into a corrupt index?
I think as a start we should remove these copy/append/grow to minimize this closer to a ref class (e.g. more like java.lang.ref and less like stringbuilder). Nobody needs this stuff on bytesref, they can already operate on the bytes directly.
---
Migrated from [LUCENE-4675](https://issues.apache.org/jira/browse/LUCENE-4675) by Robert Muir (@rmuir)
Contributor guide
Research direction
Start by locating the BytesRef class and its copy, append, and grow methods, then search the repository for their callers. Review the existing tests covering BytesRef and its consumers; done means the unsafe APIs are removed and the relevant test suite still passes.
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
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100