HHH-16832 Bytecode enhancement leads to broken constructor for a generic embedded field in a MappedSuperclass

This commit is contained in:
Andrea Boriero 2023-06-21 16:38:43 +02:00 committed by Andrea Boriero
parent d65b74c934
commit 4dd1dd63be
2 changed files with 10 additions and 4 deletions

View File

@ -607,14 +607,20 @@ class CodeTemplates {
// mapping to get private field from superclass by calling the enhanced reader, for use when field is not visible
static class GetterMapping implements Advice.OffsetMapping {
private final FieldDescription persistentField;
private final TypeDescription.Generic returnType;
private final String name;
GetterMapping(FieldDescription persistentField) {
this.persistentField = persistentField;
this( persistentField, persistentField.getType() );
}
GetterMapping(FieldDescription persistentField, TypeDescription.Generic returnType) {
this.name = persistentField.getName();
this.returnType = returnType;
}
@Override public Target resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, Advice.ArgumentHandler argumentHandler, Sort sort) {
MethodDescription.Token signature = new MethodDescription.Token( EnhancerConstants.PERSISTENT_FIELD_READER_PREFIX + persistentField.getName(), Opcodes.ACC_PUBLIC, persistentField.getType() );
MethodDescription.Token signature = new MethodDescription.Token( EnhancerConstants.PERSISTENT_FIELD_READER_PREFIX + name , Opcodes.ACC_PUBLIC, returnType );
MethodDescription method = new MethodDescription.Latent( instrumentedType.getSuperClass().asErasure(), signature );
return new Target.AbstractReadOnlyAdapter() {

View File

@ -87,7 +87,7 @@ final class InlineDirtyCheckingHandler implements Implementation, ByteCodeAppend
Advice.WithCustomMapping advice = Advice.withCustomMapping();
advice = persistentField.isVisibleTo( managedCtClass )
? advice.bind( CodeTemplates.FieldValue.class, persistentField.getFieldDescription() )
: advice.bind( CodeTemplates.FieldValue.class, new CodeTemplates.GetterMapping( persistentField.getFieldDescription() ) );
: advice.bind( CodeTemplates.FieldValue.class, new CodeTemplates.GetterMapping( persistentField.getFieldDescription(), persistentField.getGetter().get().getReturnType() ) );
implementation = advice
.bind( CodeTemplates.FieldName.class, persistentField.getName() )