Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8315575

Retransform of record class with record component annotation fails with CFE

XMLWordPrintable

    • b16
    • generic
    • generic

      The following record parameter annotation will cause a ClassFileFormat error, if the class is put through Instrumentation.retransformation, even if no class file transformer is registered.

      class Sample {
          @interface MyAnnotation{}
          public record MyRecord(@MyAnnotation Object o, Object other) {}

          public static void main(String[] args) throws Exception {
              Instrumentation inst = ByteBuddyAgent.install();
              inst.retransformClasses(MyRecord.class);
          }
      }

      This can also be seen if using javap where the relevant segment is displayed as follows:

        Record: length = 0xE (java.lang.reflect.InvocationTargetException)
         00 02 00 0B 00 0C 00 01 00 0F 00 0C 00 00

      If the annotation is declared with runtime retention, the problem goes away.

            amenkov Alex Menkov
            winterhalter Rafael Winterhalter
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: