/*
(non-Javadoc)
@see java.lang.ClassLoader#findClass(java.lang.String)
555356
@Override
  protected Class<?> findClass(final String name) throws ClassNotFoundException {

    ByteBuffer def = AccessController.doPrivileged(new PrivilegedAction<ByteBuffer>() {
      public ByteBuffer run() {
        return strategy.getClassDefinition(name);
      }
    });

    if (def != null) {

      Class<?> result = super.defineClass(name, def, null);

      if (result != null) {
        super.resolveClass(result);
        return result;
      }

    }

    throw new ClassNotFoundException(name);

  }
918763
@SuppressWarnings("unchecked")
    private Class<? extends T> loadClass(ClassLoader classLoader, String generatedName)
            throws ClassNotFoundException {
        return (Class<? extends T>) classLoader.loadClass(generatedName);
    }
823683
@Override
    @FFDCIgnore(ClassNotFoundException.class)
    protected final Class<?> findClass(String name) throws ClassNotFoundException {
        if (transformers.isEmpty()) {
            Class<?> clazz = null;
            Object token = ThreadIdentityManager.runAsServer();
            try {
                synchronized (getClassLoadingLock(name)) {
                    // This method may be invoked directly instead of via loadClass
                    // (e.g. when doing a "shallow" scan of the common library classloaders).
                    // So we first must check whether we've already defined/loaded the class.
                    // Otherwise we'll get a LinkageError on the second findClass call because
                    // it will attempt to define the class a 2nd time.
                    clazz = findLoadedClass(name);
                    if (clazz == null) {
                        ByteResourceInformation byteResInfo = this.findClassBytes(name);
                        clazz = definePackageAndClass(name, byteResInfo, byteResInfo.getBytes());
                    }
                }
            } catch (ClassNotFoundException cnfe) {
                // Check the common libraries.
                clazz = findClassCommonLibraryClassLoaders(name);
            } finally {
                ThreadIdentityManager.reset(token);
            }
            return clazz;
        }

        ByteResourceInformation byteResourceInformation;
        try {
            byteResourceInformation = findClassBytes(name);
        } catch (ClassNotFoundException cnfe) {
            // Check the common libraries.
            return findClassCommonLibraryClassLoaders(name);
        }

        byte[] bytes = transformClassBytes(byteResourceInformation.getBytes(), name);
        

        return definePackageAndClass(name, byteResourceInformation, bytes);
    }
890967
@Override
    public JavaClass findClass(/*@Nonnull*/ String className) {
        // Make sure we handle class names with slashes.
        // If we don't, we can get into serious trouble: a previously
        // loaded class will appear to be missing (because we're using the
        // wrong name to look it up) and be evicted by some other random
        // version of the class loaded from the classpath.
        String dottedClassName = className.replace('/', '.');

        return nameToClassMap.get(dottedClassName);
    }
171766
@Override
  public Class<?> loadClassImpl(String name, boolean resolve)
    throws ClassNotFoundException
  {
    // The JVM has already cached the classes, so we don't need to
    Class<?> cl = findLoadedClass(name);

    if (cl != null) {
      if (resolve)
        resolveClass(cl);
      return cl;
    }
    // System.out.println("ROOT: " + name);
    if (_classNotFoundCache.get(name) != null) {
      return null;
    }
    
    try {
      cl = super.loadClassImpl(name, resolve);
    } catch (ClassNotFoundException e) {
      _classNotFoundCache.put(name, name);
      
      throw e;
    }
    
    if (cl == null) {
      _classNotFoundCache.put(name, name);
    }
    
    return cl;
  }
346746
private static Class<?> findClass(final String implClass, final Library library, final URL fileUrl) {
        final ClassLoader containerClassLoader = library.getClassLoader();
        final String libID = library.id();
        Class<?> service = null;
        try {
            service = containerClassLoader.loadClass(implClass);
        } catch (final NoClassDefFoundError e) {
            // Happens if any class referenced by the implementation cannot be found
            if (TraceComponent.isAnyTracingEnabled() && tc.isWarningEnabled()) {
                Tr.warning(tc, "bell.no.inter", implClass, fileUrl, libID, e);
            }
        } catch (final ClassNotFoundException e) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isWarningEnabled()) {
                Tr.warning(tc, "bell.no.impl", implClass, fileUrl, libID);
            }
        } catch (final Throwable e) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isWarningEnabled()) {
                Tr.warning(tc, "bell.error.ctor", implClass, fileUrl, libID, e);
            }
        }
        return service;
    }
744875
@Override
    public JavaClass loadClass(String className) throws ClassNotFoundException {
        if (className.length() == 0) {
            throw new IllegalArgumentException("Request to load empty class");
        }
        className = ClassName.toSlashedClassName(className);
        ClassDescriptor classDescriptor = DescriptorFactory.instance().getClassDescriptor(className);
        try {
            return Global.getAnalysisCache().getClassAnalysis(JavaClass.class, classDescriptor);
        } catch (CheckedAnalysisException e) {
            throw new ClassNotFoundException("Exception while looking for class " + className, e);
        }
    }
140714
@SuppressWarnings("unchecked")
    public static <T> Class<T> loadClass(String className) throws ClassNotFoundException {
        return (Class<T>) getClassLoader().loadClass(className);
    }
532185
@Override
    public JavaClass findClass(String className) {
        @SlashedClassName
        String slashedClassName = ClassName.toSlashedClassName(className);
        ClassDescriptor classDescriptor = DescriptorFactory.instance().getClassDescriptor(slashedClassName);
        return Global.getAnalysisCache().probeClassAnalysis(JavaClass.class, classDescriptor);
    }
684616
protected Class findClass(String name) throws ClassNotFoundException {
        if (delegatationLoader==null) return super.findClass(name);
        return delegatationLoader.loadClass(name);
    }
1219461
@Override
  protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException,
      ClassNotFoundException {
    return Class.forName(desc.getName(), true, loader);
  }
752363
public Class findClass(String name) throws ClassNotFoundException {

        if (log.isDebugEnabled())
            log.debug("    findClass(" + name + ")");

        // Cannot load anything from local repositories if class loader is stopped
        if (!started) {
            throw new ClassNotFoundException(name);
        }

        // (1) Permission to define this class when using a SecurityManager
        if (securityManager != null) {
            int i = name.lastIndexOf('.');
            if (i >= 0) {
                try {
                    if (log.isTraceEnabled())
                        log.trace("      securityManager.checkPackageDefinition");
                    securityManager.checkPackageDefinition(name.substring(0,i));
                } catch (Exception se) {
                    if (log.isTraceEnabled())
                        log.trace("      -->Exception-->ClassNotFoundException", se);
                    throw new ClassNotFoundException(name, se);
                }
            }
        }

        // Ask our superclass to locate this class, if possible
        // (throws ClassNotFoundException if it is not found)
        Class clazz = null;
        try {
            if (log.isTraceEnabled())
                log.trace("      findClassInternal(" + name + ")");
            try {
                clazz = findClassInternal(name);
            } catch(ClassNotFoundException cnfe) {
                if (!hasExternalRepositories) {
                    throw cnfe;
                }
            } catch(AccessControlException ace) {
                throw new ClassNotFoundException(name, ace);
            } catch (RuntimeException e) {
                if (log.isTraceEnabled())
                    log.trace("      -->RuntimeException Rethrown", e);
                throw e;
            }
            if ((clazz == null) && hasExternalRepositories) {
                try {
                    clazz = super.findClass(name);
                } catch(AccessControlException ace) {
                    throw new ClassNotFoundException(name, ace);
                } catch (RuntimeException e) {
                    if (log.isTraceEnabled())
                        log.trace("      -->RuntimeException Rethrown", e);
                    throw e;
                }
            }
            if (clazz == null) {
                if (log.isDebugEnabled())
                    log.debug("    --> Returning ClassNotFoundException");
                throw new ClassNotFoundException(name);
            }
        } catch (ClassNotFoundException e) {
            if (log.isTraceEnabled())
                log.trace("    --> Passing on ClassNotFoundException");
            throw e;
        }

        // Return the class we have located
        if (log.isTraceEnabled())
            log.debug("      Returning class " + clazz);
        if (log.isTraceEnabled())
            log.debug("      Loaded by " + clazz.getClassLoader());
        return (clazz);

    }
897749
public static void findClassLoaderOrder(final ClassLoader classLoader,
            final ClassLoaderOrder classLoaderOrder) {
        classLoaderOrder.delegateTo(classLoader.getParent(), /* isParent = */ true);
        classLoaderOrder.add(classLoader);
    }
275059
@Override
    public JavaClass loadClass(/*@Nonnull*/ String className) throws ClassNotFoundException {
        if (className == null) {
            throw new IllegalArgumentException("className is null");
        }
        // if (className.indexOf('/') >= 0) throw new IllegalStateException();
        JavaClass javaClass = findClass(className);
        if (javaClass == null) {
            if (DEBUG) {
                System.out.println("Looking up " + className + " on classpath");
                dumpStack();
            }
            javaClass = urlClassPath.lookupClass(className);
            storeClass(javaClass);
        }
        return javaClass;
    }
416282
public Class loadClass(String name)
    {
        try
        {
            return classLoader.loadClass( name );
        }
        catch (ClassNotFoundException notFound)
        {
            return null;
        }
        catch (NoClassDefFoundError notFound)
        {
            return null;
        }
    }
1169876
protected Class findClass( String name )
        throws ClassNotFoundException
    {
        // Deal with this cast somehow... maybe have this class use
        // ClassManagerImpl type directly.
        // Don't add the method to BshClassManager... it's really an impl thing
        ClassManagerImpl bcm = (ClassManagerImpl)getClassManager();

        // Should we try to load the class ourselves or delegate?
        // look for overlay loader

        ClassLoader cl = bcm.getLoaderForClass( name );

        // If there is a designated loader and it's not us delegate to it
        if ( cl != null && cl != this ) try {
            return cl.loadClass( name );
        } catch ( ClassNotFoundException e ) {
            throw new ClassNotFoundException(
                "Designated loader could not find class: "+e );
        }

        // Let URLClassLoader try any paths it may have
        if ( getURLs().length > 0 ) try {
            return super.findClass(name);
        } catch ( ClassNotFoundException e ) {
            //System.out.println(
            //  "base loader here caught class not found: "+name );
        }


        // If there is a baseLoader and it's not us delegate to it
        cl = bcm.getBaseLoader();

        if ( cl != null && cl != this ) try {
            return cl.loadClass( name );
        } catch ( ClassNotFoundException e ) { }

        // Try system loader
        return bcm.plainClassForName( name );
    }
294089
public Class<?> loadClassFrom(String name, AbstractClassLoader first) throws ClassNotFoundException {
		// try on the system one
		try { return AppClassLoader.class.getClassLoader().loadClass(name); }
		catch (ClassNotFoundException e) { /* not found. */ }
		Class<?> c = null;
		// check it is not loaded on one of the library
		for (int i = 0; i < libs.size(); i++) {
    		AbstractClassLoader cl = libs.get(i);
    		c = cl.isLoaded(name);
    		if (c != null) return c;
    	}
    	// try with the first one
    	if (first != null) {
    		try {
    			c = first.loadClassInLibrary(name);
    			if (c != null) return c;
    		} catch (FileNotFoundException e) {
    			// not found
    		} catch (IOException e) {
    			throw new ClassNotFoundException(e.getMessage());
    		}
    	}
    	// then, try on other libraries
    	for (int i = 0; i < libs.size(); i++) {
    		AbstractClassLoader cl = libs.get(i);
    		if (cl == first) continue;
    		try {
    			c = cl.loadClassInLibrary(name);
    			if (c != null) return c;
    		} catch (FileNotFoundException e) {
    			// not found
    		} catch (IOException e) {
    			throw new ClassNotFoundException(e.getMessage());
    		}
    	}
		StringBuilder msg = new StringBuilder(512);
		msg.append("Class not found: ").append(name);
		msg.append("\r\nFrom class loader: ").append(first);
		msg.append("\r\nlibraries currently registered:");
		for (int i = 0; i < libs.size(); i++)
			msg.append("\r\n - ").append(libs.get(i).toString());
		throw new ClassNotFoundException(msg.toString());
	}

	/** Load a resource. */
	@SuppressWarnings("resource")
	public IO.Readable getResourceIO(String name, byte priority) {
		if (name.length() == 0) return null;
		if (name.charAt(0) == '/') name = name.substring(1);
		IO.Readable io = null;
    	for (int i = 0; i < libs.size(); i++) {
    		AbstractClassLoader cl = libs.get(i);
   			try { io = cl.open(name, priority); }
   			catch (IOException e) { /* ignore */ }
    		if (io != null) return io;
    	}
       	// then try on the core one
        InputStream in = AppClassLoader.class.getClassLoader().getResourceAsStream(name);
        if (in == null) return null;
        return new IOFromInputStream(in, name, Threading.getUnmanagedTaskManager(), priority);
	}