javassist

problem with classes not found during PlayPlugin.enhance

谁说我不能喝 提交于 2019-12-13 15:29:00
问题 I'm experimenting with a basic bytecode enhancement in a Play plugin, but when it tries to operate on the ApplicationClasses.ApplicationClass that it's given, the class can't be found. public void enhance(ApplicationClasses.ApplicationClass applicationClass) throws NotFoundException, IOException, CannotCompileException { ClassPool classPool = ClassPool.getDefault(); CtClass ctClass = classPool.get(applicationClass.name); ... } The exception is Oops: NotFoundException An unexpected error

Adding a class to the class path with a Java Agent

我与影子孤独终老i 提交于 2019-12-12 12:27:55
问题 I'm using a Java Agent and Javassist to add some logging to some JDK classes. Essentially when the system loads some TLS classes, Javassist will add some additional bytecode to them to help me debug some connection problems. Here's the problem, given this class is included in the agent jar: package com.something.myagent; public class MyAgentPrinter { public static final void sayHello() { System.out.println("Hello!"); } } In my agent's transform method, let's say I tried to invoke that class

Attach proxy to an existing object?

点点圈 提交于 2019-12-12 10:44:47
问题 My plan is to write a annotation based caching framework which caches the return values of methods. When a method gets called the first time with a specific parameter, then the cache should store the methods return value. When the same method gets called a second time with the same parameter then the method should return the previously calculated result from the cache and not execute its code again. My annotations looks like this: @Cached(cacheProvider = HashMapCacheProvider.class) public

Is there Scala aware high level byte-code manipulation tool like Javassist?

馋奶兔 提交于 2019-12-12 10:29:16
问题 I am looking for a high level bytecode manipulation tool like Javassist, but that understands some of Scala peculiarities. Lower level bytecode manipulation tools should be relatively agnostic, but for my use cases something at the level of Javassist is much better. However a tool at that level needs to know about the source language and its bytecode mapping. Does something like this exist for Scala? So far I have been able to use Javassist with Scala for very simple things, but I have been

Javassist CannotCompileException when trying to add a line to create a Map

与世无争的帅哥 提交于 2019-12-12 04:39:46
问题 um trying to instrument a method to do the following task. Task - Create a Map and insert values to the map Adding System.out.println lines wouldn't cause any exception. But when i add the line to create the Map, it throws a cannotCompileException due to a missing ; . When i print the final string it doesn't seem to miss any. What am i doing wrong here. public void createInsertAt(CtMethod method, int lineNo, Map<String,String> parameterMap) throws CannotCompileException { StringBuilder

How to get constant pool table with javassist

老子叫甜甜 提交于 2019-12-11 10:52:14
问题 How can we get the constant pool table from the class file using javassist? I have written the code till here: ClassPool pool = ClassPool.getDefault(); pool.insertClassPath(filepath); CtClass cc = pool.get(filename); Now please, please tell me the further steps. 回答1: Once you have the CtClass you just need to access the classFile object to retrieve the constant pool, like the following: ClassPool pool = ClassPool.getDefault(); pool.insertClassPath(filepath); CtClass cc = pool.get(filename);

Adding method parameter name with javassist

故事扮演 提交于 2019-12-11 07:44:08
问题 How can I add method parameter names to a method, when none exists? There are some examples on how to retrieve these names, if they exist, with a method like this: CtMethod m; CodeAttribute codeAttribute = m.getMethodInfo().getCodeAttribute(); if (codeAttribute != null) { LocalVariableAttribute table = (LocalVariableAttribute) codeAttribute.getAttribute(LocalVariableAttribute.tag); if (table != null) for (int i = 0; i < table.tableLength(); i++) m.getMethodInfo().getConstPool().getUtf8Info

How to extend a final class?(Reflection, Javassist)

橙三吉。 提交于 2019-12-11 05:49:28
问题 I have a .JAR file and it has tons of classes. One, that I need is set as final, so I cannot extend it. There is one method, that I basically have to extend and fix, otherwise everything breaks. How can I do that? I know Reflection and Javassist can be used for this, but I have no idea how. Any other tool is also acceptable, as long as it works. 回答1: You can't use reflection to modify existing class definitions. If the licence of that JAR allows you to, I would suggest a different solution:

Add annotation to a parameter on a new method created with Javassist

…衆ロ難τιáo~ 提交于 2019-12-11 03:30:11
问题 I am in need to add an annotation to a method parameter. The method is previously created with javassist like: CtClass cc2 = pool.makeClass("Dummy"); CtMethod method = CtNewMethod.make("public java.lang.String dummyMethod( java.lang.String oneparam){ return null; }", cc2); The annotation I want to add is quite simple: @Target(ElementType.PARAMETER) @Retention(RetentionPolicy.RUNTIME) public @interface Param { /** Name of the parameter */ String name() default ""; } 1) writting the annotation

Javassist no such field when variable clearly exists

ε祈祈猫儿з 提交于 2019-12-10 19:33:28
问题 I am trying to inject code into the minecraft 1.8 jar using javassist. The insertBefore & insertAfter methods work perfectly fine. But the insert at method does not work as expected. I am getting this error: https://gist.github.com/czaarek99/dda36426318f331ce6b0 Here is the code that handles the injection: if (className.equals(mappingManager.getMapping(CommonMappings.MINECRAFT_CLASS))) { CtClass ctClass = classPool.get(mappingManager.getMapping(CommonMappings.MINECRAFT_CLASS, true)); /