Repository navigation
Evaluate expressions in the annotation metadata of intercepted methods that also have placeholders - #14545
Conversation
…s that also have placeholders
The executable method of a proxy is configured with the bean context, which
makes its annotation metadata expression aware, and then with the environment
when the metadata has property placeholders. Configuring the environment
rebuilt the metadata from the method reference and dropped the expression
aware wrapper, so an interceptor read `#{...}` expressions as their literal
text whenever the annotations of the method or of its class also held a
`${...}` placeholder.
The method now remembers the bean context it was configured with and wraps
the environment aware metadata again, so the result is expression aware over
environment aware metadata whichever of the two is configured first.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
…data change - Extract the repeated context build and annotation type lookup of EvaluatedAnnotationMetadataInterceptedSpec into helpers. - Drop an assertion that cannot fail and a block that repeated earlier assertions from the per-invocation arguments feature, and state what the remaining assertions prove. - Rename the parameter of configureEvaluatedExpressions so it no longer shadows the beanContext field. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… write configure(Environment) assigned the environment aware metadata and then wrapped it in the expression aware one, so an invocation running while a proxy instance was built could see the metadata without its expression wrapper. Build the final metadata locally, configure it with the bean context, and assign it once. configure(BeanContext) does the same. Document on the beanContext field why it is kept: the interceptor registry configures the bean context first, getExecutableMethodByIndex the environment first, and the expression aware metadata must wrap the environment aware one in both orders. Cover a prototype bean, whose shared executable method is configured again for every instance, and pin the bean definition path. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…ntercepted metadata spec - An intercepted method with a placeholder evaluates the expression of a parameter annotation, which needs the bean context its configure passes on. - Two contexts over the same compiled classes each resolve their own properties, so the remembered bean context never crosses contexts. - Mark the mixed member feature as characterising a known limitation. - Reword the single assignment comment so it claims no more than the plain field guarantees. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The executable methods of a definition without placeholders or expressions are held in a static field shared by every context in the JVM, and the interceptor registry configures them with each context. Storing the bean context there pinned the last context, even after it was closed. Only configure(Environment) reads the field, and only for placeholder metadata, whose definitions get a copy per bean definition: keep it only then. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Automated review pipelineFour fix commits were pushed to this branch. No high severity finding is left open. Base branchThe branch already contained everything on Existing review conversationsNone on the pull request. Brooks sweep (commit e18af2d)Eight findings, three fixed:
Declined: the Round 1, code quality (commit 2f58ea1)Four findings, all fixed:
Round 2, usabilitySkipped: the diff touches a private inner class of the inject runtime and a test, with no template, copy, API or CLI surface. Round 3, test quality (commit a2f4d99)Six findings, three fixed:
Declined: a latch-based concurrency test (the window is a few instructions wide, so the test could not fail even on the old code); instead the "single write" comment no longer claims more than the non-volatile field guarantees. Also declined: a nested-wrapper assertion that cannot fail ( Round 4, performanceNo findings in the PR. Recorded, pre-existing and out of scope: every proxy build creates a new Round 5, application security (commit d440d16)One low finding, fixed: Round 6, dependencies, build and configurationNo findings: no build file, dependency, workflow or configuration is touched, and the spec compiles only a static in-test source string. Final check
Left for the author
🤖 Generated with Claude Code |
|
dstepanov
left a comment
There was a problem hiding this comment.
The fix is right, and it gives the same layering whichever configure call comes first: expression-aware metadata over environment-aware metadata. Things I checked:
- Methods without placeholders behave as before.
evaluated()is the oldconfigure(BeanContext)body, andbeanContextis only kept when the method has property expressions, so methods without placeholders don't start holding a context. - No new retention. For placeholder methods the old metadata already held the environment, and the
EvaluatedAnnotationMetadataheld the context. KeepingbeanContextadds nothing new. - Environment first, then the context, settles correctly. When a method is configured with the environment and then the context,
configure(Environment)may wrap with the context from an earlierconfigure(BeanContext)(shared definition methods). The followingconfigure(BeanContext)then re-configures the sameEvaluatedAnnotationMetadatawith the current context, so it ends up with the right one. - Tests: the spec covers both
@Aroundmodes, a placeholder in another member, a placeholder on the class, andgetDeclaredMetadata().
CI is green.
Generated by Claude Code



An interceptor reads
#{...}evaluated expressions as their literal text fromcontext.getAnnotationMetadata()when the annotations of the intercepted method, or of its class, also contain a${...}property placeholder. Without any placeholder the expression is evaluated.Reproduction
In the interceptor bound to
@Traced:The same happens when the placeholder is in another member of the same annotation (
@Label(value = "#{ ... }", scope = "${test.scope}")) or in an annotation of the class. Both the full metadata andgetDeclaredMetadata()return the unevaluated value, with@Aroundand with@Around(proxyTarget = true).Cause
The proxy builds its own executable methods and
DefaultInterceptorRegistryconfigures each of them with the bean context first, which wraps the metadata in anEvaluatedAnnotationMetadata, and then with the environment when the metadata has property placeholders.DispatchedExecutableMethod.configure(Environment)rebuilds the metadata from the method reference, so it replaced the expression aware metadata with a bare environment aware one. Nothing wrapped it again, andInterceptorChainfound noEvaluatedAnnotationMetadatato copy with the invocation arguments.Executable methods obtained from the bean definition were not affected:
getExecutableMethodByIndexconfigures the environment first and the bean context second.Changes
DispatchedExecutableMethodremembers the bean context it was configured with.configure(Environment)wraps the environment aware metadata again when a bean context was already configured. The result is expression aware metadata over environment aware metadata, the order the bean definition path already produced, whichever of the two is configured first.The change is internal to
AbstractExecutableMethodsDefinition.InterceptorChainstill takes a copy withwithArgumentsfor each invocation, so arguments stay with their own invocation.Tests
EvaluatedAnnotationMetadataInterceptedSpeccompiles intercepted beans and checks what the interceptor reads from its invocation context, for@Aroundand@Around(proxyTarget = true):Each case asserts that the expression is evaluated, that the placeholder is resolved, and that
findAnnotationandstringValueagree on the full metadata and ongetDeclaredMetadata(). Before the change every case with a placeholder failed.Ran locally, all passing:
:micronaut-inject:test(575 tests),:micronaut-inject-java:testfor the AOP, expression,*EvaluatedAnnotationMetadata*and*EnvironmentAnnotationMetadata*specs (3718 tests),:micronaut-inject-groovy:testfor the AOP specs (309 tests), the AOP, expression and scheduling tests of:test-suite:test(51 tests), and:micronaut-inject:japiCmp.Not changed
A single member that mixes both, such as
"${test.prefix:pre}-#{ 'x' }", is compiled as an expression as a whole: the expression is evaluated and the placeholder is kept as written (${test.prefix:pre}-x). This was already the behaviour and the spec records it.Related: #14466, #14172.
🤖 Generated with Claude Code