Fix overly broad classpath scanning in ReflectUtil.getClassesWithAnnotation()#13427
Fix overly broad classpath scanning in ReflectUtil.getClassesWithAnnotation()#13427vishesh92 wants to merge 2 commits into
Conversation
…tation() 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 <g.mahalingam@apple.com>
|
@blueorangutan package |
|
@vishesh92 a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 4.22 #13427 +/- ##
============================================
+ Coverage 17.67% 17.69% +0.01%
- Complexity 15792 15832 +40
============================================
Files 5922 5925 +3
Lines 533167 533537 +370
Branches 65210 65273 +63
============================================
+ Hits 94246 94416 +170
- Misses 428276 428440 +164
- Partials 10645 10681 +36
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 18273 |
|
@blueorangutan test |
|
@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
|
[SF] Trillian test result (tid-16355)
|
|
@blueorangutan package |
|
@vishesh92 a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 18427 |
|
@blueorangutan test |
|
@vishesh92 a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
|
[SF] Trillian test result (tid-16455)
|
|
@blueorangutan package |
|
@nvazquez a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 18576 |
|
@blueorangutan test |
|
@nvazquez a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
|
[SF] Trillian test result (tid-16580)
|
|
@blueorangutan package |
|
@vishesh92 a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 18621 |
|
@blueorangutan test |
|
@vishesh92 a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
|
@blueorangutan test |
|
@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
|
[SF] Trillian test result (tid-16589)
|
|
[SF] Trillian test result (tid-16595)
|
There was a problem hiding this comment.
Pull request overview
This PR tightens ReflectUtil.getClassesWithAnnotation() so Reflections only scans class files that belong to the requested package prefixes, avoiding overly broad classpath scanning that can trigger noisy startup warnings (e.g., missing optional Conscrypt types referenced by unrelated Netty classes) and reducing startup scan time.
Changes:
- Add an input filter (
FilterBuilder.includePackage(...)) to limit Reflections bytecode scanning to the requested packages. - Extend the package list used by
ApiXmlDocWriterwhen discovering@APICommandclasses.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| utils/src/main/java/com/cloud/utils/ReflectUtil.java | Restricts Reflections input scanning to requested packages via FilterBuilder, reducing unrelated class scanning and warnings. |
| server/src/main/java/com/cloud/api/doc/ApiXmlDocWriter.java | Expands the list of packages searched for @APICommand implementations during API doc generation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public static Set<Class<?>> getClassesWithAnnotation(Class<? extends Annotation> annotation, String[] packageNames) { | ||
| Reflections reflections; | ||
| Set<Class<?>> classes = new HashSet<Class<?>>(); | ||
| 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()); |
|
@blueorangutan package |
|
@vishesh92 a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 18643 |
|
@blueorangutan test |
|
@vishesh92 a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
|
[SF] Trillian test result (tid-16603)
|
DaanHoogland
left a comment
There was a problem hiding this comment.
one worry, otherwise clgtm
| "org.apache.cloudstack.api.command.admin.zone", "org.apache.cloudstack.network.contrail.api.command", | ||
| "org.apache.cloudstack.cloudian.api", "org.apache.cloudstack.framework.extensions.api", | ||
| "org.apache.cloudstack.mom.webhook.api.command.user", "org.apache.cloudstack.network.tungsten.api.command", | ||
| "org.apache.cloudstack.oauth2.api.command", "org.apache.cloudstack.storage.datastore.util"}); |
There was a problem hiding this comment.
is this going to be maintenance hog, when people add plugins?
There was a problem hiding this comment.
IMO, small change. Similar to what we do currently for ./tools/apidoc/gen_toc.py.
Description
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.
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?
How did you try to break this feature and the system with this change?