title: hibernate-enhance-maven-plugin: java.lang.IllegalStateException: Unexpected type reference on method: 19
body: <p>I recently added the bytecode enhancement as described in <a href="https://vladmihalcea.com/how-to-enable-bytecode-enhancement-dirty-checking-in-hibernate/" rel="nofollow noreferrer">this article</a> by adding the following lines to my pom.xml:</p>
  
  <pre><code>&lt;plugin&gt;
    &lt;groupId&gt;org.hibernate.orm.tooling&lt;/groupId&gt;
    &lt;artifactId&gt;hibernate-enhance-maven-plugin&lt;/artifactId&gt;
    &lt;version&gt;5.3.10.Final&lt;/version&gt;
    &lt;executions&gt;
      &lt;execution&gt;
        &lt;configuration&gt;
          &lt;enableDirtyTracking&gt;true&lt;/enableDirtyTracking&gt;
        &lt;/configuration&gt;
        &lt;goals&gt;
          &lt;goal&gt;enhance&lt;/goal&gt;
        &lt;/goals&gt;
      &lt;/execution&gt;
    &lt;/executions&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p>When I try to run <code>mvn clean install</code> I get the following errors:</p>
  
  <pre><code>[ERROR] Failed to execute goal org.hibernate.orm.tooling:hibernate-enhance-maven-plugin:5.3.10.Final:enhance (default) on project backend: Unable to enhance class: ExtrasBookingRequestDTO$ExtrasBookingRequestDTOBuilder.class: Failed to enhance class ExtrasBookingRequestDTO$ExtrasBookingRequestDTOBuilder: Unexpected type reference on method: 19 -&gt; [Help 1]
  org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.hibernate.orm.tooling:hibernate-enhance-maven-plugin:5.3.10.Final:enhance (default) on project backend: Unable to enhance class: ExtrasBookingRequestDTO$ExtrasBookingRequestDTOBuilder.class
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
      at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
      at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call(MultiThreadedBuilder.java:185)
      at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call(MultiThreadedBuilder.java:181)
      at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
      at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
      at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
      at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
      at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
      at java.base/java.lang.Thread.run(Thread.java:835)
  Caused by: org.apache.maven.plugin.MojoExecutionException: Unable to enhance class: ExtrasBookingRequestDTO$ExtrasBookingRequestDTOBuilder.class
      at org.hibernate.orm.tooling.maven.MavenEnhancePlugin.doEnhancement(MavenEnhancePlugin.java:227)
      at org.hibernate.orm.tooling.maven.MavenEnhancePlugin.execute(MavenEnhancePlugin.java:152)
      at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
      ... 11 more
  Caused by: org.hibernate.bytecode.enhance.spi.EnhancementException: Failed to enhance class ExtrasBookingRequestDTO$ExtrasBookingRequestDTOBuilder
      at org.hibernate.bytecode.enhance.internal.bytebuddy.EnhancerImpl.enhance(EnhancerImpl.java:138)
      at org.hibernate.orm.tooling.maven.MavenEnhancePlugin.doEnhancement(MavenEnhancePlugin.java:222)
      ... 14 more
  Caused by: java.lang.IllegalStateException: Unexpected type reference on method: 19
      at net.bytebuddy.pool.TypePool$Default$TypeExtractor$MethodExtractor.visitTypeAnnotation(TypePool.java:8198)
      at net.bytebuddy.jar.asm.ClassReader.readMethod(ClassReader.java:1213)
      at net.bytebuddy.jar.asm.ClassReader.accept(ClassReader.java:679)
      at net.bytebuddy.jar.asm.ClassReader.accept(ClassReader.java:391)
      at net.bytebuddy.pool.TypePool$Default.parse(TypePool.java:1176)
      at net.bytebuddy.pool.TypePool$Default.doDescribe(TypePool.java:1160)
      at net.bytebuddy.pool.TypePool$Default$WithLazyResolution.access$401(TypePool.java:1240)
      at net.bytebuddy.pool.TypePool$Default$WithLazyResolution.doResolve(TypePool.java:1338)
      at net.bytebuddy.pool.TypePool$Default$WithLazyResolution$LazyTypeDescription.delegate(TypePool.java:1407)
      at net.bytebuddy.description.type.TypeDescription$AbstractBase$OfSimpleType$WithDelegation.getModifiers(TypeDescription.java:8115)
      at net.bytebuddy.dynamic.scaffold.InstrumentedType$Factory$Default$1.represent(InstrumentedType.java:359)
      at net.bytebuddy.ByteBuddy.redefine(ByteBuddy.java:731)
      at org.hibernate.bytecode.enhance.internal.bytebuddy.EnhancerImpl.lambda$enhance$0(EnhancerImpl.java:133)
      at org.hibernate.bytecode.internal.bytebuddy.ByteBuddyState.rewrite(ByteBuddyState.java:149)
      at org.hibernate.bytecode.enhance.internal.bytebuddy.EnhancerImpl.enhance(EnhancerImpl.java:132)
      ... 15 more
  </code></pre>
  
  <p>From the exception I guess that it has something to do with the Builder that Lombok generates. Unfortunately, I could not find anything about the <code>IllegalStateException: Unexpected type reference on method: 19</code> on the internet. This is the class where maven fails:</p>
  
  <pre><code>import lombok.*;
  
  import javax.validation.Valid;
  import javax.validation.constraints.NotNull;
  import javax.validation.constraints.Size;
  import java.util.Objects;
  import java.util.Set;
  import java.util.UUID;
  
  @Builder
  @AllArgsConstructor
  @NoArgsConstructor
  @Getter
  @Setter
  public class ExtrasBookingRequestDTO {
  
      @NotNull
      private Set&lt;@Valid BookingExtraDTO&gt; extras;
  
      @Size(max = 1000)
      private String notice;
  
      @NotNull
      private UUID temporaryBookingId;
  
      @Override
      public boolean equals(Object o) {
          if (this == o) return true;
          if (o == null || getClass() != o.getClass()) return false;
          ExtrasBookingRequestDTO that = (ExtrasBookingRequestDTO) o;
          return Objects.equals(extras, that.extras) &amp;&amp;
              Objects.equals(notice, that.notice) &amp;&amp;
              Objects.equals(temporaryBookingId, that.temporaryBookingId);
      }
  
      @Override
      public int hashCode() {
          return Objects.hash(extras, notice, temporaryBookingId);
      }
  }
  
  
  </code></pre>