smallrye / smallrye-common

Common utilities for SmallRye

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

About Thread.currentThread().getContextClassLoader()

magicprinc opened this issue · comments

Thread.currentThread().getContextClassLoader() is actively used in io.smallrye.common.classloader.ClassPathUtils

but from technical perspective it could be null:

  • there is a setter
  • I have seen such situation

It is safer to add utility method

[public] static ClassLoader getClassLoader () {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    return cl != null ? cl
        : ClassPathUtils.class.getClassLoader();
}