Repository navigation
fix: prevent NPE in bestAllowedEncoding when wildcard is absent - #114
Merged
Merged
Conversation
accepts.getOrDefault(encoding, accepts.get("*")) returns null when
neither the encoding nor "*" is in the accepts map. The null is
unboxed to double in AcceptFragment, causing NullPointerException.
Extract wildcardQ before the lambda and return 0.0 as the default
when both the encoding and wildcard are absent.
Closes #110
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
NullPointerExceptioninAcceptHeaderNegotiator.bestAllowedEncoding()when Accept-Encoding header does not contain*wildcardwildcardQbefore the scoring lambda and default to0.0when both the encoding and wildcard are absentaccepts.getOrDefault(encoding, accepts.get("*"))returnsnullwhen neither key exists, which is then unboxed todoubleCloses #110
Test plan
encodingNegotiationWithoutWildcardDoesNotThrow— NPE regression test:Accept-Encoding: gzipwith available["deflate"]returns"identity"encodingNegotiationWithWildcard— wildcard present:gzip;q=1.0preferred over*;q=0.5encodingNegotiationExactMatch— exact match:gzip;q=1.0preferred overdeflate;q=0.5encodingFallsBackToIdentity— no match: falls back to"identity"encodingReturnsNullWhenIdentityRejected—identity;q=0explicitly rejected → returnsnull🤖 Generated with Claude Code