I haven't spotted a problem with the `#runtimeAvailable` method; it's actually the `#decoder(String)` method in the same class that is triggering the loading of commons-compress classes.
The best policy is to not import any classes at all from an optional dependency, and to instead use only reflection. The JLS and JVMS make no guarantees about lazy classloading. On Sun, Oct 12, 2025 at 12:47 AM Oleg Kalnichevski <[email protected]> wrote: > > > On 10/12/2025 12:06 AM, Ryan Schmitt wrote: > > > > The other issue is that our commons-compress dependency is marked as > > optional, but we import its classes as if it weren't: > > > > > That should not be a problem. There is a safe-guard check that ensures > the factory is loaded from the classpath only if the optional dependency > is also present. > > ``` > if > (CommonsCompressDecoderFactory.runtimeAvailable(c.token())) { > m.put(c, new Codec( > e -> new CommonsCompressingEntity(e, > c.token()), > ent -> new DecompressingEntity(ent, > > CommonsCompressDecoderFactory.decoder(c.token())))); > } > ``` > > The CommonsCompressDecoderFactory#runtimeAvailable implementation looks > wrong though. I overlooked it in my review. > > Oleg > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > >
