Example usage for java.lang ClassNotFoundException ClassNotFoundException

List of usage examples for java.lang ClassNotFoundException ClassNotFoundException

Introduction

In this page you can find the example usage for java.lang ClassNotFoundException ClassNotFoundException.

Prototype

public ClassNotFoundException(String s, Throwable ex) 

Source Link

Document

Constructs a ClassNotFoundException with the specified detail message and optional exception that was raised while loading the class.

Usage

From source file:com.google.gwt.dev.shell.CompilingClassLoader.java

@Override
protected Class<?> findClass(String className) throws ClassNotFoundException {
    if (className == null) {
        throw new ClassNotFoundException("null class name", new NullPointerException());
    }/*  w ww. j a v a2 s. co  m*/

    if (className.equals("com.google.gwt.core.ext.debug.JsoEval")) {
        // In addition to the system ClassLoader, we let JsoEval be available
        // from this CompilingClassLoader in case that's where the debugger
        // happens to look.
        return ClassLoader.getSystemClassLoader().loadClass(className);
    }

    loadLock.lock();
    try {

        if (scriptOnlyClasses.contains(className)) {
            // Allow the child ClassLoader to handle this
            throw new ClassNotFoundException();
        }

        // Check for a bridge class that spans hosted and user space.
        if (BRIDGE_CLASS_NAMES.containsKey(className)) {
            return BRIDGE_CLASS_NAMES.get(className);
        }

        // Get the bytes, compiling if necessary.
        byte[] classBytes = findClassBytes(className);
        if (classBytes == null) {
            throw new ClassNotFoundException(className);
        }

        if (HasAnnotation.hasAnnotation(classBytes, GwtScriptOnly.class)) {
            scriptOnlyClasses.add(className);
            maybeInitializeScriptOnlyClassLoader();

            /*
             * Release the lock before side-loading from scriptOnlyClassLoader. This prevents deadlock
             * conditions when a class from scriptOnlyClassLoader ends up trying to call back into this
             * classloader from another thread. 
             */
            loadLock.unlock();

            // Also don't run the static initializer to lower the risk of deadlock. 
            return Class.forName(className, false, scriptOnlyClassLoader);
        }

        /*
         * Prevent reentrant problems where classes that need to be injected have
         * circular dependencies on one another via JSNI and inheritance. This check
         * ensures that a class's supertype can refer to the subtype (static
         * members, etc) via JSNI references by ensuring that the Class for the
         * subtype will have been defined before injecting the JSNI for the
         * supertype.
         */
        boolean localInjection;
        if (!isInjectingClass) {
            localInjection = isInjectingClass = true;
        } else {
            localInjection = false;
        }

        Class<?> newClass = defineClass(className, classBytes, 0, classBytes.length);
        if (className.equals(JavaScriptHost.class.getName())) {
            javaScriptHostClass = newClass;
            updateJavaScriptHost();
        }

        /*
        * We have to inject the JSNI code after defining the class, since dispId
        * assignment is based around reflection on Class objects. Don't inject JSNI
        * when loading a JSO interface class; just wait until the implementation
        * class is loaded.
        */
        if (!classRewriter.isJsoIntf(className)) {
            CompilationUnit unit = getUnitForClassName(canonicalizeClassName(className));
            if (unit != null) {
                toInject.push(unit);
            }
        }

        if (localInjection) {
            try {
                /*
                * Can't use an iterator here because calling injectJsniFor may cause
                * additional entries to be added.
                */
                while (toInject.size() > 0) {
                    CompilationUnit unit = toInject.remove(0);
                    if (!alreadyInjected.contains(unit)) {
                        injectJsniMethods(unit);
                        alreadyInjected.add(unit);
                    }
                }
            } finally {
                isInjectingClass = false;
            }
        }

        if (className.equals("com.google.gwt.core.client.GWT")) {
            gwtClass = newClass;
            updateGwtClass();
        }

        return newClass;
    } finally {
        if (loadLock.isLocked()) {
            loadLock.unlock();
        }
    }
}

From source file:edu.gsgp.experiment.config.PropertiesManager.java

/**
 * Get the list of functions from the String read from the file
 *
 * @return An array of functions//from  w w w. ja va2  s  . c  o m
 * @throws Exception Parameter not found, error while parsing the function
 * type
 */
private Function[] getFunctionObjects() throws Exception {
    String[] sFunctions = getStringProperty(ParameterList.FUNCTION_LIST, false).split(",");
    ArrayList<Function> functionArray = new ArrayList<Function>();

    for (String str : sFunctions) {
        try {
            str = str.trim();
            Class<?> function = Class.forName(str);
            functionArray.add((Function) function.newInstance());
        } catch (ClassNotFoundException e) {
            throw new ClassNotFoundException("Error loading the function set. Class " + str + " not found", e);
        }
    }

    return functionArray.toArray(new Function[functionArray.size()]);
}

From source file:edu.gsgp.experiment.config.PropertiesManager.java

/**
 * Get the population initializer from the file
 *
 * @return A new population initializer object
 * @throws Exception Parameter not found, error while parsing the Populator
 * type/*from  w  w w  .j a va 2 s  .  co  m*/
 */
private Populator getPopInitObject() throws Exception {
    String populatorClassname = "";
    try {
        populatorClassname = getStringProperty(ParameterList.POP_INITIALIZER, false).replaceAll("\\s", "");
        Class<?> populatorClass = Class.forName(populatorClassname);
        Constructor<?> populatorConstructor = populatorClass.getConstructor(PropertiesManager.class);
        return (Populator) populatorConstructor.newInstance(this);
    } catch (ClassNotFoundException e) {
        String msg = "Error loading the population initializer. ";
        if (populatorClassname.isEmpty()) {
            msg += "No population initializer was specified.";
        } else {
            msg += "Class " + populatorClassname + " not found";
        }
        throw new ClassNotFoundException(msg, e);
    }
}

From source file:edu.gsgp.experiment.config.PropertiesManager.java

/**
 * Get the pipeline object from the file
 *
 * @return A new pipeline object//from  w  ww.ja  v  a2 s. c o m
 * @throws Exception Parameter not found, error while parsing the Pipeline
 * type
 */
private Pipeline getPipelineObject() throws Exception {
    String populatorClassname = "";
    try {
        populatorClassname = getStringProperty(ParameterList.POP_PIPELINE, false).replaceAll("\\s", "");
        Class<?> populatorClass = Class.forName(populatorClassname);
        Constructor<?> populatorConstructor = populatorClass.getConstructor();
        return (Pipeline) populatorConstructor.newInstance();
    } catch (ClassNotFoundException e) {
        String msg = "Error loading the pipeline. ";
        if (populatorClassname.isEmpty()) {
            msg += "No pipeline was specified.";
        } else {
            msg += "Class " + populatorClassname + " not found";
        }
        throw new ClassNotFoundException(msg, e);
    }
}

From source file:edu.gsgp.experiment.config.PropertiesManager.java

/**
 * Get the fitness object from the file/*from ww  w  .  j  a v a 2 s.c  o m*/
 *
 * @return A new fintess function
 * @throws Exception Parameter not found, error while parsing the Fitness
 * type
 */
private Fitness getFitnessObject() throws Exception {
    String fitnessClassname = "";
    try {
        fitnessClassname = getStringProperty(ParameterList.FITNESS_FUNCTION, false).replaceAll("\\s", "");
        Class<?> fitnessClass = Class.forName(fitnessClassname);
        return (Fitness) fitnessClass.newInstance();
    } catch (ClassNotFoundException e) {
        throw new ClassNotFoundException(
                "Error loading the fitness function. Class " + fitnessClassname + " not found", e);
    }
}