Tech »  Topic »  Code Smell 304: Null Pointer Exception - How to Avoid NULL References That Cause Runtime Crashes

Code Smell 304: Null Pointer Exception - How to Avoid NULL References That Cause Runtime Crashes


by Maximiliano Contieri June 20th, 2025

I keep writing about NULL problems, yet every day the news reminds me: NULL is still alive and kicking.

TL;DR: Avoid NULL references that cause runtime crashes by using proper validation and null-safe patterns

Problems 😔

In Google Cloud case:

  • Poor error handling: The code crashed instead of gracefully handling null data
  • No feature flags: New code wasn't gradually rolled out with safety controls
  • Instant global replication: Bad data spreads worldwide immediately like in Crowdstrike Incident
  • No randomized backoff: Recovery caused infrastructure overload
  • Inadequate testing: The failure scenario was never tested during deployment

Solutions 😃

  1. Avoid nulls
  2. Use null checks if nulls are beyond your control (for example, an external API)
  3. Initialize default values
  4. Implement guard clauses
  5. Use null objects
  6. Don't use optionals

Refactorings ⚙️

https://hackernoon.com ...


Copyright of this story solely belongs to hackernoon.com . To see the full text click HERE