Skip to content

Fix: Keep acronyms uppercase in Java enum constants (#2850)#2851

Merged
schani merged 4 commits into
glideapps:masterfrom
mohamedelhabib:master
Jul 6, 2026
Merged

Fix: Keep acronyms uppercase in Java enum constants (#2850)#2851
schani merged 4 commits into
glideapps:masterfrom
mohamedelhabib:master

Conversation

@mohamedelhabib

Copy link
Copy Markdown
Contributor

Enum constants containing known acronyms (like "SPA") were being incorrectly converted when using --acronym-style=camel, e.g. "MULTI_SPA_IN_GROUP_REJECTED" became "MULTI_Spa_IN_GROUP_REJECTED".

For Java enum constants (UPPER_UNDERSCORE style), acronyms should always remain uppercase regardless of the --acronym-style setting.

  • Modified javaNameStyle() to use allUpperWordStyle for acronyms in enum constants
  • Added test case for enum with "SPA" acronym

Description

Related Issue

Motivation and Context

Previous Behaviour / Output

New Behaviour / Output

How Has This Been Tested?

Screenshots (if appropriate):

mohamedelhabib and others added 4 commits December 5, 2025 19:51
Enum constants containing known acronyms (like "SPA") were being incorrectly
converted when using --acronym-style=camel, e.g. "MULTI_SPA_IN_GROUP_REJECTED"
became "MULTI_Spa_IN_GROUP_REJECTED".

For Java enum constants (UPPER_UNDERSCORE style), acronyms should always remain
uppercase regardless of the --acronym-style setting.

- Modified javaNameStyle() to use allUpperWordStyle for acronyms in enum constants
- Added test case for enum with "SPA" acronym
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…#2851

- Revert the re-indentation of the neighboring ternary in Java/utils.ts;
  keep only the semantic one-line fix (it failed biome check).
- Remove test/inputs/json/priority/enum-spa.json: as a JSON sample it ran
  through every language with default options and never exercised the
  acronym-style bug.
- Remove the hand-written MessageCode.java fixture file, which was never
  compared against generated output.

A real regression check follows in the next commit.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The fixture harness cannot catch this bug: mangled enum constants are
self-consistent identifiers (the generated code compiles) and
(de)serialization uses the raw JSON names (round-tripping succeeds).

test/check-java-acronym-names.ts generates Java for an enum containing
the known acronym "SPA" under all four --acronym-style settings and
asserts on the emitted enum constant *identifier* (extracted from the
toValue() switch, since the raw JSON name always appears in string
literals even when the identifier is wrong). It runs standalone via
ts-node and as a pre-fixture check in test/test.ts, like
check-no-node-imports.ts.

Verified to fail on unfixed code:
    acronym-style=camel: got "MULTI_Spa_IN_GROUP_REJECTED"
    acronym-style=lowerCase: got "MULTI_spa_IN_GROUP_REJECTED"

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@schani

schani commented Jul 6, 2026

Copy link
Copy Markdown
Member

Thanks for the fix — the one-line change in javaNameStyle is correct, and I've kept it as-is. I pushed three commits to this branch to get it ready to merge:

1. Merged current master (d2e1c43) — the branch was a few months behind.

2. Replaced the test artifacts (b1479e5, 6066b9d):

  • test/inputs/json/priority/enum-spa.json was a JSON Schema document added as a JSON sample, so it ran through every language fixture with default options and never exercised the acronym-style code path — it couldn't catch this bug (and priority samples run in every CI job, which is likely what made CI red here).
  • test/fixtures/java/src/main/java/io/quicktype/MessageCode.java was a hand-written file that nothing ever compared against generated output.
  • More fundamentally, the fixture harness cannot catch this regression: the mangled constants are self-consistent identifiers, so the generated Java still compiles, and (de)serialization uses the raw JSON names, so round-tripping succeeds either way.

The replacement is test/check-java-acronym-names.ts, following the existing check-no-node-imports.ts pattern: it generates Java from a schema whose enum contains the known acronym SPA, for all four --acronym-style settings, and asserts on the emitted enum constant identifier (extracted from the toValue() switch — just grepping the output for MULTI_SPA_IN_GROUP_REJECTED would always pass, because the raw JSON name appears in string literals even when the identifier is mangled). It runs standalone via ts-node and as a pre-fixture check in test/test.ts, so it runs in every CI matrix job.

Verified both ways: with your fix temporarily reverted, the check fails with

acronym-style=camel: got "MULTI_Spa_IN_GROUP_REJECTED", expected "MULTI_SPA_IN_GROUP_REJECTED"
acronym-style=lowerCase: got "MULTI_spa_IN_GROUP_REJECTED", expected "MULTI_SPA_IN_GROUP_REJECTED"

and with the fix present it passes for all four styles.

3. Reverted the unrelated re-indentation of the neighboring ternary in Java/utils.ts — it failed biome check; the diff is now just the semantic change plus a comment.

🤖 Generated with Claude Code

@schani
schani merged commit 26e9c09 into glideapps:master Jul 6, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants