Java Bug Fix Interview Question — Payment Retry Bug
Replacing nullable flags with explicit domain states
Scenario
You are building a payment platform.
When a payment fails due to a temporary issue:
network timeout
bank gateway unavailable
transient 5xx error
the system schedules a retry.
A new field was recently added:
Value Meaning
true. Retry allowed
false. Permanent failure
null. Unknown / not populate
A deployment goes live. and we see NullPointerException appearing intermittently.
Can you identify the bug?
The bug is caused by auto-unboxing a nullable Boolean into a primitive boolean.
In this line:
if (payment.getRetryable() == false) {
return;
}getRetryable() returns a Boolean object, but the == false comparison requires a primitive boolean.
The compiler effectively rewrites it as:
if (payment.getRetryable().booleanValue() == false) {
return;
}If retryable contains:
nullthen Java attempts to execute:
null.booleanValue()which throws a:
NullPointerException📢 Get actionable Java and Spring Boot insights every week, including practical code tips and real-world, use-case-based interview questions, to help you level up your backend skills—join 7500+ subscribers for hand-crafted, no-fluff content.
First 100 paid subscribers will get the annual membership at $50/year forever that is ~ $4/mo ( 92 already converted to paid, 11 remaining)
Testimonials
Why this is a realistic production bug?
This issue often appears after:
adding a new nullable column to a database
consuming events from another service where a field is omitted
deserializing JSON where a boolean field is optional
incomplete data migrations or backfills






