Skip to content

Tighten SolrQueryResponse.getResponseHeader/addResponseHeader to SimpleOrderedMap - #4809

Open
serhiy-bzhezytskyy wants to merge 2 commits into
apache:mainfrom
serhiy-bzhezytskyy:SOLR-solrqueryresponse-return-types
Open

Tighten SolrQueryResponse.getResponseHeader/addResponseHeader to SimpleOrderedMap#4809
serhiy-bzhezytskyy wants to merge 2 commits into
apache:mainfrom
serhiy-bzhezytskyy:SOLR-solrqueryresponse-return-types

Conversation

@serhiy-bzhezytskyy

Copy link
Copy Markdown
Contributor

Follow-up to @dsmiley's suggestion on #4761 (review thread on QueryComponent.java): rather than keep the remove()+add() workaround needed there because getResponseHeader()'s declared return type (NamedList<Object>) doesn't have a put(), this tightens the declared type to what it always actually is at runtime -- SimpleOrderedMap<Object> -- removing the internal unchecked cast and letting the 4 call sites in QueryComponent/CombinedQueryComponent use put() directly.

This also closes the actual hole that caused #4761's ClassCastException: MockResponseBuilder's mock was stubbing getResponseHeader() to return a bare NamedList, which the contract allowed but reality never produced. With the tightened return type, that mismatch is now a compile error instead of a runtime ClassCastException.

Compatibility note: this is binary-incompatible for any external caller compiled against the old NamedList signature -- verified locally (compiled a caller against the old class files, ran it against the new ones without recompiling): NoSuchMethodError on both getResponseHeader() and addResponseHeader(NamedList). SolrQueryResponse is @since solr 0.9 public API with no experimental/internal marker, so flagging this explicitly rather than treating it as a purely internal cleanup -- your call whether that's acceptable for 11.0.

AI-assisted (Claude Sonnet 5)

…leOrderedMap

getResponseHeader() always returned an actual SimpleOrderedMap internally,
masked by an unchecked cast; declaring the real type removes the cast and
lets 4 call sites in QueryComponent/CombinedQueryComponent use put() instead
of asShallowMap().put()/remove()+add(). It also turns the exact class of bug
hit in SOLR-18373 (a test mock returning a plain NamedList, causing a
runtime ClassCastException) into a compile error instead.

Binary-incompatible for external callers compiled against the old NamedList
signature (verified: NoSuchMethodError). Flagging for review since this is
long-standing public API, not something marked experimental/internal.

@dsmiley dsmiley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Solr 11. The binary incompatibility break for a prolific API like this wouldn't be nice for Solr plugin writers.

@dsmiley dsmiley added this to the 11.x milestone Aug 25, 2026
@epugh

epugh commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

@serhiy-bzhezytskyy can you add a changelog since this is a binary incompatbility?

@serhiy-bzhezytskyy

Copy link
Copy Markdown
Contributor Author

Added — see changelog/unreleased/SOLR-solrqueryresponse-return-types.yml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants