Я пытаюсь инструмент метода в одном из моих сущностей (com.xxx.entity.Order):Javaassist Ошибка источника в то время как инструментирование метод
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);
}
Поля customFieldValue также инструментальные в этом классе, поэтому я использую отражение, чтобы получить его значение. Ошибка, которую я получаю от этого:
[source error] invoke(com.xxx.entity.CustomFieldValue) not found in java.lang.reflect.Method
Может кто-нибудь, пожалуйста, помогите мне в этом?