Skip to content

Keep the initializer of a primitive option field across resets (#697) - #710

Closed
davsclaus wants to merge 1 commit into
aeshell:masterfrom
davsclaus:primitive-initial-value
Closed

davsclaus wants to merge 1 commit into
aeshell:masterfrom
davsclaus:primitive-initial-value

Conversation

@davsclaus

Copy link
Copy Markdown
Contributor

Fixes #697

ProcessedOption.captureInitialValue (and its GeneratedProcessedOption override) skipped primitive fields. resetField then fell back to the type default, so a primitive field lost its initializer whenever the option was not given:

@Option(hasValue = false) boolean global = true;   // was false
@Option int port = -1;                              // was 0

Object fields already keep their initializer (#392). This change captures primitive values as well, so they are restored in the same way. The reflection path, the generated path and @Mixin fields are all covered. A primitive whose initializer equals the type default (false, 0) still gets that same value.

Tests:

  • AeshCommandRuntimeTest.testInitializedPrimitivesResetToInitialValue covers boolean, int, long and a mixin int: first parse without options, then with them, then without them again.
  • ProcessorTest.testPrimitiveInitializers covers the generated (annotation processor) path.

Both tests fail without the fix. The full aesh and aesh-processor suites pass (1597 + 97 tests).

Found while porting the Apache Camel CLI from picocli to aesh (CAMEL-23810), tracked in #709.

Claude Code on behalf of davsclaus (Claus Ibsen)

🤖 Generated with Claude Code

…ll#697)

captureInitialValue skipped primitive fields, so resetField set them to
the type default: boolean global = true became false and int port = -1
became 0 when the option was not given. Object fields already kept their
initializer (aeshell#392). Capture primitives too, in the reflection and the
generated path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
@stalep

stalep commented Nov 2, 2026

Copy link
Copy Markdown
Member

Bah, really sorry @davsclaus. I did not notice this pr before I had worked and pushed a fix myself. Really sorry!

@stalep stalep closed this Nov 2, 2026
@davsclaus

Copy link
Copy Markdown
Contributor Author

No problem @stalep - just glad you are are active on this project and are willing to look into reports and do releases.

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.

The starting value of a primitive option field is lost (boolean x = true becomes false)

2 participants