Skip to content

cache: guard null fields in Entry.writeTo() to fix NPE (#8962)#9345

Merged
yschimke merged 2 commits intosquare:masterfrom
iVamsi:fix/cache-entry-write-npe-8962
Mar 20, 2026
Merged

cache: guard null fields in Entry.writeTo() to fix NPE (#8962)#9345
yschimke merged 2 commits intosquare:masterfrom
iVamsi:fix/cache-entry-write-npe-8962

Conversation

@iVamsi
Copy link
Contributor

@iVamsi iVamsi commented Feb 28, 2026

Fix NullPointerException in Cache.Entry.writeTo() when an HTTPS response has a null handshake.

Fix

Changed if (url.isHttps) to if (url.isHttps && handshake != null) so the TLS block is skipped when handshake is absent. The response still succeeds. It just won't be served from cache on subsequent requests.

Tests added

Three regression tests in CacheTest:

  • HTTPS response with null handshake does not crash writeTo().
  • Multiple HTTPS requests with null handshake all succeed
  • HTTPS response with null handshake is not served from cache

All verified to fail before the fix and pass after.

Fixes #8962

Copy link
Collaborator

@yschimke yschimke left a comment

Choose a reason for hiding this comment

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

I'm not sure if there is a different root cause, that https://example.com:80/ shouldn't match. But this change is an improvement, NPE from our code is bad.

@yschimke
Copy link
Collaborator

Actually httpsResponseWithNullHandshakeIsNotServedFromCache suggests it isn't blindly accepting.

@yschimke yschimke merged commit 21ad1aa into square:master Mar 20, 2026
22 of 23 checks 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.

NullPointerException in Cache.Entry.writeTo()

2 participants