Skip to main content
FORGEJO ERA / ISSUE #607

Enum extraction mis-assigns ids, skips constants with bodies, and mixes codecs

closedOpened by MelanX on

Original description​

By MelanX · October 23, 2026

Crate: tools/minecraft-options

Commit: 2b2af1e4f8166d02e4732d19e040a53745d97a51

Behavior

extract_enum has several independent defects, none of which affects a shipped codec today:

  • A constant is closed at the first invokespecial <init> of any owner. A constructor argument such as new TextComponentTranslation(...) ends it early, so constructor_descriptor, id, and the string set are wrong. 1.12.2 to 1.15.2 mainHand reports LEFT id 0 and RIGHT id 0, and MusicFrequency ids are the delays 20/10/0. id is the first extra int, with no tie to the codec or an accessor, and enum_domain emits it as persisted for integer_id.
  • Constants are recognized only when new names the enum itself, so new Enum$1 constants with bodies are silently skipped. A partial list is returned as complete, with no check against $VALUES or the $values() array (HumanoidModel$ArmPose yields 10 of 11).
  • The codec form is read from window[-40:], which is not reset per field, so a second codec inherits the first one's evidence and string checks win. PermissionLevel.INT_CODEC, Direction.LEGACY_ID_CODEC, and every STREAM_CODEC are reported string_token.
  • An obfuscated fromEnum codec is string_token only if a constant carries a dotless string, so computed names stay unknown (musicFrequency in 1.21.6 to 1.21.10, while it resolves in 1.21.11+).
  • token_bindings binds a literal to the nearest preceding getstatic without looking at the branch opcode, so x != A ? "b" : "a" swaps the map, and complete_token_map fills in the remainder with no low-confidence signal. enum_string_lambda takes the first Enum -> String method.

Expected behavior

Constants end at the <init> of their own class, bodies are included and checked against $VALUES, each codec field only sees its own initializer, and inverted conditions and ambiguous accessors lower confidence.

Impact

An option whose enum is persisted by integer id, or has a constant body or an extra int parameter, would silently get wrong ids or an incomplete domain in the next release that introduces one.

Locations

  • tools/minecraft-options/analyze_options.py extract_enum (539-620), token_bindings (623-647), enum_string_lambda (662-675), enum_domain (699-713)

Validation and limitations

Reproduced with extract_enum against the cached 1.12.2, 26.1, and 26.3 JARs and synthetic instruction input.