Skip to content

cache: reject HTTPS responses with null handshake before cache write (#8962)#9395

Open
iVamsi wants to merge 1 commit intosquare:masterfrom
iVamsi:fix/cache-reject-https-null-handshake-8962
Open

cache: reject HTTPS responses with null handshake before cache write (#8962)#9395
iVamsi wants to merge 1 commit intosquare:masterfrom
iVamsi:fix/cache-reject-https-null-handshake-8962

Conversation

@iVamsi
Copy link
Copy Markdown
Contributor

@iVamsi iVamsi commented Mar 30, 2026

Improve the fix for NullPointerException in Cache.Entry.writeTo() when an HTTPS response has a null handshake.

Problem with previous fix (#9345)

The previous fix guarded writeTo() with handshake != null, which prevented the NPE but wrote malformed cache entries to disk. The Entry(rawSource) read constructor still expects TLS data when url.isHttps, so these entries could never be read back — wasting disk I/O on entries that always result in a cache miss.

Fix

Added guards in Cache.put() and Cache.update() to reject HTTPS responses with null handshake before serialization, so malformed entries are never written to disk. The writeTo() guard is kept as defense-in-depth.

Tests updated

Three regression tests in CacheTest:

  • HTTPS response with null handshake is not cached
  • Multiple HTTPS requests with null handshake all succeed
  • HTTPS response with null handshake is not served from cache

All tests now assert cache.writeSuccessCount() == 0 to verify no entries are written to disk.

Fixes #8962

Reject HTTPS responses with null handshake in Cache.put() and Cache.update() so malformed entries are never written to disk.
@iVamsi iVamsi changed the title cache: guard null fields in Entry.writeTo() to fix NPE (#8962) cache: reject HTTPS responses with null handshake before cache write (#8962) Mar 30, 2026
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.

NullPointerException in Cache.Entry.writeTo()

1 participant