Backend Development 5 min read

Debugging a Marketing Tool: Identifying and Fixing a Boolean Logic Bug in Java

The author recounts a late‑night incident where a newly launched marketing tool malfunctioned due to a boolean logic error in Java code, describes the chaotic debugging process, presents the faulty and corrected implementations, and confirms the logical equivalence of the final solution.

Rare Earth Juejin Tech Community
Rare Earth Juejin Tech Community
Rare Earth Juejin Tech Community
Debugging a Marketing Tool: Identifying and Fixing a Boolean Logic Bug in Java

Almost a Crash

Two months ago, our company launched a new marketing tool nationwide at midnight, but the release was not smooth; monitoring curves dropped sharply at the moment of deployment, and some new users could not use the marketing discounts.

The issue affected many users, but because it occurred during a low‑traffic period, the impact was limited; however, a rapid fix was needed before traffic surged.

Although I was not responsible for this part, I was on duty that night and had to work through the early morning to resolve the problem.

Endless Sea of Mess

After drinking an energy drink, I dove into unfamiliar code that felt like a sea of filth: methods over 500 lines, deeply nested if‑else structures, missing logs, and tangled responsibilities.

Four or five colleagues, familiar with the code, also struggled to locate the bug.

After 30 minutes of careful analysis, I identified the root cause, held a brief bug briefing, and announced the fix.

Once the bug cause was confirmed, others rested while I handled fixing, testing, packaging, releasing, and verification until the morning, after which the monitoring curve returned to normal.

Bug Root Cause

Because the company code is confidential, I illustrate the problem with pseudocode.

The business logic iterates over all promotional activities; if any activity restricts new users, the system must check whether the current user is new.

The buggy code was:

boolean newUserCheckEnabled = false;
for ( Activity activity : activityList ) {
    newUserCheckEnabled = activity.isLimitNewUser();
}

This code sets newUserCheckEnabled to the value of the last activity only, so if the final activity does not limit new users, the flag becomes false even when earlier activities require the restriction, causing the bug.

Boss Personally Guides Code

The correct implementation should accumulate the restriction flag:

boolean newUserCheckEnabled = false;
for ( Activity activity : activityList ) {
    if (activity.isLimitNewUser()) {
        newUserCheckEnabled = true;
    }
}

The boss, however, suggested a more concise version using the logical OR operator:

boolean newUserCheckEnabled = false;
for ( Activity activity : activityList ) {
    newUserCheckEnabled = newUserCheckEnabled || activity.isLimitNewUser();
}

Both the if‑based and the OR‑based versions are logically equivalent, confirming that the concise expression correctly captures the intended behavior.

BackenddebuggingJavaCode Reviewbug-fixingboolean logic
Rare Earth Juejin Tech Community
Written by

Rare Earth Juejin Tech Community

Juejin, a tech community that helps developers grow.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.