javassist

post-compilation removal of annotations from byte code

跟風遠走 提交于 2019-12-03 08:02:27
we are using a library that contains beans that are annotated with JAXB annotations. nothing in the way we use these classes depends on JAXB. in other words, we don't need JAXB and do not depend on the annotations. however, because the annotations exist, they end up being referenced by other classes that process annotations. this requires me to bundle JAXB in our application, which isn't allowed, because JAXB is in the javax.* package (android doesn't allow "core libraries" to be included in your application). so, with this in mind, i'm looking for a way to remove the annotations from the

升级Java 11 后报错 nable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]

↘锁芯ラ 提交于 2019-12-03 06:16:56
java 升级到 11 后使用 spring-data-jpa 会报错 Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; ...... Caused by: org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister ...... Caused by: org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer] 这是因为 hibernate 实现依赖 javassist 而目前 javassist 是 3.22.0 版本,暂时不支持 java 11 ,这就是版本不支持的原因造成的 只需要升级一下 javassist 版本即可 目前是 3.23.1-GA 注意: 这种情况仅仅适用于升级 java 之前正常,升级之后出现此错误的原因

custom class loader for android?

六月ゝ 毕业季﹏ 提交于 2019-12-03 03:37:35
I'm writing an instrumentation library that I'd like to work on both desktop and mobile (Android). It functions by: Exposing a main which takes a single parameter, the main of the target class Installing a class loader which intercepts all classes as they are loaded and instruments them Like so: // Expects args[0] to contain the name of the INNER main public static void main(String[] args) throws Throwable { String className = args[0]; String [] newArgs = new String[0]; if(args.length > 1) { newArgs = Arrays.copyOfRange(args, 1, args.length-1); } System.out.println("Bootstrapping " + className

How can I create a dynamic proxy in java that retains parameter annotations on methods?

↘锁芯ラ 提交于 2019-12-03 02:46:59
I currently am trying to proxy some existing JAX/RS resources, in order to allow me to use the Hibernate Validator's method validation support. However, when I proxy my class (currently using cglib 2.2), the FormParam annotation is not present on parameters in the proxy class, and so the JAX/RS runtime (apache wink) is not populating parameters. Here's some test code that shows this: import static java.lang.annotation.ElementType.*; import static java.lang.annotation.RetentionPolicy.*; import java.lang.annotation.Annotation; import java.lang.annotation.Retention; import java.lang.annotation

What does “()V” mean in a class signature?

我是研究僧i 提交于 2019-12-02 16:46:39
I created a constructor with Javassist which has no real method CtConstructor c = CtNewConstructor.make ( argTypes, null, newClass ); When I'm trying to put out the signature of this class c.getSignature(); I get public Echo ()V I'm confused what "V" means? I expected either public Echo (); or something similar... The JVM uses a compact way of storing method signatures, of which constructors are considered a special case. For your example: () indicates a method taking no arguments V indicates that it returns nothing The other parts of the scheme are: B - byte C - char D - double F - float I -

Java 静态代理和动态代理的使用及原理解析

☆樱花仙子☆ 提交于 2019-12-01 19:53:46
代理模式是软件开发中常见的设计模式,它的目的是让调用者不用持有具体操作者的引用,而是通过代理者去对具体操作者执行具体的操作。 静态代理的实现 操作接口: public interface Operate { void doSomething(); } 复制代码 操作者: public class Operator implements Operate { @Override public void doSomething() { System.out.println("I'm doing something"); } } 复制代码 代理者: public class OperationProxy implements Operate { private Operator operator = null; @Override public void doSomething() { beforeDoSomething(); if(operator == null){ operator = new Operator(); } operator.doSomething(); afterDoSomething(); } private void beforeDoSomething() { System.out.println("before doing something"); }

Adding an annotation to a runtime generated class using Javassist

依然范特西╮ 提交于 2019-12-01 19:42:45
I'm using Javassist(Java 1.7) to add an annotation to the class ClassA, but i get the exception. What am i doing wrong? The code I tried looks like this: ClassA.java public class ClassA { } add method public static <T> Class<T> addXmlRootAnnotationDynamicly(Class<T> declaredTyp) throws NotFoundException, CannotCompileException, InstantiationException, IllegalAccessException { //pool creation ClassPool pool = ClassPool.getDefault(); //extracting the class CtClass cc = pool.getCtClass(declaredTyp.getCanonicalName()); // create the annotation ClassFile ccFile = cc.getClassFile(); ConstPool

Create class with javassist and make it available

孤者浪人 提交于 2019-12-01 12:35:18
I want to do the following: try { Class.forName("MyClass"); } catch(ClassNotFoundException e) { ClassPool pool = ClassPool.getDefault(); CtClass cc = pool.makeClass("MyClass"); Class.forName("MyClass"); } I have tried it, but it doesn't seem to work always... It works in one context, but in the other the same code is crashing on the second "Class.forName("MyClass")"... Calling cc.toClass() always brings the correct class, and have tried cc.writeFile() but it makes no difference. Somehow, in some cases the second Class.forName finds the class, and in other cases it just breaks... Am I missing

Create class with javassist and make it available

浪尽此生 提交于 2019-12-01 11:02:35
问题 I want to do the following: try { Class.forName("MyClass"); } catch(ClassNotFoundException e) { ClassPool pool = ClassPool.getDefault(); CtClass cc = pool.makeClass("MyClass"); Class.forName("MyClass"); } I have tried it, but it doesn't seem to work always... It works in one context, but in the other the same code is crashing on the second "Class.forName("MyClass")"... Calling cc.toClass() always brings the correct class, and have tried cc.writeFile() but it makes no difference. Somehow, in

difference between javaassist and cglib

天涯浪子 提交于 2019-12-01 09:24:00
I learning hibernate and I understood that hibernate has stopped using cglib and switched to javaassist. I also understood that javaassist and cglib are used for proxy generation. so I was wondering how these two works and which one is better? What is the difference between their working style? Cglib is no longer actively maintained and the library's developers would not even apply provided patches: https://jaxenter.com/hibernate-to-deprecate-cglib-as-bytecode-provider-102106.html Additionally, javassist offers an API for modifying classes and not only for subclassing them. These APIs allow