Class DiscoveryIndexSupport

java.lang.Object
tech.guilhermekaua.spigotboot.core.context.discovery.DiscoveryIndexSupport

public final class DiscoveryIndexSupport extends Object
Runtime support for the 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 Details

    • resolve

      public static Class<?>[] resolve(@NotNull @NotNull ClassLoader classLoader, String... classNames)
      Resolves the given class names with classLoader, skipping any that cannot be loaded or linked. The class is loaded but not initialized, matching the behavior of a .class literal.
      Parameters:
      classLoader - the class loader to resolve names with; never null
      classNames - the fully qualified names of the discovered classes; may be empty, and null/blank entries are ignored
      Returns:
      the successfully resolved classes, in the order given, with unresolvable names omitted; never null
      Throws:
      NullPointerException - if classLoader is null