检测方法时发生Javaassist源错误

检测方法时发生Javaassist源错误,java,reflection,instrumentation,Java,Reflection,Instrumentation,我正在尝试在我的一个实体(com.xxx.entity.Order)中插入一个方法: 有人能帮我吗?让它工作起来,问题是调用invoke方法。当尝试在第二个参数为null的情况下调用invoke方法时,它成功了。(不太清楚为什么?) private String getLookupMethodString() { return new StringBuilder( "public java.lang.String lookupCustomValue(java.la

我正在尝试在我的一个实体(com.xxx.entity.Order)中插入一个方法:


有人能帮我吗?

让它工作起来,问题是调用invoke方法。当尝试在第二个参数为null的情况下调用invoke方法时,它成功了。(不太清楚为什么?)

private String getLookupMethodString() {
    return new StringBuilder(
            "public java.lang.String lookupCustomValue(java.lang.String fieldName) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.beans.IntrospectionException {").append(
            "java.lang.String mappingFieldName =  \"value1\";").append(
            "com.xxx.entity.CustomFieldValue cfv = (com.xxx.entity.CustomFieldValue) new java.beans.PropertyDescriptor(\"customFieldValue\", getClass()).getReadMethod().invoke(this);").append(
            "return (java.lang.String) new java.beans.PropertyDescriptor(mappingFieldName, com.xxx.entity.CustomFieldValue.class).getReadMethod().invoke(cfv);}").toString();
}

public byte[] transform(ClassLoader clazzLoader, String className, Class<?> clazz, ProtectionDomain arg3, byte[] rawBytes) throws IllegalClassFormatException {
    CtClass cl = pool.makeClass(new java.io.ByteArrayInputStream(rawBytes));
    String lookupMethodString = getLookupMethodString();
    CtMethod lookupMethod = CtMethod.make(lookupMethodString, cl); // Error encountered at this line.
    cl.addMethod(lookupMethod);
}
[source error] invoke(com.xxx.entity.CustomFieldValue) not found in java.lang.reflect.Method
return (java.lang.String) new java.beans.PropertyDescriptor(mappingFieldName, com.xxx.entity.CustomFieldValue.class).getReadMethod().invoke(cfv, null);}").toString();