8000 fix: prevent NPE in bestAllowedEncoding when wildcard is absent by kawasima · Pull Request #114 · enkan/enkan · GitHub
[go: up one dir, main page]

Skip to content

fix: prevent NPE in bestAllowedEncoding when wildcard is absent - #114

Merged
kawasima merged 1 commit into
developfrom
feature/fix-encoding-npe
Mar 28, 2026
Merged

kawasima merged 1 commit into
developfrom
feature/fix-encoding-npe

Conversation

@kawasima
Copy link
Copy Markdown
Collaborator

Summary

  • Fix NullPointerException in AcceptHeaderNegotiator.bestAllowedEncoding() when Accept-Encoding header does not contain * wildcard
  • Extract wildcardQ before the scoring lambda and default to 0.0 when both the encoding and wildcard are absent
  • Root cause: accepts.getOrDefault(encoding, accepts.get("*")) returns null when neither key exists, which is then unboxed to double

Closes #110

Test plan

  • encodingNegotiationWithoutWildcardDoesNotThrow — NPE regression test: Accept-Encoding: gzip with available ["deflate"] returns "identity"
  • encodingNegotiationWithWildcard — wildcard present: gzip;q=1.0 preferred over *;q=0.5
  • encodingNegotiationExactMatch — exact match: gzip;q=1.0 preferred over deflate;q=0.5
  • encodingFallsBackToIdentity — no match: falls back to "identity"
  • encodingReturnsNullWhenIdentityRejected — identity;q=0 explicitly rejected → returns null
  • All 19 AcceptHeaderNegotiator tests pass

🤖 Generated with Claude Code

< 8000 div class="pr-1 flex-shrink-0" style="width: 16px;">
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>
@kawasima
kawasima merged commit 2ad608d into develop Mar 28, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0