ammachado opened a new pull request, #31223: URL: https://github.com/apache/camel/pull/31223
# Description [CAMEL-28005](https://issues.apache.org/jira/browse/CAMEL-28005): `JandexPackageScanClassResolver.find` ignored the package name and never called `test.matches`, so `findAnnotated` / `findImplementations("org.foo")` returned the matching classes of every package in every `jandex.idx`. It also only understood the `AnnotatedWith`, `AnnotatedWithAny` and `AssignableTo` filters. Any other filter found nothing, and so did `findAnnotated` / `findImplementations` once a filter was registered with `addFilter`, because the parent then passes a `CompositePackageScanFilter`. **Commit 1: the ticket** - The index lookups now only pick candidate class names. For any other filter (composite, inverting, custom `findByFilter`), every indexed class is a candidate. - Candidates outside the package or its subpackages are skipped. The prefix ends with a `.`, so `org.foo` does not match `org.foobar`. - The remaining candidates are loaded with the inherited `addIfMatching`, which keeps a class only when the filter matches. This also replaces three copies of the class loader loop. **Commit 2: gaps found while investigating** - The classpath scan that the index replaces matches an annotation through a meta annotation (one level deep) and on subclasses when the annotation is `@Inherited`. The index lookup only saw direct annotations, so it missed those classes. `findByAnnotation` now collects both. - The resolver overrode the `find` that the parent calls once per class loader, while ignoring the loader, so it repeated the index walk for each loader. It now overrides the `find` that runs once per package. - `jandex.adoc` (and the catalog copy) gets a "Limitations" section: only indexed JARs are scanned, and annotation and subclass lookups keep their existing restriction to top-level, non-abstract classes. That restriction differs from the classpath scan, which also returns abstract classes and annotation types. **Impact.** No code in this repository selects this resolver: it only runs when a user installs it as the `PackageScanClassResolver` plugin. With it installed, the Camel CLI bean scans in `BasePackageScanDownloadListener` (Spring `@Component`/`@Service`, Quarkus `@ApplicationScoped`/`@Singleton` through `findByFilter`) found nothing before this change and work now. No upgrade guide entry: the resolver now does what the `PackageScanClassResolver` contract says. **Tests.** These are the module's first tests. `JandexPackageScanClassResolverTest` writes a `jandex.idx` of fixture classes into a `@TempDir`, exposed through a `URLClassLoader` as the application context class loader, so the test does not depend on other indexes on the classpath. It covers: - the package scope for annotated, annotated-any and implementations lookups, including a subpackage and a sibling package that shares the name prefix; - a custom `findByFilter` filter; - `addFilter`, which produces the composite filter; - meta annotations and `@Inherited` annotations, checked against the same query on `DefaultPackageScanClassResolver`. All 7 pass. Against the original resolver, the first 5 fail; against commit 1, only the 2 meta/`@Inherited` tests fail. Each failure is the bug it targets: the sibling package leaks into the result, or the result is empty. # Target - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch) # Tracking - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it). # Apache Camel coding standards and style - [x] I checked that each commit in the pull request has a meaningful subject line and body. - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes. Not run from the root folder. I ran `mvn formatter:format impsort:sort install` in `components/camel-jandex`, which left no uncommitted changes, and copied the edited `jandex.adoc` to `catalog/camel-catalog/.../docs/jandex.adoc` (the two files were identical before the change). # AI-assisted contributions - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used. 🤖 Generated with [Claude Code](https://claude.com/claude-code) on behalf of Adriano Machado (@ammachado) _This was generated by an AI agent and may contain inaccuracies. Please verify before relying on it._ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
