Class DiscoveryIndexSupport
DiscoveryIndex implementations emitted by the
DiscoveryIndexProcessor. Generated indexes list their discovered classes as fully
qualified names and resolve them through resolve(ClassLoader, String...) instead
of referencing them with eager .class literals.
This is what keeps an optional dependency from poisoning discovery: a discovered class may
extend or implement a type supplied only by a soft dependency (for example PAPIExpansion,
whose supertype me.clip.placeholderapi.expansion.PlaceholderExpansion is absent unless
PlaceholderAPI is installed). Loading such a class throws NoClassDefFoundError. Resolving
names one at a time and skipping the failures means only the unavailable class is dropped, while
every other class in the same index still loads. This mirrors the resilience the runtime
classpath-scanning fallback already has (see ClassPathScanner and ModuleDiscovery).
The .class literals required so the Maven Shade Plugin's minimizeJar reachability
analyzer retains discovered classes are emitted separately, in a never-invoked method on the
generated index, so they are present in the bytecode without ever being linked at runtime.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Class<?>[]resolve(@NotNull ClassLoader classLoader, String... classNames) Resolves the given class names withclassLoader, skipping any that cannot be loaded or linked.
-
Method Details
-
resolve
Resolves the given class names withclassLoader, skipping any that cannot be loaded or linked. The class is loaded but not initialized, matching the behavior of a.classliteral.- Parameters:
classLoader- the class loader to resolve names with; nevernullclassNames- the fully qualified names of the discovered classes; may be empty, andnull/blank entries are ignored- Returns:
- the successfully resolved classes, in the order given, with unresolvable names omitted;
never
null - Throws:
NullPointerException- ifclassLoaderisnull
-