Repository navigation
Description
We tried the annotation processor (aesh-processor 3.19.2) on the Camel CLI. It has 158 commands, and until now aesh read their annotations at run time. The generated metadata gives the same help and the same parse results as reading the annotations (checked against our help and parse golden files). It also saves time: 13 ms on camel ps (92 → 79 ms) and 33 ms on camel --help (243 → 210 ms). Most of that is the annotation proxies the JDK generates at run time, which the generated code avoids.
To get there we had to patch the processor and change some of our classes. These three things will hit other applications too:
1. A command without a no-arg constructor is rejected
@CommandDefinition(name = "ps", description = "List running integrations")
public class ListProcess implements Command<CommandInvocation> {
public ListProcess(CamelJBangMain main) { ... } // the application creates the instance
}error: Command class must have an accessible no-arg constructor
Applications that create their own command instances, with dependencies passed to the constructor, never call newInstance(): AeshCommandContainerBuilder.create(Command) calls buildFromProvider(provider, command) with the given instance. Every Camel command takes CamelJBangMain. Citrus works around this with a second, empty constructor on each command.
Suggestion: when there is no accessible no-arg constructor, generate the metadata anyway, with a newInstance() that throws UnsupportedOperationException. Maybe also a note (not an error), so create(Class) users know. We tried exactly that (a few lines in validate and CodeGenerator), and it works.
2. Mixin fields that the generated class cannot reach
The generated code reads mixin fields directly, so these do not compile:
-
an
@Optionfield that is package-private, in a mixin class of another package than the command:package org.example.commands; public class DurationMixin { @Option(name = "duration") long duration; // package-private } package org.example.commands.action; public class LogAction implements Command<CommandInvocation> { @Mixin DurationMixin duration; }
LogAction_AeshMetadata.java: duration is not public in org.example.commands.DurationMixin; cannot be accessed from outside package -
a
private@Mixinfield:UpdateRun_AeshMetadata.java: updateMixin has private access in ...UpdateRun
A private @Option field on the command itself works: the processor warns ("requires reflective access at runtime") and goes through the Accessor. Mixin fields could use the same fallback, at least for fields the generated class cannot reach. Even an error from the processor, naming the field, would be better than a compile error in generated code.
3. Subclasses that the generated class cannot reach
@CommandDefinition is @Inherited, so getElementsAnnotatedWith also returns every subclass, including private nested classes in tests:
class CliHelpGoldenTest {
private static class TestMain extends CamelJBangMain { ... } // CamelJBangMain has @CommandDefinition
}CliHelpGoldenTest_TestMain_AeshMetadata.java: CliHelpGoldenTest.TestMain has private access in CliHelpGoldenTest
Suggestion: skip (with a note) classes that the generated metadata class cannot reach: private nested classes, or nested classes of a private class. The lookup walks the class hierarchy anyway, so they would fall back to the provider of their superclass, or to reflection. We now turn the processor off for test compilation (<proc>none</proc>), but other projects may not know why their tests stop compiling.
Context: Camel adds the processor in Camel 4.25.0, after aesh 3.19.2 (where MetadataProviderRegistry.useOnly already took 30-40 ms off the CLI, thank you!). Happy to send a PR for 1, and for the others if that helps.
Drafted by Claude Code on behalf of Claus Ibsen
Activity
davsclaus commentedon Nov 19, 2026
Camel side: https://issues.apache.org/jira/browse/CAMEL-27232 (4.25.0)
Claude Code on behalf of Claus Ibsen
davsclaus commentedon Nov 19, 2026
What we changed for the prototype, for a quick look (against v3.19.2):
1. No no-arg constructor. This is the only part we patched in aesh: drop the error in
AeshAnnotationProcessor.validate, and inCodeGenerator.generategenerate anewInstance()that throws when there is no accessible no-arg constructor:(
hasNoArgConstructoris already computed invalidate, so it could be passed on instead of looking again.)2. Mixin fields. No aesh patch: we made the fields wider in Camel (the 4 mixins' fields
public, the private@Mixinfield package-private). Where we think it goes wrong:CodeGenerator.isPrivateFieldonly checksprivate. A package-private (or protected) field of a mixin in another package than the command is just as unreachable from the generated class, which lives in the command's package. Checking "reachable from the package of the generated class" instead of "private" would send those through the reflective accessor as well.FieldAccessorInfowith amixinFieldName),info.isPrivateis about the option field only. When the option field is reachable but the@Mixinfield on the command is private, the generated setter still writes((Cmd) inst).updateMixin.x(aroundCodeGeneratorline 1364, and the getter and resetter next to it).generateMixinalready handles the private mixin field itself; the option accessors need to do the same.3. Subclasses it cannot reach. No aesh patch: we turned the processor off for our test compilation. A check in
validate(or before it, inprocess) to skip a class that the generated class cannot reach would do it: a private nested class, or a nested class of a private class. Since@CommandDefinitionis@Inherited, every subclass ends up there, also ones that never meant to be commands of their own.With these, plus
MetadataProviderRegistry.useOnly(new InternalCommandMetadataRegistry(), new _AeshMetadataRegistry()), all 158 Camel commands get metadata, and our help and parse golden files are the same as with the annotations.Claude Code on behalf of Claus Ibsen
davsclaus commentedon Nov 19, 2026
An update on point 1: on the Camel side we decided to give our commands a no-arg constructor (the main object is set after creation), so Camel no longer needs point 1, and we can use the released aesh-processor 3.19.2. For points 2 and 3 we make the mixin fields reachable and turn the processor off for our test compilation.
So nothing here blocks Camel any more. We still think all three are worth fixing for other aesh users: an application that passes its own command instances (point 1), or has a mixin in another package (2) or a private nested subclass (3), gets a compile error inside generated code today, which is hard to understand.
Claude Code on behalf of Claus Ibsen
davsclaus commentedon Nov 19, 2026
Thanks Ståle, that's what we did in the end (apache/camel#30386, on top of aesh 3.19.2):
camel pswent from 103 to 90 ms (and from 144 ms before 3.19.2).A small idea: an option to name the generated registry class, e.g.
-AaeshRegistryClass=org.example.MyMetadataRegistry. Today_AeshMetadataRegistrylands in the package of the first command the processor sees, and that package can differ between machines. So we don't reference it. Instead we look upX_AeshMetadataby name, which costs aClass.forNameand a reflective constructor per command. With a fixed name we could register the generated registry and do it with plainnew.Claude Code on behalf of Claus Ibsen
Route unreachable mixin fields through generated reflection (#785)
Allow commands without a no-arg constructor (#785)
Skip generated metadata for inaccessible command types (#785)
Add -AaeshRegistryClass option for a stable generated registry name (#…