Uploaded image for project: 'Magnolia'
  1. Magnolia
  2. MAGNOLIA-8528

ByteBuddyI18nizer fails on generic types with extends

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Minor
    • None
    • 6.2.22
    • None
    • None

    Description

      Steps to reproduce

      1. Define a class public class MyTextField<E extends Enum<E>> extends TextFieldDefinition
      2. Use this class in a dialog
      3. Open the dialog

      Expected results

      The dialog is opened.

      Actual results

      Caused by: java.lang.IllegalArgumentException: Cannot resolve E from class...

      Workaround

      Remove the extends:

      - public class MyTextField<E extends Enum<E>> extends TextFieldDefinition

      + public class MyTextField<E> extends TextFieldDefinition

      Development notes

      I believe these extends can be discarded like this:

      @@ -149,10 +149,14 @@ public class ByteBuddyI18nizer implements I18nizer {
      -            Type[] stubParameterTypes = Arrays.stream(typeParameters).map(param -> {
      -                Type[] bounds = param.getBounds();
      -                return bounds.length == 0 ? Object.class : bounds[0];
      -            }).toArray(Type[]::new);
      +            Type[] stubParameterTypes = Arrays.stream(typeParameters).map(param ->
      +                            Arrays.stream(param.getBounds())
      +                                    .filter(bound -> !(bound instanceof ParameterizedType) ||
      +                                            Arrays.stream(((ParameterizedType) bound).getActualTypeArguments())
      +                                                    .noneMatch(TypeVariable.class::isInstance))
      +                                    .findFirst()
      +                                    .orElse(Object.class))
      +                    .toArray(Type[]::new);
      

      Checklists

        Acceptance criteria

        Attachments

          Issue Links

            Activity

              People

                Unassigned Unassigned
                rkovarik Roman Kovařík
                DeveloperX
                Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                  Created:
                  Updated:

                  Checklists

                    Bug DoR
                    Task DoD