Search in sources :

Example 31 with NotFoundException

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

the class ProxyUtil method ensureProxyable.

/**
 * Ensure proxyable.
 *
 * @param clazz
 *            the clazz
 * @throws CannotCompileException
 *             the cannot compile exception
 */
public static void ensureProxyable(CtClass clazz) throws CannotCompileException {
    int flags = clazz.getClassFile().getAccessFlags();
    flags = AccessFlag.setPublic(flags);
    flags = AccessFlag.clear(flags, AccessFlag.FINAL);
    clazz.getClassFile().setAccessFlags(flags);
    try {
        CtConstructor ct = clazz.getDeclaredConstructor(new CtClass[] {});
        if (Modifier.isPrivate(ct.getModifiers())) {
            ct.setModifiers(AccessFlag.setProtected(ct.getModifiers()));
        }
    } catch (NotFoundException ex) {
        CtConstructor c = CtNewConstructor.make("protected " + clazz.getSimpleName() + "() {}", clazz);
        clazz.addConstructor(c);
    }
}
Also used : NotFoundException(org.hotswap.agent.javassist.NotFoundException) CtConstructor(org.hotswap.agent.javassist.CtConstructor)

Example 32 with NotFoundException

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

the class ELResolverPlugin method patchJBossEl.

/*
     * JBossEL has weak reference cache. Values are stored in ThreadGroupContext cache, that must be flushed from appropriate thread.
     * Therefore we must create request for cleanup cache in PURGE_CLASS_CACHE_METHOD and own cleanup is executed indirectly when
     * application calls getBeanProperty(...).
     */
private static void patchJBossEl(CtClass ctClass) {
    try {
        ctClass.addField(new CtField(CtClass.booleanType, "$$ha$purgeRequested", ctClass), CtField.Initializer.constant(false));
        ctClass.addMethod(CtNewMethod.make("public void " + PURGE_CLASS_CACHE_METHOD_NAME + "(java.lang.ClassLoader classLoader) {" + "$$ha$purgeRequested=true;" + "}", ctClass));
        try {
            CtMethod mGetBeanProperty = ctClass.getDeclaredMethod("getBeanProperty");
            mGetBeanProperty.insertBefore("if($$ha$purgeRequested) {" + "$$ha$purgeRequested=false;" + "java.lang.reflect.Method meth = javax.el.BeanELResolver.SoftConcurrentHashMap.class.getDeclaredMethod(\"$$ha$createNewInstance\", null);" + "properties = (javax.el.BeanELResolver.SoftConcurrentHashMap) meth.invoke(properties, null);" + "}");
        } catch (NotFoundException e) {
            LOGGER.debug("FIXME : checkJBoss_3_0_EL() 'getBeanProperty(...)' not found in javax.el.BeanELResolver.");
        }
    } catch (CannotCompileException e) {
        LOGGER.error("patchJBossEl() exception {}", e.getMessage());
    }
}
Also used : CtField(org.hotswap.agent.javassist.CtField) NotFoundException(org.hotswap.agent.javassist.NotFoundException) CannotCompileException(org.hotswap.agent.javassist.CannotCompileException) CtMethod(org.hotswap.agent.javassist.CtMethod)

Example 33 with NotFoundException

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

the class ELResolverPlugin method checkJBoss_3_0_EL.

private static boolean checkJBoss_3_0_EL(CtClass ctClass) {
    // JBoss EL Resolver - is recognized by "javax.el.BeanELResolver.properties" property
    try {
        CtField field = ctClass.getField("properties");
        if ((field.getModifiers() & Modifier.STATIC) != 0) {
            field.setModifiers(Modifier.STATIC);
            patchJBossEl(ctClass);
        }
        return true;
    } catch (NotFoundException e1) {
    // do nothing
    }
    return false;
}
Also used : CtField(org.hotswap.agent.javassist.CtField) NotFoundException(org.hotswap.agent.javassist.NotFoundException)

Aggregations

NotFoundException (org.hotswap.agent.javassist.NotFoundException)33 CtClass (org.hotswap.agent.javassist.CtClass)19 CtMethod (org.hotswap.agent.javassist.CtMethod)15 OnClassLoadEvent (org.hotswap.agent.annotation.OnClassLoadEvent)8 CannotCompileException (org.hotswap.agent.javassist.CannotCompileException)8 CtField (org.hotswap.agent.javassist.CtField)7 CtConstructor (org.hotswap.agent.javassist.CtConstructor)5 ClassPool (org.hotswap.agent.javassist.ClassPool)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 IdentityHashMap (java.util.IdentityHashMap)2 BadBytecode (org.hotswap.agent.javassist.bytecode.BadBytecode)2 ConstPool (org.hotswap.agent.javassist.bytecode.ConstPool)2 ExceptionTable (org.hotswap.agent.javassist.bytecode.ExceptionTable)2 ExprEditor (org.hotswap.agent.javassist.expr.ExprEditor)2 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1