Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing to create decorator bean on interface with overloaded methods #29230

Closed
drmalex07 opened this issue Nov 13, 2022 · 2 comments · Fixed by #29386
Closed

Failing to create decorator bean on interface with overloaded methods #29230

drmalex07 opened this issue Nov 13, 2022 · 2 comments · Fixed by #29386
Labels
area/arc Issue related to ARC (dependency injection) kind/bug Something isn't working
Milestone

Comments

@drmalex07
Copy link

drmalex07 commented Nov 13, 2022

Describe the bug

I am trying to create a simple CDI decorator on an interface with multiple methods. Some of the interface methods are overloaded.

We have an interface like:

public interface FooService {
    Foo findById(int id);
    Foo findById(String idAsString); // overload with a String argument
}

And a decorator like:

@Priority(100)
@Decorator
public class SomeFooServiceDecorator implements FooService {
   @Inject @Any @Delegate FooService delegate;
   // ... implement interface methods ... //
}

And finally, a bean class like:

@ApplicationScoped
public class DefaultFooService implements FooService {
   // ... implement interface methods ... //
}

Expected behavior

Expected a FooService bean to be created as a SomeFooServiceDecorator wrapping (decorating) real service bean of type DefaultFooService.

Actual behavior

Dependency injection fails with NullPointerException errors. The exception trace contains no relevant information on the cause of the error.

A typical exception trace:

[ERROR] Failed to execute goal io.quarkus.platform:quarkus-maven-plugin:2.13.4.Final:build (default) on project hello-decorator: Failed to build quarkus application: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[ERROR] 	[error]: Build step io.quarkus.arc.deployment.ArcProcessor#generateResources threw an exception: java.lang.IllegalStateException: java.util.concurrent.ExecutionException: java.lang.NullPointerException
[ERROR] 	at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:918)
[ERROR] 	at io.quarkus.builder.BuildContext.run(BuildContext.java:281)
[ERROR] 	at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
[ERROR] 	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
[ERROR] 	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
[ERROR] 	at java.base/java.lang.Thread.run(Thread.java:829)
[ERROR] 	at org.jboss.threads.JBossThread.run(JBossThread.java:501)
[ERROR] Caused by: java.util.concurrent.ExecutionException: java.lang.NullPointerException
[ERROR] 	at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
[ERROR] 	at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
[ERROR] 	at io.quarkus.arc.processor.BeanProcessor.generateResources(BeanProcessor.java:322)
[ERROR] 	at io.quarkus.arc.deployment.ArcProcessor.generateResources(ArcProcessor.java:565)
[ERROR] 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR] 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR] 	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[ERROR] 	at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:909)
[ERROR] 	... 6 more
[ERROR] Caused by: java.lang.NullPointerException
[ERROR] 	at io.quarkus.gizmo.BytecodeCreatorImpl.allocateLocalVariables(BytecodeCreatorImpl.java:1202)
[ERROR] 	at io.quarkus.gizmo.MethodCreatorImpl.write(MethodCreatorImpl.java:122)
[ERROR] 	at io.quarkus.gizmo.ClassCreator.writeTo(ClassCreator.java:202)
[ERROR] 	at io.quarkus.gizmo.ClassCreator.close(ClassCreator.java:225)
[ERROR] 	at io.quarkus.arc.processor.SubclassGenerator.generate(SubclassGenerator.java:127)
[ERROR] 	at io.quarkus.arc.processor.BeanProcessor$4$2.call(BeanProcessor.java:289)
[ERROR] 	at io.quarkus.arc.processor.BeanProcessor$4$2.call(BeanProcessor.java:286)
[ERROR] 	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[ERROR] 	... 5 more

How to Reproduce?

A reproducer project is available at:
https://github.com/drmalex07/reproducer-for-arc-bug-on-decorator

Just run Maven build (mvn package -DskipTests)

Output of uname -a or ver

Linux optiplex 4.9.0-15-amd64 #1 SMP Debian 4.9.258-1 (2021-03-08) x86_64 GNU/Linux

Output of java -version

openjdk version "11.0.14" 2022-01-18 OpenJDK Runtime Environment GraalVM CE 22.0.0.2 (build 11.0.14+9-jvmci-22.0-b05) OpenJDK 64-Bit Server VM GraalVM CE 22.0.0.2 (build 11.0.14+9-jvmci-22.0-b05, mixed mode, sharing)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.13.4

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

Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0) Maven home: /home/malex/opt/apache-maven-3.8.5 Java version: 11.0.14, vendor: GraalVM Community, runtime: /home/malex/opt/graalvm-ce-java11-22.0.0.2 Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "4.9.0-15-amd64", arch: "amd64", family: "unix"

Additional information

If we rename the overloaded method (e.g findById to findById1), everything works fine and Arc manages to resolve dependencies. But this is not a practical solution as it is very common for interfaces to contain overloaded methods.

@drmalex07 drmalex07 added the kind/bug Something isn't working label Nov 13, 2022
@mkouba mkouba added area/arc Issue related to ARC (dependency injection) and removed triage/needs-triage labels Nov 21, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Nov 21, 2022

/cc @manovotn

@mkouba
Copy link
Contributor

mkouba commented Nov 21, 2022

I can confirm that quarkus fails to generate the intercepted subclass and the NPE thrown from gizmo does not really help. I'll try to investigate the issue and if possible fix the problem in Arc and improve the error handling in gizmo.

mkouba added a commit to mkouba/quarkus that referenced this issue Nov 21, 2022
@quarkus-bot quarkus-bot bot added this to the 2.15 - main milestone Nov 23, 2022
@gsmet gsmet modified the milestones: 2.15 - main, 2.14.2.Final Nov 24, 2022
gsmet pushed a commit to gsmet/quarkus that referenced this issue Nov 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/arc Issue related to ARC (dependency injection) kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants