Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-2570

org.jboss.resteasy.spi.util.Types.extractTypeVariables support for ParameterizedType

    XMLWordPrintable

Details

    • Patch
    • Resolution: Unresolved
    • Major
    • None
    • 3.6.2.Final, 4.5.3.Final
    • jaxrs
    • None

    Description

      I started to use a gem of a feature called ContextInjector (https://resteasy.github.io/2018/07/19/asynchronous-injection-in-resteasy/) but immediately noticed that inheritance is a bit tricky since type variables are not deeply resolved in extractTypeVariables

      Here's a patch (sorry for not having a test case, nor a pull request) that got me going. I also refer to my findings of RESTEASY-1295 since they are related to ParameterizedType handling but were not included back in the days to fix.

      org/jboss/resteasy/spi/util/Types.java
      @@ -13,6 +13,7 @@
       import java.util.Map;
       import java.util.Objects;
       import java.util.function.Function;
      +import java.util.stream.IntStream;
       
       import javax.annotation.PostConstruct;
       
      @@ -522,9 +523,9 @@
          {
             if (searchedFor.isInterface())
             {
      -         return findInterfaceParameterizedTypes(root, null, searchedFor);
      +         return findInterfaceParameterizedTypes(root, new ResteasyParameterizedType(root.getTypeParameters(), root, root), searchedFor);
             }
      -      return findClassParameterizedTypes(root, null, searchedFor);
      +      return findClassParameterizedTypes(root, new ResteasyParameterizedType(root.getTypeParameters(), root, root), searchedFor);
          }
       
          public static Type[] findClassParameterizedTypes(Class<?> root, ParameterizedType rootType,
      @@ -683,6 +684,16 @@
                {
                   resolvedMethodParameterTypes[i] = typeVarMap.get(methodParameterType);
                }
      +         else if (methodParameterType instanceof ParameterizedType)
      +         {
      +            ParameterizedType param = (ParameterizedType) methodParameterType;
      +            Type[] actualTypeArguments = param.getActualTypeArguments();
      +            Type[] extractedTypes = extractTypes(typeVarMap, methodParameterType);
      +            resolvedMethodParameterTypes[i] = 
      +                IntStream.range(0, actualTypeArguments.length).allMatch(index -> actualTypeArguments[index] == extractedTypes[index])
      +                ? methodParameterType
      +                : new ResteasyParameterizedType(extractedTypes, param.getRawType(), param.getOwnerType());
      +         }
                else
                {
                   resolvedMethodParameterTypes[i] = methodParameterType;
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              tuomas_kiviaho Tuomas Kiviaho (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: