Code Smell 304: Null Pointer Exception - How to Avoid NULL References That Cause Runtime Crashes
hackernoon.comI 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 😔
- Runtime crashes
- Big incidents and outages
- Unpredictable behavior
- Hard debugging
- User frustration
- System instability
- Poor reliability
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 😃
- Avoid nulls
- Use null checks if nulls are beyond your control (for example, an external API)
- Initialize default values
- Implement guard clauses
- Use null objects
- Don't use optionals
Refactorings ⚙️
Copyright of this story solely belongs to hackernoon.com . To see the full text click HERE