use of javassist.LoaderClassPath in project pinpoint by naver.
the class JavassistVerifyErrorTest method bug_regression_BytecodeVerifyError_Invalid_StackMapFrame.
/**
* bug id
* https://github.com/naver/pinpoint/issues/1807
* @throws Exception
*/
@Ignore("fixed Javassist 3.21.0-GA")
@Test
public void bug_regression_BytecodeVerifyError_Invalid_StackMapFrame() throws Exception {
CustomURLClassLoader classLoader = new CustomURLClassLoader(new URL[] {}, Thread.currentThread().getContextClassLoader());
ClassPool classPool = new ClassPool(true);
classPool.appendClassPath(new LoaderClassPath(classLoader));
final CtClass ctClass = classPool.get(INVALID_STACK_MAP_FRAME);
final CtMethod method = ctClass.getDeclaredMethod("bytecodeVerifyError");
method.addLocalVariable("test_localVariable", CtClass.intType);
method.insertBefore("{ test_localVariable = 1; }");
final byte[] bytecode = ctClass.toBytecode();
classLoader.defineClass0(INVALID_STACK_MAP_FRAME, bytecode);
try {
Class.forName(INVALID_STACK_MAP_FRAME, true, classLoader);
Assert.fail("VerifyError");
} catch (VerifyError e) {
logger.debug("verifyError:{}", e.getMessage(), e);
}
final ASMBytecodeDisassembler bytecodeDisassembler = new ASMBytecodeDisassembler();
final String dumpBytecode = bytecodeDisassembler.dumpBytecode(bytecode);
logger.debug("dumpBytecode:{}", dumpBytecode);
// javassist bug : invalid stack map frame
// 00013 InvalidStackMapFrame ArrayList String Iterator I : : FRAME FULL [bug_regression_jdk7/javassist/InvalidStackMapFrame java/util/ArrayList [[[java/lang/Object->[Ljava/lang/String;]]] java/util/Iterator T T T I] []
final String verify = bytecodeDisassembler.dumpVerify(bytecode, classLoader);
logger.debug("dumpVerify:{}", verify);
final String dumpAsm = bytecodeDisassembler.dumpASM(bytecode);
logger.debug("dumpAsm :{}", dumpAsm);
}
use of javassist.LoaderClassPath in project HikariCP by brettwooldridge.
the class JavassistProxyFactory method main.
public static void main(String... args) {
classPool = new ClassPool();
classPool.importPackage("java.sql");
classPool.appendClassPath(new LoaderClassPath(JavassistProxyFactory.class.getClassLoader()));
try {
// Cast is not needed for these
String methodBody = "{ try { return delegate.method($$); } catch (SQLException e) { throw checkException(e); } }";
generateProxyClass(Connection.class, ProxyConnection.class.getName(), methodBody);
generateProxyClass(Statement.class, ProxyStatement.class.getName(), methodBody);
generateProxyClass(ResultSet.class, ProxyResultSet.class.getName(), methodBody);
// For these we have to cast the delegate
methodBody = "{ try { return ((cast) delegate).method($$); } catch (SQLException e) { throw checkException(e); } }";
generateProxyClass(PreparedStatement.class, ProxyPreparedStatement.class.getName(), methodBody);
generateProxyClass(CallableStatement.class, ProxyCallableStatement.class.getName(), methodBody);
modifyProxyFactory();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of javassist.LoaderClassPath in project hibernate-orm by hibernate.
the class EnhancerImpl method buildClassPool.
private ClassPool buildClassPool(JavassistEnhancementContext enhancementContext) {
ClassPool classPool = new ClassPool(false) {
@Override
public ClassLoader getClassLoader() {
return enhancementContext.getLoadingClassLoader();
}
};
ClassLoader loadingClassLoader = enhancementContext.getLoadingClassLoader();
if (loadingClassLoader != null) {
classPool.appendClassPath(new LoaderClassPath(loadingClassLoader));
}
return classPool;
}
use of javassist.LoaderClassPath in project dubbo by alibaba.
the class ClassGenerator method getClassPool.
public static ClassPool getClassPool(ClassLoader loader) {
if (loader == null)
return ClassPool.getDefault();
ClassPool pool = POOL_MAP.get(loader);
if (pool == null) {
pool = new ClassPool(true);
pool.appendClassPath(new LoaderClassPath(loader));
POOL_MAP.put(loader, pool);
}
return pool;
}
use of javassist.LoaderClassPath in project pinpoint by naver.
the class LegacyProfilerPluginClassInjector method loadFromOtherClassLoader.
private Class<?> loadFromOtherClassLoader(ClassLoader classLoader, String className) throws NotFoundException, IllegalArgumentException, IOException, CannotCompileException, IllegalAccessException, InvocationTargetException {
ClassPool pool = new ClassPool();
pool.appendClassPath(new LoaderClassPath(classLoader));
pool.appendClassPath(new LoaderClassPath(sourceClassLoader));
return loadFromOtherClassLoader(pool, classLoader, className);
}
Aggregations