Uploaded image for project: 'Hibernate ORM'
  1. HHH-12579

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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 5.3.0.Final
    • Fix Version/s: 5.3.1
    • Component/s: bytecode-enhancement
    • Labels:
      None
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true
    • Sprint:

      Description

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

      
      @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:

      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:

      public Generic.Type $$_hibernate_read_entity() {
           (...)
          }
      

      In 5.2.17, it looked like

      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

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: