Skip to content

[BCEL-379] Emit boolean literals for boolean ConstantValue fields - #536

Closed
AryanRG wants to merge 1 commit into
apache:masterfrom
AryanRG:bcel-379-boolean-constants
Closed

AryanRG wants to merge 1 commit into
apache:masterfrom
AryanRG:bcel-379-boolean-constants

Conversation

@AryanRG

@AryanRG AryanRG commented Oct 17, 2026

Copy link
Copy Markdown

Summary

BCEL-379: BCELifier prints the numeric CONSTANT_Integer value for a boolean field, so its generated creator calls FieldGen.setInitValue(int) and fails at runtime. Emit a boolean literal for boolean fields while leaving other constant types unchanged.

The regression checks true and false literals from compiled bytecode and adds the fixture to the existing generate/compile/run/javap round trip. The change also includes a changes.xml entry.

Jira: https://issues.apache.org/jira/browse/BCEL-379

Validation

  • Default mvn: BUILD SUCCESS on macOS with JDK 27.
  • mvn -q verify: passed.
  • mvn -q checkstyle:check: passed after correcting the new fixture header.
  • Independent automated code review found no blocking issue; the reviewer did not run tests.

Contribution checklist

  • Contribution guidelines and ASF generative-tooling guidance checked.
  • AI tooling disclosure: OpenAI Codex assisted with implementation and regression tests; Kiro Claude Opus 5.5 provided an independent automated code review.
  • Default mvn build passed.
  • Added a regression test for the behavior change.
  • Explained the issue, fix, and validation above.

garydgregory added a commit that referenced this pull request Oct 18, 2026
Emit boolean literals so generated creators call
FieldGen.setInitValue(boolean)
and avoid the type mismatch caused by the int overload.

Improve on PR #536 by preserving explicit false ConstantValue
attributes,
which the PR loses during reconstruction. This keeps regenerated fields
usable
as compile-time constants. Also allow false to replace a previous true
value.

Use the low bit for noncanonical integer encodings to match HotSpot
behavior.
Document the fixture's indirect use and generated creator workflow.

Extend tests to cover initializer replacement and cancellation,
noncanonical
encodings, and preservation of boolean ConstantValue attributes. The
PR's
javap comparison alone does not detect missing constant attributes.
@garydgregory

Copy link
Copy Markdown
Member

@AryanRG

Thank you for the fix. The reported bug is real, and emitting boolean literals resolves the generated creator’s runtime failure.

Closing this PR in favor of commit 7fc6cd4f, which incorporates that fix and addresses additional round-trip correctness issues:

  • Preserves explicit false ConstantValue attributes, keeping regenerated fields usable as compile-time constants.
  • Allows false to replace an existing true initializer.
  • Matches HotSpot’s low-bit handling of noncanonical integer encodings.
  • Adds tests for initializer assignment, replacement, cancellation, and preservation of constant attributes. The existing javap -p -c comparison does not detect missing ConstantValue attributes.

You are credited in changes.xml.

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