Skip to content

Decorator for default methods of decorated types not being called #46721

@slinstaedt-hlag

Description

@slinstaedt-hlag

Describe the bug

First: I am aware, quarkus is an implementation of CDI light, but not CDI full. Nevertheless it provides some functionalities of CDI full, like decorators, which I would expect to work like specified in CDI full.

We discovered actually some corner cases, where quarkus' implementation of CDI decorators actually behaves differently (in terms of not failing with an exception, but interpreting the spec differently) from other CDI implementations: If a bean has a bean type being an interface with default methods, which the bean itself does not override, any applied decorator for that bean type that override that method is never getting called but any calls are directly delegated to the interface's default method. If the bean overrides these default method (even if it just delegates it's calls to interface's default method), the decorator is getting called as expected.

As CDI light is not mentioning anything regarding decoration behaviour, I am referring to the CDI full spec of decotors:

The decorator intercepts every method which is declared by a decorated type of the decorator and is implemented by the bean class of the decorator.

From my interpretation, that reads like: If an interface declares a method (independently of being abstract or concrete) and an decorator class implements this method, the decorator is getting called for invocations of this method. The spec does not mention any differentiation between abstract and default methods.

Expected behavior

You can imagine I was somehow surprised when changing some interface's abstract methods to default ones (e.g. to remove duplications in implementing classes), that some decorations did not get applied any more, especially if these decorations are security relevant. I have silently assumed that decoration works, like in other CDI implementations and also programmatically applied DIY GoF decorator pattern.

Actual behavior

Calls to default methods of decorated bean types, which are not overridden by the decorated bean itself, are not getting decorated, but directly delegated to the default method's implementation.

How to Reproduce?

No response

Output of uname -a or ver

Linux NHH43414 5.15.167.4-microsoft-standard-WSL2 #1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

Java version: 21.0.6, vendor: Ubuntu, runtime: /usr/lib/jvm/java-21-openjdk-amd64

Quarkus version or git rev

3.19.2

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.9.9

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/arcIssue related to ARC (dependency injection)kind/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions