Search in sources :

Example 1 with ExceptionsAttribute

use of org.hotswap.agent.javassist.bytecode.ExceptionsAttribute in project HotswapAgent by HotswapProjects.

the class Expr method mayThrow.

/**
 * Returns the list of exceptions that the expression may throw. This list
 * includes both the exceptions that the try-catch statements including the
 * expression can catch and the exceptions that the throws declaration
 * allows the method to throw.
 */
public CtClass[] mayThrow() {
    ClassPool pool = thisClass.getClassPool();
    ConstPool cp = thisMethod.getConstPool();
    LinkedList list = new LinkedList();
    try {
        CodeAttribute ca = thisMethod.getCodeAttribute();
        ExceptionTable et = ca.getExceptionTable();
        int pos = currentPos;
        int n = et.size();
        for (int i = 0; i < n; ++i) if (et.startPc(i) <= pos && pos < et.endPc(i)) {
            int t = et.catchType(i);
            if (t > 0)
                try {
                    addClass(list, pool.get(cp.getClassInfo(t)));
                } catch (NotFoundException e) {
                }
        }
    } catch (NullPointerException e) {
    }
    ExceptionsAttribute ea = thisMethod.getExceptionsAttribute();
    if (ea != null) {
        String[] exceptions = ea.getExceptions();
        if (exceptions != null) {
            int n = exceptions.length;
            for (int i = 0; i < n; ++i) try {
                addClass(list, pool.get(exceptions[i]));
            } catch (NotFoundException e) {
            }
        }
    }
    return (CtClass[]) list.toArray(new CtClass[list.size()]);
}
Also used : ConstPool(org.hotswap.agent.javassist.bytecode.ConstPool) CtClass(org.hotswap.agent.javassist.CtClass) ExceptionsAttribute(org.hotswap.agent.javassist.bytecode.ExceptionsAttribute) CodeAttribute(org.hotswap.agent.javassist.bytecode.CodeAttribute) ClassPool(org.hotswap.agent.javassist.ClassPool) NotFoundException(org.hotswap.agent.javassist.NotFoundException) ExceptionTable(org.hotswap.agent.javassist.bytecode.ExceptionTable) LinkedList(java.util.LinkedList)

Aggregations

LinkedList (java.util.LinkedList)1 ClassPool (org.hotswap.agent.javassist.ClassPool)1 CtClass (org.hotswap.agent.javassist.CtClass)1 NotFoundException (org.hotswap.agent.javassist.NotFoundException)1 CodeAttribute (org.hotswap.agent.javassist.bytecode.CodeAttribute)1 ConstPool (org.hotswap.agent.javassist.bytecode.ConstPool)1 ExceptionTable (org.hotswap.agent.javassist.bytecode.ExceptionTable)1 ExceptionsAttribute (org.hotswap.agent.javassist.bytecode.ExceptionsAttribute)1