Skip to content

Implement features from CDI Alpha4 release#3332

Open
manovotn wants to merge 10 commits intoweld:masterfrom
manovotn:implementCdiAlpha4
Open

Implement features from CDI Alpha4 release#3332
manovotn wants to merge 10 commits intoweld:masterfrom
manovotn:implementCdiAlpha4

Conversation

@manovotn
Copy link
Copy Markdown
Member

A work in progress in implementing latest parts of CDI API.

Update `weld.api.version` to 7.0.Alpha5 and `cdi.tck.version` to
5.0.0.Alpha3. Add no-op stubs for new CDI 5.0 API methods to restore
compilation:
- `BeanAttributesConfigurator.eager(boolean)`
- `BeanConfigurator.eager(boolean)`
- `AfterDeploymentValidation.ensureAsyncHandlerExists()`
- `BeanInfo.isEager()`
- `StereotypeInfo.isEager()`
- `SyntheticBeanBuilder.eager(boolean)`
@manovotn manovotn changed the title Implement cdi alpha4 Implement features from CDI Alpha4 release Apr 14, 2026
@manovotn
Copy link
Copy Markdown
Member Author

manovotn commented Apr 14, 2026

The CI TCK failure is unfortunately correct in some artifacts are missing from the release, see also jakartaee/cdi#946 (comment).

I ended up reverting TCKs to the previous Alpha version for now.
All of the features implemented in this PR will have its own tests, akin to those that are in the TCKs.

When `Instance` is obtained programmatically via
`BeanContainer.createInstance()` and no qualifiers are specified,
`DynamicLookupInjectionPoint.getQualifiers()` now returns
`@Default` instead of an empty set.

This aligns with the CDI 5.0 spec clarification (issue weld#779) that
`@Default` is implied when no qualifiers are selected.
@manovotn manovotn force-pushed the implementCdiAlpha4 branch from b6d434d to cab86ed Compare April 14, 2026 17:19
`@Registration(types = ...)` now supports `TypeLiteral` subclasses
to specify parameterized registration types. For example,
`@Registration(types = MyTypeLiteral.class)` where
`MyTypeLiteral extends TypeLiteral<MyService<String>>` will match
beans whose types include `MyService<String>`.

Changes in `ExtensionPhaseRegistration`:
- Resolve `TypeLiteral` subclasses to their actual type argument
- Validate against raw `TypeLiteral` and type variables

Changes in `ExtensionPhaseRegistrationAction`:
- Accept `Set<Type>` instead of `Set<Class<?>>`
- Bean matching: raw type comparison for `Class`, exact match for
  parameterized types
- Observer matching: raw assignability for `Class`, type closure
  check for parameterized types
@manovotn manovotn force-pushed the implementCdiAlpha4 branch 3 times, most recently from 840adea to 8a551c7 Compare April 15, 2026 08:02
  Add `AsyncHandler` discovery and integration into the invoker
  chain. When a method's return type or parameter type matches a
  registered async handler, dependent bean cleanup is deferred until
  the async operation completes.

  Built-in `@ReturnType` handlers are provided for `CompletionStage`,
  `CompletableFuture`, and `Flow.Publisher`.

  Key changes:
  - `AsyncHandlerRegistry` as a deployment-level `Service` in the
    `ServiceRegistry`, shared across all BeanManagers
  - `AsyncInvokerImpl` applies async handler's `transform()` with
    deferred cleanup for both `@ReturnType` and `@ParameterType`
  - `CleanupActions` deferred variants store the instance in a
    ThreadLocal instead of running cleanup on success
  - `AfterDeploymentValidation.ensureAsyncHandlerExists()` and
    `InvokerValidation` support in the lite extension translator
The 5.0.0.Alpha3 release did not publish all artifacts correctly,
causing dependency resolution failures for the TCK runner module.
  `@ApplicationScoped` beans annotated with `@Eager` (or with a
  stereotype declaring `@Eager`) are now eagerly initialized during
  container startup, before the `Startup` event is fired. Eager beans
  are collected during `addBean()` for efficient startup init.

  Key changes:
  - `ImmutableBeanAttributes`: new `eager` field and `isEager()`
  - `BeanAttributesFactory` / `ExternalBeanAttributesFactory`: detect
    and preserve `@Eager` on beans, producers, and extension-provided
    `BeanAttributes`
  - `StereotypeModel` / `MergedStereotypes`: support `@Eager` via
    stereotypes, including inherited stereotypes
  - `BeanAttributesConfiguratorImpl` / `BeanConfiguratorImpl`:
    real `eager(boolean)` implementation
  - `ForwardingBeanAttributes`: delegate `isEager()`
  - `Validator`: `@Eager` on non-`@ApplicationScoped` is a
    `DefinitionException`
  - `BeanManagerImpl`: collect eager beans during `addBean()`
  - `WeldStartup`: instantiate collected eager beans in
    `endInitialization()` before the `Startup` event
  - Lite extension translator: `BeanInfo.isEager()`,
    `StereotypeInfo.isEager()`, and `SyntheticBeanBuilder.eager()`
Cleanup of invoker and lite extension translator modules to ensure
all exceptions go through Logger interfaces instead of being
thrown directly.
@manovotn manovotn force-pushed the implementCdiAlpha4 branch from 8a551c7 to e80b31e Compare April 15, 2026 12:24
Added a test using a @singleton stereotype to verify eager
initialization works for singleton beans.
@manovotn
Copy link
Copy Markdown
Member Author

Keeping it as draft a while longer as I also need to implement the synthetic injection points from the latest CDI API release.

…ctions

Bump Weld API to 7.0.Alpha6. Implement the new CDI 5.0 API for
declaring and validating injection points on synthetic beans.
@manovotn manovotn force-pushed the implementCdiAlpha4 branch from bb2362f to e05d8ce Compare April 16, 2026 17:17
@manovotn
Copy link
Copy Markdown
Member Author

manovotn commented Apr 17, 2026

Keeping it as draft a while longer as I also need to implement the synthetic injection points from the latest CDI API release.

These are now implemented as well, moving out of draft state.

@manovotn manovotn marked this pull request as ready for review April 17, 2026 09:11
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.

1 participant