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);
}
}
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());
}
}
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;
}
Aggregations