Modernize String-based charset APIs to java.nio.charset.Charset#4606
Merged
Conversation
Replace charset-name String overloads (which throw the checked UnsupportedEncodingException) with Charset overloads, as flagged by Error Prone's JdkObsolete pattern. Charset.forName() throws unchecked IllegalArgumentException, so where the charset name comes from a client-supplied Content-Type header, the new ContentStreamBase.charsetForName() converts it back to UnsupportedEncodingException, preserving the previous contract that an invalid charset is handled as an I/O error. Dead UnsupportedEncodingException handling for compile-time-constant charsets is removed.
janhoy
commented
Jul 3, 2026
janhoy
added a commit
to janhoy/solr
that referenced
this pull request
Jul 3, 2026
Per review feedback, behavior-changing fixes are split into their own PRs so this PR only carries the mechanical Error Prone 2.50.0 compliance work: - Reference-equality bug fixes (ZkMaintenanceUtils, HttpShardHandler, ZkShardTermsTest) moved to apache#4605 - Charset API modernization (JdkObsolete findings) moved to apache#4606 The affected sites revert to the code on main, with @SuppressWarnings and a TODO comment pointing at the PR that carries the real fix; the suppressions are dropped when those PRs merge and this branch rebases.
renatoh
reviewed
Jul 3, 2026
dsmiley
reviewed
Jul 3, 2026
janhoy
added a commit
that referenced
this pull request
Jul 3, 2026
(cherry picked from commit da4e044)
janhoy
added a commit
to janhoy/solr
that referenced
this pull request
Jul 3, 2026
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.
Split out of the Error Prone 2.50.0 upgrade (#4604) per review feedback there: the
JdkObsoletepattern flags charset-nameStringoverloads, and this modernization changes exception behavior, so it deserves its own review.Stringcharset-name APIs (new String(bytes, name),new InputStreamReader(is, name),URLEncoder.encode(s, name), ...) with theirCharsetoverloads.Charset.forName()throws uncheckedIllegalArgumentExceptionwhere the old APIs threw the checkedUnsupportedEncodingException. Since the charset name often comes from a client-supplied Content-Type header, a newContentStreamBase.charsetForName()helper converts it back toUnsupportedEncodingExceptionso an invalid charset stays an I/O error instead of escaping as a runtime exception.HttpSolrClientcatchesIllegalArgumentExceptionexplicitly.UnsupportedEncodingExceptionhandling around compile-time-constant charsets (e.g.SolrParams.toQueryString).#4604 will suppress the corresponding
JdkObsoletefindings with TODO comments pointing here; once this merges, that branch drops the suppressions on rebase.