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

Unindexed qualifier throws NPE when ArcProcessor validates beans #41371

Closed
scrocquesel opened this issue Jun 23, 2024 · 3 comments · Fixed by #41514
Closed

Unindexed qualifier throws NPE when ArcProcessor validates beans #41371

scrocquesel opened this issue Jun 23, 2024 · 3 comments · Fixed by #41514
Labels
area/arc Issue related to ARC (dependency injection) kind/bug Something isn't working
Milestone

Comments

@scrocquesel
Copy link
Contributor

scrocquesel commented Jun 23, 2024

Describe the bug

Don't know if this expected but the experience may be improved as it is the second time I lost some time finding out what was going on.

I was trying to register two synthetic beans SqsClientBuilder and SqsClient . The second one having an injection point of the first one with a custom qualifier. Both beans have a custom qualifier. Those qualifiers were not register as per documented https://quarkus.io/guides/cdi-integration#use-case-my-annotation-is-not-recognized-as-a-qualifier-or-an-interceptor-binding.

I got an NPE because requiredClazz is null here for the first qualifier.

if (!requiredClazz.method(val.name()).hasAnnotation(DotNames.NONBINDING)

java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
        [error]: Build step io.quarkus.arc.deployment.ArcProcessor#validate threw an exception: java.lang.NullPointerException: Cannot invoke "org.jboss.jandex.ClassInfo.method(String, org.jboss.jandex.Type[])" because "requiredClazz" is null
        at io.quarkus.arc.processor.Beans.hasQualifier(Beans.java:684)

Expected behavior

No NPE and as much as possible, a meaningfull error message.

Actual behavior

Inspecting beanDeployment.beanArchiveImmutableIndex, it contains only the qualifier of the second bean, so something seems to have added it automatically (maybe because it is used in the app project), but not the required one.
If hasQualifier return false when requiredClazz is null, then, I have an more descriptive error but it is still meaningless.

Caused by: jakarta.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type software.amazon.awssdk.services.sqs.SqsClientBuilder and qualifiers [@io.quarkus.amazon.common.AmazonClientBuilder("test")]
        - synthetic injection point
        - declared on SYNTHETIC bean [types=[software.amazon.awssdk.services.sqs.SqsClient, java.lang.Object], qualifiers=[@Any, @io.quarkus.amazon.common.AmazonClient("test")], target=n/a]
        The following beans match by type, but none has matching qualifiers:
        - SYNTHETIC bean [types=[java.lang.Object, software.amazon.awssdk.services.sqs.SqsClientBuilder], qualifiers=[@io.quarkus.amazon.common.AmazonClientBuilder("test"), @Any], target=n/a]
        - SYNTHETIC bean [types=[java.lang.Object, software.amazon.awssdk.services.sqs.SqsClientBuilder], qualifiers=[@Default, @Any], target=n/a]

I'm wondering why io.quarkus.amazon.common.AmazonClient is a known qualifier and io.quarkus.amazon.common.AmazonClientBuilder is not.
Why ArcProcessor knows about the qualifier as the error message shows it and we still need to register the annotation manually for AdditionalBeanBuildItem.
Could it be possible to add a message when requiredClazz is null that tells that a qualifier should be registered manually ?

How to Reproduce?

No response

Output of uname -a or ver

No response

Output of java -version

No response

Quarkus version or git rev

3.11

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

No response

Additional information

No response

@scrocquesel scrocquesel added the kind/bug Something isn't working label Jun 23, 2024
@mkouba mkouba added area/arc Issue related to ARC (dependency injection) and removed triage/needs-triage labels Jun 24, 2024
Copy link

quarkus-bot bot commented Jun 24, 2024

/cc @Ladicek (arc), @manovotn (arc)

@manovotn
Copy link
Contributor

Inspecting beanDeployment.beanArchiveImmutableIndex, it contains only the qualifier of the second bean, so something seems to have added it automatically (maybe because it is used in the app project), but not the required one.

Arc does some best effort to automatically add encountered missing classes to the index if they are used by beans which might be the case here. Hard to say without a reproducer, but assuming both qualifiers reside in the same project, that would be my guess.

Why ArcProcessor knows about the qualifier as the error message shows it and we still need to register the annotation manually for AdditionalBeanBuildItem.

It only knows of its DotName representation but the actual class isn't present in the index - think of it as knowing the String representation of the class but not having access to the actual Class reference.

Could it be possible to add a message when requiredClazz is null that tells that a qualifier should be registered manually ?

We could add a null check with an exception saying it has not been indexed although the cause for that isn't necessarily missing manual registration so the message would have to be more broad.

@Ladicek
Copy link
Contributor

Ladicek commented Jun 26, 2024

I think we should add a null check here, but I keep wondering if there's more places like this that could use a null check as well...

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.

5 participants