gnodet-bot commented on code in PR #31223:
URL: https://github.com/apache/camel/pull/31223#discussion_r4765230749


##########
components/camel-jandex/src/main/java/org/apache/camel/jandex/JandexPackageScanClassResolver.java:
##########
@@ -115,37 +149,19 @@ private void findByAnnotation(Class<? extends Annotation> 
c, Set<Class<?>> class
         }
     }
 
-    private void findBySubClass(Class<?> c, Set<Class<?>> classes) {
+    private static void addCandidate(ClassInfo ci, Set<String> names) {
+        // annotation types are abstract, so they are skipped too
+        if (ci.nestingType() == ClassInfo.NestingType.TOP_LEVEL && 
!ci.isAbstract()) {
+            names.add(ci.name().toString());
+        }
+    }
+
+    private void findBySubClass(Class<?> c, Set<String> names) {
         for (Index index : indexes) {
-            if (c.isInterface()) {
-                for (var ai : index.getAllKnownImplementations(c)) {
-                    if (!ai.asClass().isAbstract()) {
-                        String currentClass = ai.asClass().name().toString();
-                        for (ClassLoader cl : getClassLoaders()) {
-                            try {
-                                Class<?> clazz = cl.loadClass(currentClass);
-                                classes.add(clazz);
-                                break;
-                            } catch (ClassNotFoundException e) {
-                                // ignore
-                            }
-                        }
-                    }
-                }
-            } else {
-                for (var ai : index.getAllKnownSubclasses(c)) {
-                    if (!ai.isAbstract()) {
-                        String currentClass = ai.asClass().name().toString();
-                        for (ClassLoader cl : getClassLoaders()) {
-                            try {
-                                Class<?> clazz = cl.loadClass(currentClass);
-                                classes.add(clazz);
-                                break;
-                            } catch (ClassNotFoundException e) {
-                                // ignore
-                            }
-                        }
-                    }
+            var found = c.isInterface() ? index.getAllKnownImplementations(c) 
: index.getAllKnownSubclasses(c);
+            for (ClassInfo ci : found) {
+                if (!ci.isAbstract()) {

Review Comment:
   `findBySubClass` still checks only `!ci.isAbstract()` while `addCandidate()` 
— used for all annotation paths — enforces both `nestingType() == TOP_LEVEL && 
!ci.isAbstract()`. A concrete nested class that extends the target type would 
be collected by this path and then passed to `addIfMatching`, which loads it as 
a candidate. Concrete nested classes excluded in the annotation path would 
appear in the subclass path — an observable inconsistency.
   
   Replace the predicate to use `addCandidate` for the same filter as the 
annotation paths:
   
   ```suggestion
               var found = c.isInterface() ? 
index.getAllKnownImplementations(c) : index.getAllKnownSubclasses(c);
               for (ClassInfo ci : found) {
                   addCandidate(ci, names);
               }
   ```



-- 
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]

Reply via email to