question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CDI events qualifiers not working when abstract superclass is in a library

See original GitHub issue

Describe the bug

CDI events qualifiers are not working well when abstract superclass is in a library since when implementing the class it will be registered as a general observer instead of one with a qualifier. Check https://github.com/MarcoMartins86/event_qualifier_issue for more details.

Expected behavior

If I trigger an important event http://localhost:8080/Events/Important should appear:

Library AbstractObserverImportantEvent: Important event message 0 Event qualifiers[[@org.acme.ImportantEvent(), @javax.enterprise.inject.Any()]]
Runner ImportantEventImpl: Important event message 0

Actual behavior

If I trigger an important event http://localhost:8080/Events/Important appears:

Library AbstractObserverNormalEvent: Important event message 0 Event qualifiers[[@org.acme.ImportantEvent(), @javax.enterprise.inject.Any()]]
Runner NormalEventImpl: Important event message 0
Library AbstractObserverImportantEvent: Important event message 0 Event qualifiers[[@org.acme.ImportantEvent(), @javax.enterprise.inject.Any()]]
Runner ImportantEventImpl: Important event message 0

To Reproduce

A project that reproduces this https://github.com/MarcoMartins86/event_qualifier_issue

Steps to reproduce the behavior:

  1. make
  2. Do GET to http://localhost:8080/Events/Important
  3. Check the command line for the prints

Environment (please complete the following information):

Output of uname -a or ver

Darwin PT-320323-MBP16 20.2.0 Darwin Kernel Version 20.2.0: Wed Dec 2 20:39:59 PST 2020; root:xnu-7195.60.75~1/RELEASE_X86_64 x86_64

Output of java -version

java version “11.0.9” 2020-10-20 LTS Java™ SE Runtime Environment 18.9 (build 11.0.9+7-LTS) Java HotSpot™ 64-Bit Server VM 18.9 (build 11.0.9+7-LTS, mixed mode)

GraalVM version (if different from Java)

Quarkus version or git rev

1.12.2.Final

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

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: /usr/local/Cellar/maven/3.6.3_1/libexec Java version: 11.0.9, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-11.0.9.jdk/Contents/Home Default locale: en_PT, platform encoding: UTF-8 OS name: “mac os x”, version: “10.16”, arch: “x86_64”, family: “mac”

Additional context

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mkoubacommented, Mar 19, 2021

I can confirm that it’s a bug.

The Jandex MethodParameterInfo does not implement equals()/hashCode() and for some reason we receive two distinct target instances for the @Observes and @NormalEvent annotations declared on the event param of AbstractObserverNormalEvent.observer().

I’ll prepare a fix next Monday.

0reactions
mkoubacommented, Mar 20, 2021

@MarcoMartins86 FYI the problem only occurs if an observer method is declared on a class located in an archive with a pregenerated Jandex index (e.g. via the jandex-maven-plugin).

Read more comments on GitHub >

github_iconTop Results From Across the Web

25.5 Using Events in CDI Applications
25.5.1 Defining Events. An event consists of the following: The event object, a Java object. Zero or more qualifier types, the event qualifiers....
Read more >
Cdi Producer Not Recognized with Qualifiers Java - ADocLib
CDI events qualifiers are not working well when abstract superclass is in a library since when implementing the class it will be registered....
Read more >
Contexts and Dependency Injection - Quarkus
This behavior is defined by CDI. But producer methods and fields and observer methods are discovered even if the declaring class is not...
Read more >
JSR 365: Contexts and Dependency Injection for Java 2.0
The container inspects the qualifier annotations and type of the injected attribute to determine the bean instance to be injected, according to the...
Read more >
Chapter 7. Contexts and Dependency Injection (CDI)
An event is not fired for any type annotated with @Vetoed , or in a package ... Qualifiers are annotations used to avoid...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found