Checks the availability of the JAXP classes on the classpath.
@throws NoClassDefFoundError if the required JAXP classes are not availabile on the classpath.
321544
static void checkJAXPAvailability() {
        try {
            XmlConfigurator.class.getName();
        }
        catch (NoClassDefFoundError error) {
            Error tmp=new NoClassDefFoundError(JAXP_MISSING_ERROR_MSG);
            tmp.initCause(error);
            throw tmp;
        }
    }
453483
public boolean hasClass(String name) {
        byte[] b = classesFound.get(name);
        Boolean found = b == null ? null : b.length > 0;
        if (found != null)
            return found;

        try {
            // try dynamic jar assets
            String path = name.replace('.', '/') + ".class";
            b = findInJarAssets(path);
            // try the file system
            if (b == null)
                b = findInFileSystem(path);
        }
        catch (Exception ex) {
            logger.severeException(ex.getMessage(),  ex);
        }
        found = b != null;
        classesFound.put(name, found ? b : new byte[0]);
        return found;
    }
251703
@Override
    protected Class<?> loadClass(String className, boolean resolve)
                    throws ClassNotFoundException {

        Class<?> loadedClass = null;

        synchronized (this) {
            loadedClass = findLoadedClass(className);

            if (loadedClass == null) {
                int index = className.lastIndexOf('.');
                String packageName = index > 0 ? className.substring(0, index) : "";
                if (packageList.contains(packageName)) {
                    try {
                        // first check our classpath
                        loadedClass = findClass(className);
                    } catch (ClassNotFoundException cnfe) {
                        // ignore this since we'll try the parent next
                    }
                }
            }
        }

        if (null == loadedClass) {
            // then the parent classpath
            loadedClass = super.loadClass(className, resolve);
        }

        // The resolve parameter is a legacy parameter that is effectively
        // never used as of JDK 1.1 (see footnote 1 of section 5.3.2 of the 2nd
        // edition of the JVM specification).  The only caller of this method is
        // is java.lang.ClassLoader.loadClass(String), and that method always
        // passes false, so we ignore the parameter.

        return loadedClass;
    }
295889
@Override
    protected Class<?> findClass(final String className)
            throws ClassNotFoundException, LinkageError, SecurityException {
        final Class<?> loadedClass = findLoadedClass(className);
        if (loadedClass != null) {
            return loadedClass;
        }

        // Get ClassInfo for named class
        final ClassInfo classInfo = scanResult.getClassInfo(className);

        // Try environment classloaders first
        boolean triedClassInfoLoader = false;
        final ClassLoader[] classLoaderOrder = scanResult.getClassLoaderOrderRespectingParentDelegation();
        if (classLoaderOrder != null) {
            // Try environment classloaders
            for (final ClassLoader envClassLoader : classLoaderOrder) {
                try {
                    return Class.forName(className, scanResult.scanSpec.initializeLoadedClasses, envClassLoader);
                } catch (ReflectiveOperationException | LinkageError e) {
                    // Ignore
                }
                if (classInfo != null && envClassLoader == classInfo.classLoader) {
                    triedClassInfoLoader = true;
                }
            }
        }

        // Try specific classloader for the classpath element that the classfile was obtained from
        if (!triedClassInfoLoader && classInfo != null && classInfo.classLoader != null) {
            try {
                return Class.forName(className, scanResult.scanSpec.initializeLoadedClasses, classInfo.classLoader);
            } catch (final ReflectiveOperationException | LinkageError e) {
                // Ignore
            }
        }

        // If class came from a module, and it was not able to be loaded by the environment classloader,
        // then it is possible it was a non-public class, and ClassGraph found it by ignoring class visibility
        // when reading the resources in exported packages directly. Force ClassGraph to respect JPMS
        // encapsulation rules by refusing to load modular classes that the context/system classloaders
        // could not load. (A SecurityException should be thrown above, but this is here for completeness.)
        if (classInfo != null && classInfo.classpathElement instanceof ClasspathElementModule
                && !classInfo.isPublic()) {
            throw new ClassNotFoundException("Classfile for class " + className + " was found in a module, "
                    + "but the context and system classloaders could not load the class, probably because "
                    + "the class is not public.");
        }

        // Try obtaining the classfile as a resource, and defining the class from the resource content
        final ResourceList classfileResources = scanResult
                .getResourcesWithPath(JarUtils.classNameToClassfilePath(className));
        if (classfileResources != null) {
            for (final Resource resource : classfileResources) {
                // Iterate through resources (only loading of first resource in the list will be attempted)
                try {
                    // Load the content of the resource, and define a class from it
                    final ByteBuffer resourceByteBuffer = resource.read();
                    return defineClass(className, resourceByteBuffer, null);
                } catch (final IOException e) {
                    throw new ClassNotFoundException("Could not load classfile for class " + className + " : " + e);
                } finally {
                    resource.close();
                }
            }
        }
        throw new ClassNotFoundException("Could not load classfile for class " + className);
    }
62917
@SuppressWarnings("unchecked")
    private boolean isClassTrivial(ClassTraceInfo info) {
        AnnotationNode trivialAnnotation = getAnnotation(TRIVIAL_TYPE.getDescriptor(), info.classNode.visibleAnnotations);
        if (trivialAnnotation != null) {
            return true;
        }
        return false;
    }
875053
private static Class checkClass(String packageName, TypeElement type, Map<String, String> mappedUniName,
            boolean isUniName) {
        String simpleName = getProxyClassName(type.name(), mappedUniName, isUniName);
        String className = packageName + PACKAGE_SPLIT_CHAR + simpleName;

        Class<?> c = null;
        try {
            c = Class.forName(className);
        } catch (ClassNotFoundException e1) {
            // if class not found so should generate a new java source class.
            c = null;
        }

        return c;
    }
100900
public static void dispose(String xmlClasspath) {

    if (xml2containerMap != null) {
      SpringContainer container = xml2containerMap.get(xmlClasspath);
      if (container != null) {
        xml2containerMap.remove(xmlClasspath);
        container.dispose();
      }
    }
  }
260657
@Override
  protected Class<?> findClass(String name) throws ClassNotFoundException {
    if (!loadedClassFiles) {
      classFileMap = extractClassFileMap();
      loadedClassFiles = true;
    }

    if (classFileMap == null) {
      throw new ClassNotFoundException(name);
    }

    String internalName = name.replace('.', '/');
    CompiledClass compiledClass = classFileMap.get(internalName);
    if (compiledClass == null) {
      throw new ClassNotFoundException(name);
    }

    // Make sure the class's package is present.
    String pkg = compiledClass.getPackageName();
    if (getPackage(pkg) == null) {
      definePackage(pkg, null, null, null, null, null, null, null);
    }

    byte[] bytes = compiledClass.getBytes();
    return defineClass(name, bytes, 0, bytes.length);
  }
730992
@Override
    public boolean redefineClasses(Notification notification) {
        // if there are no paths to process, this is a minor update
        if (notification.getPaths().isEmpty()) {
            return true;
        }

        boolean success;
        synchronized (classLoaders) {
            if (classLoaders.isEmpty()) {
                success = false;
            } else {
                success = true;
                for (ContainerClassLoader loader : classLoaders) {
                    if (!loader.redefineClasses(notification)) {
                        success = false;
                        break;
                    }
                }
            }
        }

        return success;
    }
53226
void showClassesConfiguration() {

        // Warning about a classes folder present in the classpath:
        if (classesInClasspath != null) {
            log.warn("Dynamic class reloading is disabled because a classes URL is present in the classpath. P"
                    + "lease launch without including your classes directory: {}", classesInClasspath);
        }

        // Message to communicate the resolved configuration:
        String message;
        if (classesReloadable) {
            if (StringUtils.isNotBlank(packagePrefix)) {
                message = "Classes will be reloaded from: " + classesUrl;
            } else {
                message = "Classes will be reloaded from package " + packagePrefix + " at: " + classesUrl;
            }
        } else {
            message = "Classes will not be dynamically reloaded.";
        }
        log.info("Classes: {}", message);
    }
199303
public static Properties getProperties(String classpath) {
        Properties properties = new Properties();
        try (InputStream is = getResourceInputStream(classpath)) {
            properties.load(is);
            return properties;
        } catch (Exception e) {
            return JMExceptionManager.handleExceptionAndReturnNull(log, e,
                    "getProperties", classpath);
        }
    }
86766
public void setClassPath(String classpath) {
		this.classpath = new ArrayList<>();
		for (final String path : Strings.split(classpath, Pattern.quote(File.pathSeparator))) {
			this.classpath.add(normalizeFile(path));
		}
	}
361218
private Collection<Candidate> findCandidateClasses(Outline outline, JClass xmlElementDeclModelClass) {
		Map<String, ClassOutline> interfaceImplementations = new HashMap<String, ClassOutline>();

		// Visit all classes to create a map "interfaceName -> ClassOutline".
		// This map is later used to resolve implementations from interfaces.
		for (ClassOutline classOutline : outline.getClasses()) {
			for (Iterator<JClass> iter = classOutline.implClass._implements(); iter.hasNext();) {
				JClass interfaceClass = iter.next();

				if (interfaceClass instanceof JDefinedClass) {
					// Don't care if some interfaces collide: value classes have exactly one implementation
					interfaceImplementations.put(interfaceClass.fullName(), classOutline);
				}
			}
		}

		Collection<Candidate> candidates = new ArrayList<Candidate>();

		JClass collectionModelClass = outline.getCodeModel().ref(Collection.class);
		JClass xmlSchemaModelClass = outline.getCodeModel().ref(XmlSchema.class);

		// Visit all classes created by JAXB processing to collect all potential wrapper classes to be removed:
		for (ClassOutline classOutline : outline.getClasses()) {
			JDefinedClass candidateClass = classOutline.implClass;

			// * The candidate class should not extend any other model class (as the total number of properties in this case will be more than 1)
			if (!isHiddenClass(candidateClass._extends())) {
				continue;
			}

			JFieldVar field = null;

			// * The candidate class should have exactly one property
			for (JFieldVar f : candidateClass.fields().values()) {
				if ((f.mods().getValue() & JMod.STATIC) == JMod.STATIC) {
					continue;
				}

				// If there are at least two non-static fields, we discard this candidate:
				if (field != null) {
					field = null;
					break;
				}

				field = f;
			}

			// "field" is null if there are no fields (or all fields are static) or there are more then two fields.
			// The only property should be a collection, hence it should be class:
			if (field == null || !(field.type() instanceof JClass)) {
				continue;
			}

			JClass fieldType = (JClass) field.type();

			// * The property should be a collection
			if (!collectionModelClass.isAssignableFrom(fieldType)) {
				continue;
			}

			List<JClass> fieldParametrisations = fieldType.getTypeParameters();

			// FIXME: All known collections have exactly one parametrisation type.
			assert fieldParametrisations.size() == 1;

			JDefinedClass fieldParametrisationClass = null;
			JDefinedClass fieldParametrisationImpl = null;

			// Parametrisations like "List<String>" or "List<Serialazable>" are not considered.
			// They are substituted as is and do not require moving of classes.
			if (fieldParametrisations.get(0) instanceof JDefinedClass) {
				fieldParametrisationClass = (JDefinedClass) fieldParametrisations.get(0);

				ClassOutline fieldParametrisationClassOutline = interfaceImplementations
				            .get(fieldParametrisationClass.fullName());

				if (fieldParametrisationClassOutline != null) {
					assert fieldParametrisationClassOutline.ref == fieldParametrisationClass;

					fieldParametrisationImpl = fieldParametrisationClassOutline.implClass;
				}
				else {
					fieldParametrisationImpl = fieldParametrisationClass;
				}
			}

			// We have a candidate class:
			Candidate candidate = new Candidate(candidateClass, classOutline.target, field, fieldParametrisationClass,
			            fieldParametrisationImpl, xmlElementDeclModelClass, xmlSchemaModelClass);
			candidates.add(candidate);

			logger.debug("Found " + candidate);
		}

		return candidates;
	}
556120
public boolean reloadIsModified()
  {
    if (_classIsModified) {
      return true;
    }

    if (! _hasJNIReload || ! _classPath.canRead()) {
      return true;
    }
    
    try {
      long length = _classPath.length();

      Class<?> cl = _clRef != null ? _clRef.get() : null;

      if (cl == null) {
        return false;
      }

      /*
      if (cl.isAnnotationPresent(RequireReload.class))
        return true;
        */

      byte []bytecode = new byte[(int) length];
      try (InputStream is = _classPath.inputStream()) {
        IoUtil.readAll(is, bytecode, 0, bytecode.length);
      }

      int result = reloadNative(cl, bytecode, 0, bytecode.length);

      if (result != 0) {
        _classIsModified = true;
        return true;
      }

      // XXX: setDependPath(_classPath);

      if (_sourcePath != null) {
        _sourceLastModified = _sourcePath.getLastModified();
        _sourceLength = _sourcePath.length();
      }

      log.info("Reloading " + cl.getName());

      return false;
    } catch (Exception e) {
      log.log(Level.WARNING, e.toString(), e);
      _classIsModified = true;

      return true;
    }
  }
1330170
private void processClasspath(String classpathElement) throws ResourceNotFoundException, ParseErrorException, Exception {
//        getLog().info("Classpath is " + classpathElement);
        if (classpathElement.endsWith(".jar")) {
            // TODO: implement JAR scanning
        } else {
            final File dir = new File(classpathElement);

            processPackage(dir, dir);
        }
    }
972235
boolean processSelf(Collection<String> classes) throws IOException {
        options.add("--add-modules");
        options.add("java.se.ee,jdk.xml.bind"); // TODO why jdk.xml.bind?

        if (classes.isEmpty()) {
            Path modules = FileSystems.getFileSystem(URI.create("jrt:/"))
                                      .getPath("/modules");

            // names are /modules/<modulename>/pkg/.../Classname.class
            try (Stream<Path> paths = Files.walk(modules)) {
                Stream<String> files =
                    paths.filter(p -> p.getNameCount() > 2)
                         .map(p -> p.subpath(1, p.getNameCount()))
                         .map(Path::toString);
                return doModularFileNames(files);
            }
        } else {
            return doClassNames(classes);
        }
    }
1177183
void compileClass(Source javaSource, Source javaClass,
                    String sourcePath, boolean isMake)
    throws ClassNotFoundException
  {
    try {
      JavaCompilerUtil compiler = JavaCompilerUtil.create(getClassLoader());
      compiler.setClassDir(_classDir);
      compiler.setSourceDir(_sourceDir);
      if (_encoding != null)
        compiler.setEncoding(_encoding);
      compiler.setArgs(_args);
      compiler.setCompileParent(! isMake);
      compiler.setSourceExtension(_sourceExt);
      if (_compiler != null)
        compiler.setCompiler(_compiler);

      //LineMap lineMap = new LineMap(javaFile.getNativePath());
      // The context path is obvious from the browser url
      //lineMap.add(name.replace('.', '/') + _sourceExt, 1, 1);

      // Force this into a relative path so different compilers will work
      String prefix = _sourceDir.getPath();
      String full = javaSource.getPath();

      String source;
      if (full.startsWith(prefix)) {
        source = full.substring(prefix.length());
        if (source.startsWith("/"))
          source = source.substring(1);
      }
      else
        source = javaSource.getPath();

      /*
      if (javaSource.canRead() && javaClass.exists())
        javaClass.remove();
      */
          
      compiler.compileIfModified(source, null);
    } catch (Exception e) {
      //getClassLoader().addDependency(new Depend(javaSource));

      log.log(Level.FINEST, e.toString(), e);

      // Compile errors are wrapped in a special ClassNotFound class
      // so the server can give a nice error message
      throw new CompileClassNotFound(e);
    }
  }