Search in sources :

Example 1 with CodeGenerationException

use of net.sf.cglib.core.CodeGenerationException in project cglib by cglib.

the class AbstractClassLoader method loadClass.

public Class loadClass(String name) throws ClassNotFoundException {
    Class loaded = findLoadedClass(name);
    if (loaded != null) {
        if (loaded.getClassLoader() == this) {
            return loaded;
        }
    //else reload with this class loader
    }
    if (!filter.accept(name)) {
        return super.loadClass(name);
    }
    ClassReader r;
    try {
        java.io.InputStream is = classPath.getResourceAsStream(name.replace('.', '/') + ".class");
        if (is == null) {
            throw new ClassNotFoundException(name);
        }
        try {
            r = new ClassReader(is);
        } finally {
            is.close();
        }
    } catch (IOException e) {
        throw new ClassNotFoundException(name + ":" + e.getMessage());
    }
    try {
        DebuggingClassWriter w = new DebuggingClassWriter(ClassWriter.COMPUTE_FRAMES);
        getGenerator(r).generateClass(w);
        byte[] b = w.toByteArray();
        Class c = super.defineClass(name, b, 0, b.length, DOMAIN);
        postProcess(c);
        return c;
    } catch (RuntimeException e) {
        throw e;
    } catch (Error e) {
        throw e;
    } catch (Exception e) {
        throw new CodeGenerationException(e);
    }
}
Also used : DebuggingClassWriter(net.sf.cglib.core.DebuggingClassWriter) CodeGenerationException(net.sf.cglib.core.CodeGenerationException) ClassReader(org.objectweb.asm.ClassReader) IOException(java.io.IOException) CodeGenerationException(net.sf.cglib.core.CodeGenerationException) IOException(java.io.IOException)

Example 2 with CodeGenerationException

use of net.sf.cglib.core.CodeGenerationException in project blade by biezhi.

the class AbstractClassLoader method loadClass.

public Class loadClass(String name) throws ClassNotFoundException {
    Class loaded = findLoadedClass(name);
    if (loaded != null) {
        if (loaded.getClassLoader() == this) {
            return loaded;
        }
    //else reload with this class loader
    }
    if (!filter.accept(name)) {
        return super.loadClass(name);
    }
    ClassReader r;
    try {
        java.io.InputStream is = classPath.getResourceAsStream(name.replace('.', '/') + ".class");
        if (is == null) {
            throw new ClassNotFoundException(name);
        }
        try {
            r = new ClassReader(is);
        } finally {
            is.close();
        }
    } catch (IOException e) {
        throw new ClassNotFoundException(name + ":" + e.getMessage());
    }
    try {
        DebuggingClassWriter w = new DebuggingClassWriter(ClassWriter.COMPUTE_FRAMES);
        getGenerator(r).generateClass(w);
        byte[] b = w.toByteArray();
        Class c = super.defineClass(name, b, 0, b.length, DOMAIN);
        postProcess(c);
        return c;
    } catch (RuntimeException e) {
        throw e;
    } catch (Error e) {
        throw e;
    } catch (Exception e) {
        throw new CodeGenerationException(e);
    }
}
Also used : DebuggingClassWriter(net.sf.cglib.core.DebuggingClassWriter) CodeGenerationException(net.sf.cglib.core.CodeGenerationException) ClassReader(org.objectweb.asm.ClassReader) IOException(java.io.IOException) CodeGenerationException(net.sf.cglib.core.CodeGenerationException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 CodeGenerationException (net.sf.cglib.core.CodeGenerationException)2 DebuggingClassWriter (net.sf.cglib.core.DebuggingClassWriter)2 ClassReader (org.objectweb.asm.ClassReader)2