Repository navigation
[Ready] SOLR-9864: getCopy() also copies the sort clause list - #5150
Draft
nick-boss-tech wants to merge 8 commits into
Draft
nick-boss-tech wants to merge 8 commits into
nick-boss-tech wants to merge 8 commits into
Conversation
Hypothetical, unrun regression test; see SOLR-9864-TESTING.md.
nick-boss-tech
marked this pull request as ready for review
October 15, 2026 00:15
getCopy() also copies the sort clause listgetCopy() also copies the sort clause list
nick-boss-tech
marked this pull request as draft
October 28, 2026 04:44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 AI text below 🤖 (posted on behalf of Nick Shanin)
Ready for review, but held as a draft due to the project's open-PR cap; I'll mark it open on request.
https://issues.apache.org/jira/browse/SOLR-9864
What happens today
SolrQuery.getCopy()copies thesortparameter but not the internal sort-clause list, so the copy'sgetSorts()is empty.The copy keeps the serialized
sortparameter, so its sorts are not lost until the copy's sort list changes. Adding a sort to the copy rebuildssortfrom the empty list, and only the new clause remains. For a query sorted byprice asc,id desc, addingscore descto the copy givesscore descinstead ofprice asc,id desc,score desc. The ticket lists 4.8.1, 6.3, 7.7, and 9.0 as affected versions. The copy code is at SolrQuery.java L1182-L1188 at base.What this change does
getCopy()also copies the sort-clause list.The copy gets a new
ArrayListthat holds the sameSortClauseobjects in the same order (SolrQuery.java L1187-L1189).SortClausehas final fields, so sharing the objects is safe. Changing the copy's sorts leaves the original unchanged. No other part ofgetCopy()changes.Proof
The new test fails on the base code and passes with this change.
testGetCopyKeepsSortClausesfails on base14c7aac0d151402b00259e2fb9bf5eed7049ec5d: the copy's sort list is empty where the two clauses were expected. A second test,testGetCopyRemoveReplaceAndClearSortClauses, also fails on base: after a sort is removed from the copy, the copy still reports the removed clause. The other 17SolrQueryTestmethods pass on that base, includingtestGetCopyWithoutSortClauses, which pins the no-sort case.Verified 2026-10-15 at
0fdc9e97b2b0930641f1d4174e6053c69895e4d3:SolrQueryTest19 of 19QueryRequestTest5 of 5TestUpdateRequest5 of 5Formatting (
tidy), the Error Prone test compile, and:solr:solrj:check -x testalso pass.Limits
The tests cover copies with two sorts, with sorts removed and replaced, and with no sorts.
testGetCopyWithoutSortClausescovers that case; it passes on the base code too, since that behavior was already correct.sortparameter has no clause list. Parsing that parameter into clauses is outside this change. We can open a follow-up ticket and PR for it on request.SortClausesubclass with mutable state would share that state../gradlew checkhas not been run. The focused tests above are the behavior evidence.action_requiredand have not produced results yet.Changelog:
changelog/unreleased/SOLR-9864-solrquery-getcopy-sorts.ymlAI assistance
AI agents assisted with research, implementation, review, and drafting. Nick Shanin directed the work and takes responsibility for this contribution.