When checking the code, I ran into this construct, ContextClassLoader , from what I see was not initialized, it is unclear what the ClassLoader getContextClassLoader() method variable returns to the cl , shouldn't ClassLoader getContextClassLoader() return null ?

  ClassLoader getContextClassLoader() { return (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { ClassLoader cl = null; try { cl = Thread.currentThread().getContextClassLoader(); // Что содержит CL на данный момент ? } catch (SecurityException ex) { } return cl; } }); } 

Below is the code inside the Thread class:

  @CallerSensitive public ClassLoader getContextClassLoader() { if (contextClassLoader == null) return null; SecurityManager sm = System.getSecurityManager(); if (sm != null) { ClassLoader.checkClassLoaderPermission(contextClassLoader, Reflection.getCallerClass()); } return contextClassLoader; } /* The context ClassLoader for this thread */ private ClassLoader contextClassLoader; public static native Thread currentThread(); 

    1 answer 1

    ContextClassLoader , from what I see has not been initialized

    ContextClassLoader initialized in the ContextClassLoader Thread.init(..) method

    it is not clear what the ClassLoader getContextClassLoader() variable of the method ClassLoader getContextClassLoader() will return to cl

    Shouldn't ClassLoader getContextClassLoader() return null ?

    The Thread.getContextClassLoader() method will return either ClassLoader or null cl variable.

    • The fact is that since I zashol source I stumbled upon the init () method, but empty, zashol source via IDEA and not the Grep Code .. the method did not accept any parameters, so I decided to ask a question, I will attach the code that throws in the future on init (). - Maks.Burkov