From 34649c85c88e67ab28ebf5d2c96c3d864f756570 Mon Sep 17 00:00:00 2001 From: Ganesh Maharaj Mahalingam Date: Fri, 3 Apr 2026 20:24:44 -0700 Subject: [PATCH] Fix overly broad classpath scanning in ReflectUtil.getClassesWithAnnotation() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Production logs show a recurring WARN at startup: "could not get type for name org.conscrypt.AllocatedBuffer" (org.reflections.ReflectionsException / ClassNotFoundException) Root cause: ReflectUtil.getClassesWithAnnotation() uses ClasspathHelper.forPackage() to collect URLs to scan, but this returns all classpath entries (JARs/directories), not just those containing the target package. The Reflections library then scans every .class file in every JAR — including Netty's ConscryptAlpnSslEngine$BufferAdapter which references the optional org.conscrypt.AllocatedBuffer type. During expandSuperTypes(), Reflections tries Class.forName() on that type and fails because Conscrypt is not (and need not be) on the classpath. The fix adds a FilterBuilder that restricts bytecode scanning to only classes whose fully-qualified names match the requested packages. This prevents Reflections from processing unrelated classes (e.g., io.netty.handler.ssl.*), eliminating the warning and reducing startup time by skipping thousands of irrelevant class files. Signed-off-by: Ganesh Maharaj Mahalingam --- utils/src/main/java/com/cloud/utils/ReflectUtil.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/utils/src/main/java/com/cloud/utils/ReflectUtil.java b/utils/src/main/java/com/cloud/utils/ReflectUtil.java index 5b40d48c20e2..bf11cea22cce 100644 --- a/utils/src/main/java/com/cloud/utils/ReflectUtil.java +++ b/utils/src/main/java/com/cloud/utils/ReflectUtil.java @@ -42,6 +42,7 @@ import org.reflections.scanners.TypeAnnotationsScanner; import org.reflections.util.ClasspathHelper; import org.reflections.util.ConfigurationBuilder; +import org.reflections.util.FilterBuilder; import com.cloud.utils.exception.CloudRuntimeException; import com.google.common.collect.ImmutableSet; @@ -70,9 +71,12 @@ public static Set> getClassesWithAnnotation(Class Reflections reflections; Set> classes = new HashSet>(); ConfigurationBuilder builder=new ConfigurationBuilder(); + FilterBuilder filterBuilder = new FilterBuilder(); for (String packageName : packageNames) { builder.addUrls(ClasspathHelper.forPackage(packageName)); + filterBuilder.includePackage(packageName); } + builder.filterInputsBy(filterBuilder); builder.setScanners(new SubTypesScanner(),new TypeAnnotationsScanner()); reflections = new Reflections(builder); classes.addAll(reflections.getTypesAnnotatedWith(annotation));