Java Coding Question – Sneaky Enum Bug
Enum bug, concept, coding and solution
Problem
Backend APIs often rely on enums to represent filter, sorting, or expansion parameters. Sounds clean and safe, right? Until it isn’t. Backend system expected enum values in lower-case snake_case, while real-world API clients were sending UPPER_CASE enum names… and everything silently broke. No errors. No warnings.
Just quietly failing behavior — the worst kind.
We have an enum:
Expected client input
"created_at"What real clients actually send
"CREATED_AT"or sometimes…
"Created_At"Result in production
Enum is not mapped
Expansion logic doesn’t execute
Sorting / filtering silently fails
To fix this, we want to accept all of these:
CREATED_AT
created_at
Created_AtBut we must reject the following:
createdAt
created-at
createdAt123
anything_unknownBehavior requirements:
Normalize input
Map correctly to enum
Throw
IllegalArgumentExceptionfor invalid valuesDon’t break existing behavior
📢 Get actionable Java/Spring Boot insights every week — from practical code tips to real-world use-case based interview questions.
Join 3600+ subscribers and level up your Spring & backend skills with hand-crafted content — no fluff.
I want to offer an additional 40% discount ($ 18 per year) until January 31st. That’s just $1.5/mo. Unlock all the premium benefits including 35+ real world use cases.
Not convinced? Check out the details of the past work
Solution
We will add the fromString() method to our SortField Enum. fromString() converts a string input from the client into the correct SortField enum constant.
First, we check if the input is null or blank; if so, we raise IllegalArgumentException.




