Class NegativeCachingGroovyClassLoader

java.lang.Object
java.lang.ClassLoader
java.security.SecureClassLoader
java.net.URLClassLoader
groovy.lang.GroovyClassLoader
org.openrewrite.groovy.internal.NegativeCachingGroovyClassLoader
All Implemented Interfaces:
Closeable, AutoCloseable

public class NegativeCachingGroovyClassLoader extends groovy.lang.GroovyClassLoader
A GroovyClassLoader that caches names that could not be resolved, so repeated lookups for the same absent name skip re-scanning the whole classpath. Groovy's resolver probes many package-prefixes per unresolved reference, and neither GroovyClassLoader nor URLClassLoader caches a ClassNotFoundException, so each miss re-opens every classpath JAR before failing.

Caching misses is safe for GroovyParser's usage: the classpath is fixed for the batch and the parser never defines classes into the loader (it compiles only to CANONICALIZATION), so an absent name stays absent. Only the lookupScriptFiles == false path is cached, since a true lookup could resolve a name to a Groovy script source rather than a class.

  • Constructor Details

    • NegativeCachingGroovyClassLoader

      public NegativeCachingGroovyClassLoader(ClassLoader parent, org.codehaus.groovy.control.CompilerConfiguration config)
  • Method Details

    • loadClass

      public Class loadClass(String name, boolean lookupScriptFiles, boolean preferClassOverScript, boolean resolve) throws ClassNotFoundException, org.codehaus.groovy.control.CompilationFailedException
      Overrides:
      loadClass in class groovy.lang.GroovyClassLoader
      Throws:
      ClassNotFoundException
      org.codehaus.groovy.control.CompilationFailedException