Bytecode enhancement with Generics on @MappedSuperclass crashes bootstrapping while using Bytebuddy

Description

It seems that bytecode enhancement has changed from 5.2 to 5.3:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 @Entity @Cache(usage = CacheConcurrencyStrategy.NONE) public class Generic extends AbstractGeneric<Generic.Type> { public enum Type implements Marker { ONE } } @MappedSuperclass @Cache(usage = CacheConcurrencyStrategy.NONE) public class AbstractGeneric<T extends Marker> { @Id @GeneratedValue public int id; @Access(AccessType.PROPERTY) private T entity; private T getEntity() { return entity; } private void setEntity(T entity) { this.entity = entity; } } public interface Marker { }

Using bytecode enhancement and bootstrapping Hibernate results in:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 Error performing callback invocation : org.hibernate.testing.junit4.BaseCoreFunctionalTestCase#buildSessionFactory org.hibernate.testing.junit4.CallbackException: org.hibernate.testing.junit4.BaseCoreFunctionalTestCase#buildSessionFactory at org.hibernate.testing.junit4.TestClassMetadata.performCallbackInvocation(TestClassMetadata.java:208) at org.hibernate.testing.junit4.TestClassMetadata.invokeCallback(TestClassMetadata.java:192) at org.hibernate.testing.junit4.TestClassMetadata.performCallbacks(TestClassMetadata.java:184) at org.hibernate.testing.junit4.TestClassMetadata.performBeforeClassCallbacks(TestClassMetadata.java:175) at org.hibernate.testing.junit4.BeforeClassCallbackHandler.evaluate(BeforeClassCallbackHandler.java:25) at org.hibernate.testing.junit4.AfterClassCallbackHandler.evaluate(AfterClassCallbackHandler.java:25) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) Caused by: java.lang.VerifyError: Bad return type Exception Details: Location: com/genericsenhancement/Generic.$$_hibernate_read_entity()Lcom/genericsenhancement/Generic$Type; @34: areturn Reason: Type 'com/genericsenhancement/Marker' (current frame, stack[0]) is not assignable to 'com/genericsenhancement/Generic$Type' (from method signature) Current Frame: bci: @34 flags: { } locals: { 'com/genericsenhancement/Generic' } stack: { 'com/genericsenhancement/Marker' } Bytecode: 0x0000000: 2ab6 0044 c600 1a2a 2ab6 0044 2a12 592a 0x0000010: b700 5cb9 0060 0400 c000 62b7 0066 2ab7 0x0000020: 005c b0 Stackmap Table: same_frame(@30) at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) at java.lang.Class.getDeclaredMethods(Class.java:1975) at org.hibernate.annotations.common.reflection.java.JavaXClass.getDeclaredMethodProperties(JavaXClass.java:95) at org.hibernate.annotations.common.reflection.java.JavaXClass.getDeclaredProperties(JavaXClass.java:112) at org.hibernate.annotations.common.reflection.java.JavaXClass.getDeclaredProperties(JavaXClass.java:104) at org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:252) at org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:211) at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:767) at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:250) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:231) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:274) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:84) at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:474) at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:85) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:689) at org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.buildSessionFactory(BaseCoreFunctionalTestCase.java:117) at org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.buildSessionFactory(BaseCoreFunctionalTestCase.java:104) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.hibernate.testing.junit4.TestClassMetadata.performCallbackInvocation(TestClassMetadata.java:205) ... 11 more org.hibernate.testing.junit4.CallbackException: org.hibernate.testing.junit4.BaseCoreFunctionalTestCase#buildSessionFactory at org.hibernate.testing.junit4.TestClassMetadata.performCallbackInvocation(TestClassMetadata.java:208) at org.hibernate.testing.junit4.TestClassMetadata.invokeCallback(TestClassMetadata.java:192) at org.hibernate.testing.junit4.TestClassMetadata.performCallbacks(TestClassMetadata.java:184) at org.hibernate.testing.junit4.TestClassMetadata.performBeforeClassCallbacks(TestClassMetadata.java:175) at org.hibernate.testing.junit4.BeforeClassCallbackHandler.evaluate(BeforeClassCallbackHandler.java:25) at org.hibernate.testing.junit4.AfterClassCallbackHandler.evaluate(AfterClassCallbackHandler.java:25) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) Caused by: java.lang.VerifyError: Bad return type Exception Details: Location: com/genericsenhancement/Generic.$$_hibernate_read_entity()Lcom/genericsenhancement/Generic$Type; @34: areturn Reason: Type 'com/genericsenhancement/Marker' (current frame, stack[0]) is not assignable to 'com/genericsenhancement/Generic$Type' (from method signature) Current Frame: bci: @34 flags: { } locals: { 'com/genericsenhancement/Generic' } stack: { 'com/genericsenhancement/Marker' } Bytecode: 0x0000000: 2ab6 0044 c600 1a2a 2ab6 0044 2a12 592a 0x0000010: b700 5cb9 0060 0400 c000 62b7 0066 2ab7 0x0000020: 005c b0 Stackmap Table: same_frame(@30) at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) at java.lang.Class.getDeclaredMethods(Class.java:1975) at org.hibernate.annotations.common.reflection.java.JavaXClass.getDeclaredMethodProperties(JavaXClass.java:95) at org.hibernate.annotations.common.reflection.java.JavaXClass.getDeclaredProperties(JavaXClass.java:112) at org.hibernate.annotations.common.reflection.java.JavaXClass.getDeclaredProperties(JavaXClass.java:104) at org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:252) at org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:211) at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:767) at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:250) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:231) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:274) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:84) at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:474) at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:85) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:689) at org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.buildSessionFactory(BaseCoreFunctionalTestCase.java:117) at org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.buildSessionFactory(BaseCoreFunctionalTestCase.java:104) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.hibernate.testing.junit4.TestClassMetadata.performCallbackInvocation(TestClassMetadata.java:205) ... 11 more

This is because bytecode enhancement creates:

1 2 3 public Generic.Type $$_hibernate_read_entity() { (...) }

In 5.2.17, it looked like

1 2 public Marker $$_hibernate_read_entity() { (...)

Removing the generic return type from the field and casting to the generic in getEntity() does not work in the test case, but solved the issues in our code stack.

Test case:
https://github.com/nikowitt/hibernate-test-case-templates/tree/HHH-12579

Environment

None

Status

Assignee

Guillaume Smet

Reporter

Niko Wittenbeck

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.3.0.Final

Priority

Major
Configure