public Class<?> toClass(ClassLoader loader, ProtectionDomain pd) { if (mCtc != null) { mCtc.detach(); CtClass ctcs = mSuperClass == null ? null : mPool.get(mSuperClass); if (mClassName == null) { mClassName = (mSuperClass == null || javassist.Modifier.isPublic(ctcs.getModifiers()) ? ClassGenerator.class.getName() : mSuperClass + "$sc") + id; mCtc = mPool.makeClass(mClassName); if (mSuperClass != null) { mCtc.setSuperclass(ctcs); mCtc.addInterface(mPool.get(DC.class.getName())); // add dynamic class tag. if (mInterfaces != null) { for (String cl : mInterfaces) { throw new RuntimeException(e.getMessage(), e); } catch (CannotCompileException e) { throw new RuntimeException(e.getMessage(), e);
private CtClass produceProxyClass(CtClass orgclass, Class orgRtClass) throws CannotCompileException, NotFoundException int modify = orgclass.getModifiers(); if (Modifier.isAbstract(modify) || Modifier.isNative(modify) || !Modifier.isPublic(modify)) throw new CannotCompileException(orgclass.getName() + " must be public, non-native, and non-abstract."); CtClass proxy = classPool.makeClass(orgclass.getName(), orgclass.getSuperclass()); = new CtField(classPool.get("javassist.tools.rmi.ObjectImporter"), fieldImporter, proxy); f.setModifiers(Modifier.PRIVATE); throw new CannotCompileException(e);
@Override public Class<?> loadClass() { try { Class<?> loadClass = clazz.toClass(GeccoClassLoader.get(), null); log.debug("load class : " + clazz.getName()); return loadClass; } catch (CannotCompileException e) { e.printStackTrace(); log.error(clazz.getName() + " cannot compile," + e.getMessage()); return null; } finally { // clazz.detach(); } }
String METHOD_P1 = PerfCounterPack.class.getName(); if (bodyTable.containsKey(METHOD_COUNTER) == false) throw new CannotCompileException("no method body: " + METHOD_COUNTER); ClassPool cp = ClassPool.getDefault(); String jar = FileUtil.getJarFileName(PluginLoader.class); if (jar != null) { cp.appendClassPath(jar); CtClass cc = cp.get(superName); CtClass impl = null; CtMethod method_counter = null; try { impl = cp.get(className); impl.defrost(); method_counter = impl.getMethod(METHOD_COUNTER, METHOD_SIGNATURE); } catch (NotFoundException e) { impl = cp.makeClass(className, cc); sb.append("public void ").append(METHOD_COUNTER).append("(").append(METHOD_P1).append(" p1){}"); method_counter = CtNewMethod.make(sb.toString(), impl); impl.addMethod(method_counter); return plugin; } catch (CannotCompileException ee) { Logger.println("PLUG-IN : " + ee.getMessage()); } catch (Throwable e) { Logger.println("A161", e);
thisClass.getClassFile(); // to call checkModify(). ConstPool constPool = getConstPool(); int pos = currentPos; int index = iterator.u16bitAt(pos + 1); ClassPool cp = thisClass.getClassPool(); CodeAttribute ca = iterator.get(); = new CtClass[] { cp.get(javaLangObject) }; CtClass retType = getType(); int paramVar = ca.getMaxLocals(); jc.recordParams(javaLangObject, params, true, paramVar, withinStatic()); catch (CompileError e) { throw new CannotCompileException(e); } catch (NotFoundException e) { throw new CannotCompileException(e); } catch (BadBytecode e) { throw new CannotCompileException("broken method");
cc.checkModify(); ClassPool pool = cc.getClassPool(); String fname; int i = 0; fname = "_cflow$" + i++; try { cc.getDeclaredField(fname); pool.recordCflow(name, declaringClass.getName(), fname); try { CtClass type = pool.get("javassist.runtime.Cflow"); CtField field = new CtField(type, fname, cc); field.setModifiers(Modifier.PUBLIC | Modifier.STATIC); throw new CannotCompileException(e);
cc.checkModify(); if (isClassInitializer()) throw new CannotCompileException("class initializer"); CodeAttribute ca = methodInfo.getCodeAttribute(); CodeIterator iterator = ca.iterator(); Bytecode b = new Bytecode(methodInfo.getConstPool(), ca.getMaxStack(), ca.getMaxLocals()); b.setStackDepth(ca.getMaxStack()); Javac jv = new Javac(b, cc); ca.setMaxStack(b.getMaxStack()); ca.setMaxLocals(b.getMaxLocals()); iterator.skipConstructor(); int pos = iterator.insertEx(b.get()); iterator.insert(b.getExceptionTable(), pos); methodInfo.rebuildStackMapIf6(cc.getClassPool(), cc.getClassFile2()); throw new CannotCompileException(e); throw new CannotCompileException(e); throw new CannotCompileException(e);
cc.checkModify(); ConstPool cp = methodInfo.getConstPool(); CodeAttribute ca = methodInfo.getCodeAttribute(); CodeIterator iterator = ca.iterator(); Bytecode b = new Bytecode(cp, ca.getMaxStack(), ca.getMaxLocals()); b.setStackDepth(1); Javac jv = new Javac(b, cc); try { jv.recordParams(getParameterTypes(), Modifier.isStatic(getModifiers())); int var = jv.recordVariable(exceptionType, exceptionName); b.addAstore(var); ca.setMaxLocals(locals); int len = iterator.getCodeLength(); int pos = iterator.append(b.get()); ca.getExceptionTable().add(getStartPosOfBody(ca), len, len, cp.addClassInfo(exceptionType)); iterator.append(b.getExceptionTable(), pos); methodInfo.rebuildStackMapIf6(cc.getClassPool(), cc.getClassFile2()); throw new CannotCompileException(e); throw new CannotCompileException(e); } catch (BadBytecode e) { throw new CannotCompileException(e);
static void setBody0(CtClass srcClass, MethodInfo srcInfo, CtClass destClass, MethodInfo destInfo, ClassMap map) throws CannotCompileException { destClass.checkModify(); map = new ClassMap(map); map.put(srcClass.getName(), destClass.getName()); try { CodeAttribute cattr = srcInfo.getCodeAttribute(); if (cattr != null) { ConstPool cp = destInfo.getConstPool(); CodeAttribute ca = (CodeAttribute)cattr.copy(cp, map); destInfo.setCodeAttribute(ca); // a stack map table is copied to destInfo. } } catch (CodeAttribute.RuntimeCopyException e) { /* the exception may be thrown by copy() in CodeAttribute. */ throw new CannotCompileException(e); } destInfo.setAccessFlags(destInfo.getAccessFlags() & ~AccessFlag.ABSTRACT); destClass.rebuildClassFile(); }
int mod = m.getModifiers(); if (m.getDeclaringClass() != Object.class && !Modifier.isFinal(mod)) if (Modifier.isPublic(mod)) { CtMethod body; if (Modifier.isStatic(mod)) body = forwardStaticMethod; else proxy); wmethod.setModifiers(mod); proxy.addMethod(wmethod); else if (!Modifier.isProtected(mod) && !Modifier.isPrivate(mod)) throw new CannotCompileException( "the methods must be public, protected, or private.");
byte[] b = ct.toBytecode(); java.lang.reflect.Method method; Object[] args; if (domain == null) { method = defineClass1; args = new Object[] { ct.getName(), b, new Integer(0), new Integer(b.length)}; args = new Object[] { ct.getName(), b, new Integer(0), new Integer(b.length), domain}; return (Class)toClass2(method, loader, args); throw new CannotCompileException(e.getTargetException()); throw new CannotCompileException(e);
protected void createSetActivityContextInterfaceMethod( CtClass activityContextInterface) { String methodToAdd = "public void sbbSetActivityContextInterface( Object aci ) {" + "this.sbbActivityContextInterface = (" + activityContextInterface.getName() + ") aci ; } "; CtMethod methodTest; try { methodTest = CtNewMethod.make(methodToAdd, sbbConcreteClass); sbbConcreteClass.addMethod(methodTest); logger.debug("Method " + methodToAdd + " added"); } catch (CannotCompileException cce) { cce.printStackTrace(); } }
CodeAttribute codeAttr = minfo.getCodeAttribute(); if (codeAttr == null || transformers == null) return; t.initialize(cp, clazz, minfo); CodeIterator iterator = codeAttr.iterator(); while (iterator.hasNext()) { try { int pos = iterator.next(); for (t = transformers; t != null; t = t.getNext()) pos = t.transform(clazz, pos, iterator, cp); throw new CannotCompileException(e); codeAttr.setMaxLocals(codeAttr.getMaxLocals() + locals); minfo.rebuildStackMapIf6(clazz.getClassPool(), clazz.getClassFile2()); throw new CannotCompileException(b.getMessage(), b);
public static void disassemble(CtClass clazz, PrintStream out, boolean evenSuperclassMethods) { out.println("Class " + clazz.getName()); for (CtConstructor ctor : clazz.getConstructors()) try { disassemble(ctor.toMethod(ctor.getName(), clazz), out); } catch (CannotCompileException e) { e.printStackTrace(out); } for (CtMethod method : clazz.getDeclaredMethods()) if (evenSuperclassMethods || method.getDeclaringClass().equals(clazz)) disassemble(method, out); }
private static void checkSignature(CtMethod wrappedBody, String descriptor) throws CannotCompileException { if (!descriptor.equals(wrappedBody.getMethodInfo2().getDescriptor())) throw new CannotCompileException( "wrapped method with a bad signature: " + wrappedBody.getDeclaringClass().getName() + '.' + wrappedBody.getName()); }
private CtField(String typeDesc, String name, CtClass clazz) throws CannotCompileException { super(clazz); ClassFile cf = clazz.getClassFile2(); if (cf == null) throw new CannotCompileException("bad declaring class: " + clazz.getName()); fieldInfo = new FieldInfo(cf.getConstPool(), name, typeDesc); }
code.setMaxStack(stacksize); code.setMaxLocals(localsize); m = new MethodInfo(cf.getConstPool(), "<clinit>", "()V"); m.setAccessFlags(AccessFlag.STATIC); m.setCodeAttribute(code.toCodeAttribute()); cf.addMethod(m); CtMember.Cache cache = hasMemberCache(); CodeAttribute codeAttr = m.getCodeAttribute(); if (codeAttr == null) throw new CannotCompileException("empty <clinit>"); CodeIterator it = codeAttr.iterator(); int pos = it.insertEx(code.get()); it.insert(code.getExceptionTable(), pos); int maxstack = codeAttr.getMaxStack(); if (maxstack < stacksize) codeAttr.setMaxStack(stacksize); int maxlocals = codeAttr.getMaxLocals(); throw new CannotCompileException(e); throw new CannotCompileException(e);
/** * Inserts a new parameter, which becomes the first parameter. */ public void insertParameter(CtClass type) throws CannotCompileException { declaringClass.checkModify(); String desc = methodInfo.getDescriptor(); String desc2 = Descriptor.insertParameter(type, desc); try { addParameter2(Modifier.isStatic(getModifiers()) ? 0 : 1, type, desc); } catch (BadBytecode e) { throw new CannotCompileException(e); } methodInfo.setDescriptor(desc2); }
throws CannotCompileException declaringClass.checkModify(); ConstPool cp = methodInfo.getConstPool(); CodeAttribute ca = methodInfo.getCodeAttribute(); if (ca == null) throw new CannotCompileException("no method body"); LocalVariableAttribute va = (LocalVariableAttribute)ca.getAttribute( LocalVariableAttribute.tag); if (va == null) { va = new LocalVariableAttribute(cp); ca.getAttributes().add(va); int maxLocals = ca.getMaxLocals(); String desc = Descriptor.of(type); va.addEntry(0, ca.getCodeLength(),
throws CannotCompileException String d1 = origMethod.getMethodInfo2().getDescriptor(); String d2 = substMethod.getMethodInfo2().getDescriptor(); if (!d1.equals(d2)) throw new CannotCompileException("signature mismatch: " + substMethod.getLongName()); if (Modifier.isStatic(mod1) != Modifier.isStatic(mod2) || (Modifier.isPrivate(mod1) && !Modifier.isPrivate(mod2)) || origMethod.getDeclaringClass().isInterface() != substMethod.getDeclaringClass().isInterface()) throw new CannotCompileException("invoke-type mismatch " + substMethod.getLongName());