Engineering With Java

Engineering With Java

Java Bug Fix Interview Question — Payment Retry Bug

Replacing nullable flags with explicit domain states

Suraj Mishra's avatar
Suraj Mishra
Jun 09, 2026
∙ Paid

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:

null

then 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)

So far we have covered 62 real world based interview questions and will add up to 100 by end of this year.

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

User's avatar

Continue reading this post for free, courtesy of Suraj Mishra.

Or purchase a paid subscription.
© 2026 Suraj Mishra · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture