Class ByteArrayClassLoader

java.lang.Object
java.lang.ClassLoader
edu.internet2.middleware.grouper.app.gsh.template.ByteArrayClassLoader

public class ByteArrayClassLoader extends ClassLoader
Classloader that defines a set of Java classes from in-memory bytecode. Used by GshTemplateClassLoaderRegistry as the per-template loader for a single compiled GSH Java template version. Parent delegation is standard parent-first: when asked for a class, the default loadClass() implementation in ClassLoader first asks the parent (which is Grouper's app classloader, holding GshTemplateV2, the Grouper API, JDK classes, and any helper jars), and only falls through to this loader's findClass() for classes the parent does not have. That guarantees GshTemplateV2, helper-jar classes, and JDK types are all resolved to a single Class object shared across the JVM, while the template's own bytecode is loaded here. One instance per template version. On a source change, the registry drops its reference to this loader and constructs a new one; the old loader becomes unreferenced and is eligible for GC once any in-flight executions holding references drain. GRP-7010
  • Constructor Details

    • ByteArrayClassLoader

      public ByteArrayClassLoader(ClassLoader parent, Map<String,byte[]> classNameToBytecode)
      Parameters:
      parent - typically GshTemplateV2.class.getClassLoader() — the loader that has Grouper's app classes, so the template's references to the Grouper API resolve through delegation
      classNameToBytecode - bytecode for the template's class(es), keyed by FQN. Caller retains ownership of the map; this loader does not copy it but also does not mutate it.
  • Method Details

    • findClass

      protected Class<?> findClass(String name) throws ClassNotFoundException
      Define a class from this loader's bytecode map. Called by the JDK's default loadClass() only after the parent loader has been asked first and returned ClassNotFoundException — i.e. for classes the parent does not have, which for our purposes are exactly the template's own classes.
      Overrides:
      findClass in class ClassLoader
      Throws:
      ClassNotFoundException